From 4a152262a2d804eb148e301500d30c471860123b Mon Sep 17 00:00:00 2001 From: Karsch Lukas <lk224@hdm-stuttgart.de> Date: Sat, 24 Jun 2023 14:48:25 +0200 Subject: [PATCH] Revert "moved HeaderController into new package. Now displaying NutritionTable in..." This reverts commit 2b0b34d130f195c3ad24c936cdc99398f036e407 --- .../controllers/RecipeCreatorController.java | 27 ++--- .../resources/fxml/shoppingList-view.fxml | 106 ++++++++++-------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/src/main/java/mi/hdm/controllers/RecipeCreatorController.java b/src/main/java/mi/hdm/controllers/RecipeCreatorController.java index d8ff2fc..0f876ff 100644 --- a/src/main/java/mi/hdm/controllers/RecipeCreatorController.java +++ b/src/main/java/mi/hdm/controllers/RecipeCreatorController.java @@ -1,10 +1,7 @@ package mi.hdm.controllers; import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.ScrollPane; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; +import javafx.scene.control.*; import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -166,14 +163,12 @@ public class RecipeCreatorController extends BaseController { List<Category> categories = List.copyOf(selectedCategories); String prepTime = prepTimeTextField.getText(); Integer preparationTimeMins = isInteger(prepTime) ? Integer.parseInt(prepTime) : null; - String imagePathString = imagePathTextField.getText(); try { recipe = new Recipe(name, ingredients, description, preparation, categories, preparationTimeMins); recipeManager.addRecipe(recipe); - - if (!imagePathString.isBlank() && Files.exists(Paths.get(new URI(imagePathString)))) { - recipe.setImage(new URL(imagePathString)); + if (Files.exists(Paths.get(new URI(imagePathTextField.getText())))) { + recipe.setImage(new URL(imagePathTextField.getText())); } log.info("Recipe '{}' was created.", name); changeScene(View.RECIPE_VIEW, recipe); @@ -184,23 +179,19 @@ public class RecipeCreatorController extends BaseController { a.show(); log.error(e.getMessage()); log.error("Recipe not created."); - } catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) { - Alert a = new Alert(Alert.AlertType.WARNING); - a.setHeaderText("Image was not set"); - a.setContentText("Invalid argument provided: The filepath to your image was not correct and the default image was loaded."); - a.show(); - Recipe r = recipeManager.getRecipeByName(name).get(); //TODO: this is terrible - log.warn("Invalid image path '{}', loaded default image.", imagePathString); - log.info("Recipe '{}' was created with default image.", name); - changeScene(View.RECIPE_VIEW, r); } catch (RuntimeException e) { Alert a = new Alert(Alert.AlertType.ERROR); a.setHeaderText("Error creating recipe"); a.setContentText("Something went wrong when creating the recipe. Check all your inputs!"); a.show(); log.error(e.getMessage()); - e.printStackTrace(); log.error("Recipe not created."); + } catch (MalformedURLException | URISyntaxException e) { + Recipe r = recipeManager.getRecipeByName(name).get(); + r.setImage(Recipe.class.getResource("/images/dish-fork-and-knife.png")); + log.error("Invalid image path, loaded default image."); + log.info("Recipe '{}' was created.", name); + changeScene(View.RECIPE_VIEW, r); } } diff --git a/src/main/resources/fxml/shoppingList-view.fxml b/src/main/resources/fxml/shoppingList-view.fxml index 00bc17a..1a5aa28 100644 --- a/src/main/resources/fxml/shoppingList-view.fxml +++ b/src/main/resources/fxml/shoppingList-view.fxml @@ -43,67 +43,75 @@ </rowConstraints> <ScrollPane fx:id="selectedIngredientsScrollPane" prefHeight="200.0" prefWidth="467.0" style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-width: 4; -fx-border-radius: 10;"> + <content> + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="459.0" prefWidth="454.0" + style="-fx-background-color: transparent;"> + <children> + <VBox fx:id="selectedIngredientsVBox" prefHeight="200.0" prefWidth="100.0" + AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" + AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/> + </children> + </AnchorPane> + </content> <GridPane.margin> <Insets left="20.0" right="30.0" top="30.0"/> </GridPane.margin> - <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="459.0" prefWidth="454.0" - style="-fx-background-color: transparent;"> - <VBox fx:id="selectedIngredientsVBox" prefHeight="200.0" prefWidth="100.0" - AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" - AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/> - </AnchorPane> </ScrollPane> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="347.0" prefWidth="327.0" style="-fx-background-color: transparent;" GridPane.columnIndex="1"> + <children> + <VBox layoutX="31.0" layoutY="233.0" prefHeight="200.0" prefWidth="100.0" + AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" + AnchorPane.topAnchor="0.0"> + <children> + <TextField fx:id="ingredientSearch"> + <VBox.margin> + <Insets/> + </VBox.margin> + </TextField> + <ScrollPane fx:id="searchResultsPane" prefHeight="316.0" prefWidth="338.0" + style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-width: 4; -fx-border-radius: 10;"> + <VBox.margin> + <Insets bottom="20.0" top="20.0"/> + </VBox.margin> + <content> + <AnchorPane prefHeight="297.0" prefWidth="326.0"/> + </content> + </ScrollPane> + <HBox prefHeight="51.0" prefWidth="338.0" + style="-fx-background-color: transparent;"> + <Button mnemonicParsing="false" onAction="#handleRemoveBought" + style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-width: 4; -fx-border-radius: 5;" + text="Remove Bought" textFill="#d91c1c"> + <font> + <Font name="System Bold" size="17.0"/> + </font> + <HBox.margin> + <Insets right="10.0"/> + </HBox.margin> + </Button> + <Button fx:id="clearList" accessibleText="Clear Shopping List" + alignment="CENTER" contentDisplay="RIGHT" mnemonicParsing="false" + onAction="#handleClearList" 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="Clear List" textAlignment="CENTER" textFill="#d91c1c"> + <font> + <Font name="System Bold" size="17.0"/> + </font> + <HBox.margin> + <Insets left="10.0"/> + </HBox.margin> + </Button> + </HBox> + </children> + </VBox> + </children> <GridPane.margin> <Insets left="20.0" right="30.0" top="30.0"/> </GridPane.margin> - <VBox layoutX="31.0" layoutY="233.0" prefHeight="200.0" prefWidth="100.0" - AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" - AnchorPane.topAnchor="0.0"> - <TextField fx:id="ingredientSearch"> - <VBox.margin> - <Insets/> - </VBox.margin> - </TextField> - <ScrollPane fx:id="searchResultsPane" prefHeight="316.0" prefWidth="338.0" - style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-width: 4; -fx-border-radius: 10;"> - <VBox.margin> - <Insets bottom="20.0" top="20.0"/> - </VBox.margin> - <AnchorPane prefHeight="297.0" prefWidth="326.0"/> - </ScrollPane> - <HBox prefHeight="51.0" prefWidth="338.0" style="-fx-background-color: transparent;"> - <Button mnemonicParsing="false" onAction="#handleRemoveBought" - style="-fx-background-color: transparent; -fx-border-color: d91c1c; -fx-border-width: 4; -fx-border-radius: 5;" - text="Remove Bought" textFill="#d91c1c"> - <font> - <Font name="System Bold" size="17.0"/> - </font> - <HBox.margin> - <Insets right="10.0"/> - </HBox.margin> - </Button> - <Button fx:id="clearList" accessibleText="Clear Shopping List" alignment="CENTER" - contentDisplay="RIGHT" mnemonicParsing="false" onAction="#handleClearList" - 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="Clear List" textAlignment="CENTER" textFill="#d91c1c"> - <font> - <Font name="System Bold" size="17.0"/> - </font> - <HBox.margin> - <Insets left="10.0"/> - </HBox.margin> - </Button> - </HBox> - </VBox> </AnchorPane> </GridPane> </children> </AnchorPane> </VBox> - <padding> - <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/> - </padding> </AnchorPane> -- GitLab