From bfe245ed786ad5b3f5621d253a2d70f4138264b5 Mon Sep 17 00:00:00 2001 From: Lara Blersch <lb210@hdm-stuttgart.de> Date: Thu, 8 Jun 2023 14:04:22 +0200 Subject: [PATCH] continued recipe-view and controller, image path still not working --- src/main/java/mi/hdm/controllers/BaseController.java | 4 ++-- .../java/mi/hdm/controllers/MainPageController.java | 2 +- .../mi/hdm/controllers/RecipeViewController.java | 7 ++++--- src/main/java/mi/hdm/controllers/View.java | 7 ++----- src/main/resources/fxml/recipe-view.fxml | 12 ++++++------ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/mi/hdm/controllers/BaseController.java b/src/main/java/mi/hdm/controllers/BaseController.java index ca66cf0..930dcfd 100644 --- a/src/main/java/mi/hdm/controllers/BaseController.java +++ b/src/main/java/mi/hdm/controllers/BaseController.java @@ -16,7 +16,7 @@ public abstract class BaseController { protected Scene currentScene; //TODO this should be static? private static View currentView = GuiController.getStartupView(); - protected void changeScene(final View newScene) { + protected void changeScene(final View newScene, Object... args) { if (newScene == currentView) { return; } @@ -28,7 +28,7 @@ public abstract class BaseController { String newWindowTitle = newScene.getWindowTitle(); log.debug("Attempting to change the scene to {}", newScene); - Parent newParent = newScene.getScene(); + Parent newParent = newScene.getScene(args); currentScene = new Scene(newParent, sizeX, sizeY); currentView = newScene; diff --git a/src/main/java/mi/hdm/controllers/MainPageController.java b/src/main/java/mi/hdm/controllers/MainPageController.java index 55581fb..a524cdd 100644 --- a/src/main/java/mi/hdm/controllers/MainPageController.java +++ b/src/main/java/mi/hdm/controllers/MainPageController.java @@ -56,7 +56,7 @@ public class MainPageController extends BaseController { for (Recipe recipe : recipes) { RecipeVbox recipeVbox = new RecipeVbox(recipe, categoryManager); - recipeVbox.setOnMouseClicked(mouseEvent -> System.out.format("User selected '%s'.%n", recipe.getName())); //TODO: this needs to display the recipe view + recipeVbox.setOnMouseClicked(mouseEvent -> changeScene(View.RECIPE_VIEW, recipeVbox.getAssociatedRecipe())); //TODO: this needs to display the recipe view currentRecipesInGUI.add(recipeVbox); } recipeTilePane.getChildren().addAll(currentRecipesInGUI); //... and add the new ones diff --git a/src/main/java/mi/hdm/controllers/RecipeViewController.java b/src/main/java/mi/hdm/controllers/RecipeViewController.java index 7a578e9..f1495fd 100644 --- a/src/main/java/mi/hdm/controllers/RecipeViewController.java +++ b/src/main/java/mi/hdm/controllers/RecipeViewController.java @@ -18,8 +18,8 @@ public class RecipeViewController extends BaseController { private final Recipe recipe; @FXML private AnchorPane parent; - @FXML - private Label recipeDescription; + // @FXML + //private Label recipeDescription; @FXML private Label recipeName; @FXML @@ -46,7 +46,8 @@ public class RecipeViewController extends BaseController { loadHeader(parent); recipeName.setText(recipe.getName()); - recipeDescription.setText(recipe.getDescription()); + //recipeDescription.setText(recipe.getDescription()); + //TODO: display recipe description, preparation and ingredients //idea for solution from: https://stackoverflow.com/questions/22710053/how-can-i-show-an-image-using-the-imageview-component-in-javafx-and-fxml Image image = new Image(recipe.getImage()); diff --git a/src/main/java/mi/hdm/controllers/View.java b/src/main/java/mi/hdm/controllers/View.java index 2d20662..55a9f44 100644 --- a/src/main/java/mi/hdm/controllers/View.java +++ b/src/main/java/mi/hdm/controllers/View.java @@ -40,15 +40,12 @@ public enum View { ); case RECIPE_VIEW -> loader.setControllerFactory((callback) -> { - if (args== null && args.length == 1 && args[0] instanceof Recipe recipe) { + if (args != null && args.length == 1 && args[0] instanceof Recipe recipe) { return new RecipeViewController(recipe); } else { throw new InvalidParameterException(); } - } - - - ); + }); case SHOPPINGLIST_VIEW -> loader.setControllerFactory((callback) -> new ShoppingListViewController(model.getRecipeManager(), model.getShoppingList()) diff --git a/src/main/resources/fxml/recipe-view.fxml b/src/main/resources/fxml/recipe-view.fxml index 6f53fca..e401335 100644 --- a/src/main/resources/fxml/recipe-view.fxml +++ b/src/main/resources/fxml/recipe-view.fxml @@ -6,7 +6,7 @@ <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> -<AnchorPane prefHeight="540.0" prefWidth="872.0" style="-fx-background-color: ffffff;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mi.hdm.controllers.RecipeViewController"> +<AnchorPane fx:id="parent" prefHeight="540.0" prefWidth="872.0" style="-fx-background-color: ffffff;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mi.hdm.controllers.RecipeViewController"> <children> <VBox layoutX="410.0" layoutY="1.0" prefHeight="539.0" prefWidth="872.0" style="-fx-background-color: ffffff;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <padding> @@ -22,7 +22,7 @@ <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> <children> - <Label alignment="TOP_CENTER" prefHeight="54.0" prefWidth="207.0" text="Recipe Name" textFill="#d91c1c" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="TOP"> + <Label fx:id="recipeName" alignment="TOP_CENTER" prefHeight="54.0" prefWidth="207.0" text="Recipe Name" textFill="#d91c1c" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="TOP"> <font> <Font name="Arial" size="34.0" /> </font> @@ -49,12 +49,12 @@ <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> <children> - <Button alignment="CENTER" contentDisplay="RIGHT" mnemonicParsing="false" prefHeight="41.0" prefWidth="159.0" style="-fx-background-color: ffffff; -fx-control-inner-background: transparent; -fx-border-color: d91c1c; -fx-border-radius: 5; -fx-border-width: 4;" text="Delete" textAlignment="CENTER" textFill="#d91c1c"> + <Button fx:id="recipeDelete" alignment="CENTER" contentDisplay="RIGHT" mnemonicParsing="false" prefHeight="41.0" prefWidth="159.0" style="-fx-background-color: ffffff; -fx-control-inner-background: transparent; -fx-border-color: d91c1c; -fx-border-radius: 5; -fx-border-width: 4;" text="Delete" textAlignment="CENTER" textFill="#d91c1c"> <font> <Font name="System Bold" size="17.0" /> </font> </Button> - <Button alignment="CENTER" contentDisplay="RIGHT" mnemonicParsing="false" prefHeight="41.0" prefWidth="159.0" style="-fx-background-color: ffffff; -fx-control-inner-background: transparent; -fx-border-color: d91c1c; -fx-border-radius: 5; -fx-border-width: 4;" text="Edit" textAlignment="CENTER" textFill="#d91c1c" GridPane.columnIndex="1"> + <Button fx:id="recipeDelete" alignment="CENTER" contentDisplay="RIGHT" mnemonicParsing="false" prefHeight="41.0" prefWidth="159.0" style="-fx-background-color: ffffff; -fx-control-inner-background: transparent; -fx-border-color: d91c1c; -fx-border-radius: 5; -fx-border-width: 4;" text="Edit" textAlignment="CENTER" textFill="#d91c1c" GridPane.columnIndex="1"> <font> <Font name="System Bold" size="17.0" /> </font> @@ -70,7 +70,7 @@ </VBox.margin></ListView> <ScrollPane prefHeight="244.0" prefWidth="393.0" style="-fx-border-color: D91C1C; -fx-border-width: 4; -fx-border-radius: 10; -fx-background-color: transparent;"> <content> - <Label alignment="TOP_LEFT" contentDisplay="CENTER" lineSpacing="1.5" prefHeight="372.0" prefWidth="393.0" style="-fx-background-color: transparent;" text=" sjdfjakjfkj j kasdjfkasjdkf aorjfaksdjf alösjfailjskdf aöiejraö skjdfoakdjfpoeaijf alskjdf aroijf oajdfo oerajfija oaeijr oaiejrüoj oaejf üoaijer fjüaroifj üeorj ojeaüroit oijetiüfj üeor" wrapText="true"> + <Label fx:id="recipePreparation" alignment="TOP_LEFT" contentDisplay="CENTER" lineSpacing="1.5" prefHeight="372.0" prefWidth="393.0" style="-fx-background-color: transparent;" text=" sjdfjakjfkj j kasdjfkasjdkf aorjfaksdjf alösjfailjskdf aöiejraö skjdfoakdjfpoeaijf alskjdf aroijf oajdfo oerajfija oaeijr oaiejrüoj oaejf üoaijer fjüaroifj üeorj ojeaüroit oijetiüfj üeor" wrapText="true"> <font> <Font name="Inter Regular" size="12.0" /> </font> @@ -100,7 +100,7 @@ <Pane layoutX="10.0" layoutY="10.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-radius: 10; -fx-border-width: 4;"> <children> <ScrollBar layoutX="317.0" layoutY="5.0" orientation="VERTICAL" prefHeight="190.0" prefWidth="14.0" /> - <TableView layoutY="-1.0" prefHeight="200.0" prefWidth="321.0" style="-fx-background-color: transparent;"> + <TableView fx:id="recipeIngredients" layoutY="-1.0" prefHeight="200.0" prefWidth="321.0" style="-fx-background-color: transparent;"> <columns> <TableColumn editable="false" prefWidth="91.0" text="C1" /> -- GitLab