Skip to content

Commit

Permalink
fix Main & add paging
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdavifar2002 committed Jun 26, 2020
1 parent f5fedb0 commit e80bffb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/graphics/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void profileButtonPressed(ActionEvent actionEvent) throws IOException {
default:
throw new IllegalStateException("Unexpected value: " + Main.controller.getPersonalInfo("type"));
}
Main.setMainStage("", fxmlPath);
Main.setMainStage("Profile", fxmlPath);

}
}
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/graphics/ProductsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javafx.geometry.Insets;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.image.*;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
Expand All @@ -35,6 +37,9 @@ public class ProductsPage {
public JFXTextField sellerField;
public IntegerValidator numberValidator;
public ChoiceBox<String> sortBox;
public Spinner pageSpinner;
public HBox pageHBox;
public SpinnerValueFactory.IntegerSpinnerValueFactory pageFactory;
Comparator<Product> comparator;
ArrayList<Product> products = Database.getAllProducts();
ArrayList<JFXTextField> fields = new ArrayList<>();
Expand All @@ -58,6 +63,10 @@ public void initialize() {
resetProducts(products);
});

pageSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
resetProducts(products);
});

resetProducts(products);
makeFilters(null);
}
Expand Down Expand Up @@ -145,12 +154,17 @@ private void resetProducts(ArrayList<Product> products) {
int counter = 0;

gridPane.getChildren().clear();
int pageSize = 6;
gridPane.getChildren().add(pageHBox);
pageFactory.setMax(1 + (productsToShow.size() - 1) / pageSize);
int pageNumber = Integer.parseInt(pageSpinner.getValue().toString());
productsToShow.sort(comparator);
for (Product product : productsToShow) {
ProductPane pane = new ProductPane(product);

gridPane.getChildren().add(pane);
GridPane.setConstraints(pane, counter % 2, counter / 2);
if (counter < pageNumber * pageSize && counter >= (pageNumber - 1) * pageSize) {
ProductPane pane = new ProductPane(product);
gridPane.getChildren().add(pane);
GridPane.setConstraints(pane, counter % 2, (counter - (pageNumber - 1) * pageSize) / 2 + 1);
}
counter++;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/graphics/TopBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void logoutPressed() throws Exception {
Main.sellerController = null;
Main.managerController = null;
Main.customerController = new CustomerController((Customer)Main.controller.getUser(), Main.productController);
Main.clearStack();
Main.setMainStage("Main Menu", "src/main/resources/fxml/MainMenu.fxml");
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static void returnMainStage() {
Main.mainStage.setScene(sceneStack.peek());
}

public static void clearStack() {
sceneStack.clear();
}

public static void setMainStageSize(int width, int height) {
mainStage.setWidth(width);
mainStage.setHeight(height);
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/fxml/MainMenu.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import java.net.URL?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<StackPane xmlns:fx="http://javafx.com/fxml/1" alignment="CENTER" prefHeight="450.0" prefWidth="620.0"
xmlns="http://javafx.com/javafx/10.0.2-internal" fx:controller="graphics.MainMenu">
<VBox>
Expand All @@ -21,7 +23,12 @@

<Separator orientation="VERTICAL"/>

<SlideShow/>
<!-- <SlideShow/>-->
<ImageView fitHeight="300.0" preserveRatio="true">
<image>
<Image url="@../images/shop-logo.png"/>
</image>
</ImageView>

<stylesheets>
<URL value="@../stylesheets/main.css"/>
Expand Down
24 changes: 18 additions & 6 deletions src/main/resources/fxml/ProductsPage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<?import graphics.TopBar?>
<?import java.net.URL?>

<?import javafx.scene.control.ScrollPane?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Separator?>
<?import com.jfoenix.controls.JFXTextField?>
<?import com.jfoenix.validation.IntegerValidator?>
<?import javafx.collections.FXCollections?>
<?import java.lang.String?>
<?import com.jfoenix.controls.JFXCheckBox?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import graphics.TopBar?>
<?import java.net.URL?>
<?import com.jfoenix.controls.JFXTextField?>
<ScrollPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="graphics.ProductsPage" fitToWidth="true">
Expand All @@ -26,7 +26,19 @@

<HBox fillHeight="false" style="-fx-padding: 0 0 30 0;">
<VBox>
<GridPane fx:id="gridPane" hgap="10" vgap="10" minWidth="420" style="-fx-padding: 0 30 30 30;"/>
<GridPane fx:id="gridPane" hgap="10" vgap="10" minWidth="420" style="-fx-padding: 0 30 30 30;">

<!-- Page Spinner -->
<HBox fx:id="pageHBox" alignment="CENTER" spacing="5"
GridPane.columnIndex="0" GridPane.rowIndex="0">
<Label text="Page:"/>
<Spinner fx:id="pageSpinner" promptText="1" maxWidth="50">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="1" max="5" fx:id="pageFactory"/>
</valueFactory>
</Spinner>
</HBox>
</GridPane>
</VBox>
<VBox>
<VBox styleClass="bobble" prefWidth="170" spacing="20">
Expand Down
Binary file added src/main/resources/images/shop-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e80bffb

Please sign in to comment.