diff --git a/src/main/java/graphics/MainMenu.java b/src/main/java/graphics/MainMenu.java index 774d2be..3e98969 100644 --- a/src/main/java/graphics/MainMenu.java +++ b/src/main/java/graphics/MainMenu.java @@ -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); } } diff --git a/src/main/java/graphics/ProductsPage.java b/src/main/java/graphics/ProductsPage.java index cbfe21a..b0c19dc 100644 --- a/src/main/java/graphics/ProductsPage.java +++ b/src/main/java/graphics/ProductsPage.java @@ -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; @@ -35,6 +37,9 @@ public class ProductsPage { public JFXTextField sellerField; public IntegerValidator numberValidator; public ChoiceBox sortBox; + public Spinner pageSpinner; + public HBox pageHBox; + public SpinnerValueFactory.IntegerSpinnerValueFactory pageFactory; Comparator comparator; ArrayList products = Database.getAllProducts(); ArrayList fields = new ArrayList<>(); @@ -58,6 +63,10 @@ public void initialize() { resetProducts(products); }); + pageSpinner.valueProperty().addListener((observable, oldValue, newValue) -> { + resetProducts(products); + }); + resetProducts(products); makeFilters(null); } @@ -145,12 +154,17 @@ private void resetProducts(ArrayList 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++; } } diff --git a/src/main/java/graphics/TopBar.java b/src/main/java/graphics/TopBar.java index e114d9e..7cf9133 100644 --- a/src/main/java/graphics/TopBar.java +++ b/src/main/java/graphics/TopBar.java @@ -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"); } diff --git a/src/main/java/main/Main.java b/src/main/java/main/Main.java index 683365e..15778d2 100644 --- a/src/main/java/main/Main.java +++ b/src/main/java/main/Main.java @@ -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); diff --git a/src/main/resources/fxml/MainMenu.fxml b/src/main/resources/fxml/MainMenu.fxml index 3d847dc..356f53f 100644 --- a/src/main/resources/fxml/MainMenu.fxml +++ b/src/main/resources/fxml/MainMenu.fxml @@ -8,6 +8,8 @@ + + @@ -21,7 +23,12 @@ - + + + + + + diff --git a/src/main/resources/fxml/ProductsPage.fxml b/src/main/resources/fxml/ProductsPage.fxml index 3d8732e..d909c31 100644 --- a/src/main/resources/fxml/ProductsPage.fxml +++ b/src/main/resources/fxml/ProductsPage.fxml @@ -5,16 +5,16 @@ - - - - - + + + + + @@ -26,7 +26,19 @@ - + + + + + + diff --git a/src/main/resources/images/shop-logo.png b/src/main/resources/images/shop-logo.png new file mode 100644 index 0000000..211ca7d Binary files /dev/null and b/src/main/resources/images/shop-logo.png differ