diff --git a/pom.xml b/pom.xml index 32d414b465d02b1008bed5a297f3be78e27329f6..0e8382b993894da6738068e5f5705536e79edac9 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ <version>0.0.4</version> <configuration> <launcher>TastyPagesdriver</launcher> - <mainClass>mi.hdm.GuiDriver</mainClass> + <mainClass>mi.hdm.TastyPages</mainClass> </configuration> </plugin> diff --git a/src/main/java/mi/hdm/TastyPages.java b/src/main/java/mi/hdm/TastyPages.java index 66532d8047fe631a9936afd06d499064a9aab456..fdee332a9a0cc30a5a91c06294eb30a3b8643f9b 100644 --- a/src/main/java/mi/hdm/TastyPages.java +++ b/src/main/java/mi/hdm/TastyPages.java @@ -14,7 +14,7 @@ import java.util.List; import java.util.Map; public class TastyPages extends Application { - //TODO: instantiate all dependencies HERE! The getScene() method from View.java should go here aswell for dependency injection + //TODO: instantiate all dependencies HERE! The getScene() method from View.java should go here as well for dependency injection public final static RecipeManager recipeManager = new RecipeManager(); private final static Logger log = LogManager.getLogger(TastyPages.class); @@ -33,18 +33,14 @@ public class TastyPages extends Application { return stage; } - - public void save() { - } - @Override public void start(Stage stage) throws IOException { TastyPages.stage = stage; - Parent parent = View.SHOPPINGLIST_VIEW.getScene(); + Parent parent = View.MAIN.getScene(); final Scene scene = new Scene(parent, 1400, 800); - stage.setTitle("Shopping List"); + stage.setTitle(View.MAIN.getWindowTitle()); stage.setMaximized(true); //open scene in full screen stage.setScene(scene); stage.show(); diff --git a/src/main/java/mi/hdm/controllers/BaseController.java b/src/main/java/mi/hdm/controllers/BaseController.java index a3457ad47c4deb52486c2926492dc9f47615783d..c37964932af3f0572b80e1272773c99c3dfe4b52 100644 --- a/src/main/java/mi/hdm/controllers/BaseController.java +++ b/src/main/java/mi/hdm/controllers/BaseController.java @@ -7,13 +7,15 @@ import mi.hdm.TastyPages; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.IOException; + public abstract class BaseController { private final static Logger log = LogManager.getLogger(BaseController.class); private final static Stage stage = TastyPages.getApplicationStage(); protected Scene currentScene; - protected void changeScene(final View newScene) throws Exception { + protected void changeScene(final View newScene) throws IOException { boolean wasMaximized = stage.isMaximized(); double sizeX = stage.getWidth(); double sizeY = stage.getHeight(); diff --git a/src/main/java/mi/hdm/controllers/MainPageController.java b/src/main/java/mi/hdm/controllers/MainPageController.java new file mode 100644 index 0000000000000000000000000000000000000000..a8461874a5196833c89155ba19eb142aee915f12 --- /dev/null +++ b/src/main/java/mi/hdm/controllers/MainPageController.java @@ -0,0 +1,38 @@ +package mi.hdm.controllers; + +import javafx.fxml.FXML; +import mi.hdm.recipes.RecipeManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; + +public class MainPageController extends BaseController { + private final static Logger log = LogManager.getLogger(MainPageController.class); + + private final RecipeManager recipeManager; + + public MainPageController(RecipeManager recipeManager) { + this.recipeManager = recipeManager; + } + + @FXML + public void changeSceneToHome() throws IOException { + changeScene(View.MAIN); + } + + @FXML + public void changeSceneToShoppingList() throws IOException { + changeScene(View.SHOPPINGLIST_VIEW); + } + + @FXML + public void changeSceneToMealPlan() throws IOException { + log.error("NOT IMPLEMENTED! Scene meal plan doesn't exist yet!"); + } + + @FXML + public void addRecipe() { + log.info("User is trying to add recipe!"); + } +} diff --git a/src/main/java/mi/hdm/controllers/View.java b/src/main/java/mi/hdm/controllers/View.java index 043c04c10e83e3efcb91e8fd5d2e28c8e41c04e8..79059c164275ab26684221d075a277c9831b7ab9 100644 --- a/src/main/java/mi/hdm/controllers/View.java +++ b/src/main/java/mi/hdm/controllers/View.java @@ -2,7 +2,6 @@ package mi.hdm.controllers; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; -import mi.hdm.HelloController; import mi.hdm.TastyPages; import mi.hdm.recipes.RecipeManager; import mi.hdm.shoppingList.ShoppingList; @@ -12,14 +11,14 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; public enum View { - MAIN("/fxml/hello.fxml", "Tasty Pages"), + MAIN("/fxml/Tasty_Pages_Main_Page.fxml", "Tasty Pages"), RECIPE_VIEW("/fxml/recipe-view.fxml", "Tasty Pages - Recipe View"), SHOPPINGLIST_VIEW("/fxml/shoppingList-view.fxml", "Tasty Pages - Shopping List View"); private static final Logger log = LogManager.getLogger(View.class); private final RecipeManager recipeManager = TastyPages.recipeManager; - private final ShoppingList shoppingList = ShoppingList.getInstance(); + private final ShoppingList shoppingList = new ShoppingList(); private final String path; private final String windowTitle; @@ -30,23 +29,26 @@ public enum View { } public Parent getScene() throws IOException { - log.info("Loading FXML for {} view from: {}", windowTitle, path); + //TODO: keep track of current view and don't reload it if the user selects it again! + log.info("Loading FXML for '{}' view from: {}", windowTitle, path); final FXMLLoader loader = new FXMLLoader(getClass().getResource(path)); log.debug("Successfully retrieved resource from {}", path); //set the correct controller factory for views (necessary to enable dependency injection) switch (this) { case MAIN -> loader.setControllerFactory((callback) -> - new HelloController() + new MainPageController(recipeManager) ); case RECIPE_VIEW -> loader.setControllerFactory((callback) -> new RecipeViewController(recipeManager) ); + case SHOPPINGLIST_VIEW -> loader.setControllerFactory((callback) -> new ShoppingListViewController(recipeManager, shoppingList) ); } + log.debug("Set controller factory for {}", windowTitle); return loader.load(); } diff --git a/src/main/java/mi/hdm/recipes/mealPlan/MealPlan.java b/src/main/java/mi/hdm/mealPlan/MealPlan.java similarity index 98% rename from src/main/java/mi/hdm/recipes/mealPlan/MealPlan.java rename to src/main/java/mi/hdm/mealPlan/MealPlan.java index 3596bb80f5c39a77e191e69b7493963fbe8461e2..5db9f3c7ca5ebf03031d24df54e3fa31c3c6638b 100644 --- a/src/main/java/mi/hdm/recipes/mealPlan/MealPlan.java +++ b/src/main/java/mi/hdm/mealPlan/MealPlan.java @@ -1,4 +1,4 @@ -package mi.hdm.recipes.mealPlan; +package mi.hdm.mealPlan; import mi.hdm.exceptions.InvalidMealPlanException; import mi.hdm.recipes.NutritionCalculator; diff --git a/src/main/java/mi/hdm/recipes/CategoryManager.java b/src/main/java/mi/hdm/recipes/CategoryManager.java index b4547fe3c57e17dbd957a91ea10aaf82d28a9d66..326c6abe2bfdfea7d8f76e03f1de300e653e6a8c 100644 --- a/src/main/java/mi/hdm/recipes/CategoryManager.java +++ b/src/main/java/mi/hdm/recipes/CategoryManager.java @@ -8,28 +8,27 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -//TODO: make this not a singleton? public class CategoryManager { - private static final CategoryManager instance = new CategoryManager(); private static final Logger log = LogManager.getLogger(CategoryManager.class); private final List<Category> allCategories; - private CategoryManager() { + public CategoryManager() { allCategories = new ArrayList<>(); } - public static CategoryManager getInstance() { - return instance; + public CategoryManager(List<Category> categories) { + allCategories = categories; } /** * Adds a category if neither the given name nor the color code have been used in a category before. - * @param name Name for the category that is to be added + * + * @param name Name for the category that is to be added * @param colourCode Color code for the category that is to be added * @throws InvalidCategoryException if the category already exists */ - public void addCategory(String name, int colourCode){ + public void addCategory(String name, int colourCode) { Category c = new Category(name, colourCode); if (getCategoryByName(name).isPresent() || getCategoryByCode(colourCode).isPresent()) { log.error("Category {} not added because it already exists", c.getName()); diff --git a/src/main/java/mi/hdm/recipes/IngredientManager.java b/src/main/java/mi/hdm/recipes/IngredientManager.java index 4fa23490df553502fcb95ab3fe82f568a94fc96b..909e84a234fec836f9a36c35ad7043502b88f6ea 100644 --- a/src/main/java/mi/hdm/recipes/IngredientManager.java +++ b/src/main/java/mi/hdm/recipes/IngredientManager.java @@ -7,24 +7,22 @@ import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; import java.util.Optional; -//TODO: check for other "return false" methods which should throw an exceptions instead -//TODO: make this not a singleton? public class IngredientManager { private static final Logger log = LogManager.getLogger(IngredientManager.class); - private static final IngredientManager instance = new IngredientManager(); private final List<Ingredient> allIngredients; - private IngredientManager() { + public IngredientManager() { allIngredients = new ArrayList<>(); } - public static IngredientManager getInstance() { - return instance; + public IngredientManager(List<Ingredient> ingredients) { + allIngredients = ingredients; } /** * Adds an ingredient if there is no equal ingredient (no ingredient with the same name). + * * @param in Ingredient that is to be added * @return True if the ingredient has been added (meaning no equal ingredient existed before), otherwise false. */ @@ -49,10 +47,6 @@ public class IngredientManager { } public void deleteIngredient(String name) { - //TODO: check this out, might be a better solution - /*Optional<Ingredient> ingredient = getIngredientByName(name); - return ingredient.isPresent() && allIngredients.remove(ingredient);*/ - Ingredient ingredient = getIngredientByName(name).orElseThrow(() -> new InvalidIngredientException("No ingredient with name " + name)); log.info("Ingredient {} deleted successfully.", name); allIngredients.remove(ingredient); diff --git a/src/main/java/mi/hdm/recipes/NutritionCalculator.java b/src/main/java/mi/hdm/recipes/NutritionCalculator.java index 6be2ac8f82016e673a90620d2db9594848cb0fce..cd1106efe8c88de4856c5d42b903cd1e1523abab 100644 --- a/src/main/java/mi/hdm/recipes/NutritionCalculator.java +++ b/src/main/java/mi/hdm/recipes/NutritionCalculator.java @@ -1,6 +1,6 @@ package mi.hdm.recipes; -import mi.hdm.recipes.mealPlan.MealPlan; +import mi.hdm.mealPlan.MealPlan; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/mi/hdm/recipes/NutritionTable.java b/src/main/java/mi/hdm/recipes/NutritionTable.java index 855ed6f26293f2f62b8a28ffc830bad6401519f5..d7ca2bb55ad2e90aa2071b5f4a9c893c40450506 100644 --- a/src/main/java/mi/hdm/recipes/NutritionTable.java +++ b/src/main/java/mi/hdm/recipes/NutritionTable.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; public class NutritionTable { + //TODO: refactor this class to use BigDecimal private final Map<Nutrition, Double> table; /** @@ -57,7 +58,6 @@ public class NutritionTable { return this; } - //TODO: use big decimal instead of double to avoid this trouble? /** * Overridden equals method to account for rounding errors when calculating nutrition scores. diff --git a/src/main/java/mi/hdm/recipes/RecipeManager.java b/src/main/java/mi/hdm/recipes/RecipeManager.java index f2cab8a6d9b7f5f8772a6ef097b48b7e19391962..1ec73070920b48a5928c26eb215f679d636609e5 100644 --- a/src/main/java/mi/hdm/recipes/RecipeManager.java +++ b/src/main/java/mi/hdm/recipes/RecipeManager.java @@ -9,12 +9,12 @@ import java.util.List; import java.util.Optional; public class RecipeManager { - //TODO observable array list + //TODO observable array list? + private static final Logger log = LogManager.getLogger(RecipeManager.class); private final List<Recipe> recipes; private final CategoryManager categories; private final IngredientManager ingredients; - private static final Logger log = LogManager.getLogger(RecipeManager.class); public RecipeManager(List<Recipe> recipes, CategoryManager categories, IngredientManager ingredients) { this.recipes = recipes; @@ -24,18 +24,17 @@ public class RecipeManager { public RecipeManager() { recipes = new ArrayList<>(); - categories = CategoryManager.getInstance(); - ingredients = IngredientManager.getInstance(); + categories = new CategoryManager(); + ingredients = new IngredientManager(); } public void addRecipe(Recipe recipe) { - if (getRecipeByName(recipe.getName()).isEmpty()) { - recipes.add(recipe); - log.info("Recipe {} added successfully.", recipe.getName()); - } else { - log.error("Recipe {} not added because it already exists.", recipe.getName()); - throw new InvalidRecipeException("Recipe name already exists"); + if (getRecipeByName(recipe.getName()).isPresent()) { + log.error("Recipe '{}' not added because another recipe with the same name already exists", recipe.getName()); + throw new InvalidRecipeException("Recipe with this name already exists."); } + recipes.add(recipe); + log.info("Recipe {} added successfully.", recipe.getName()); } public Recipe deleteRecipe(int i) { @@ -52,10 +51,10 @@ public class RecipeManager { // Exception vs return false: What's the best approach? // -> false for normal situations, exceptions for real faults which should not occur public void deleteRecipe(Recipe r) { - log.info("Recipe deleted successfully."); - if (recipes.remove(r) == false) { + if (!recipes.remove(r)) { throw new InvalidRecipeException("Recipe is not listed."); } + log.info("Recipe deleted successfully."); } private Optional<Recipe> getRecipeByName(String name) { diff --git a/src/main/java/mi/hdm/shoppingList/ShoppingList.java b/src/main/java/mi/hdm/shoppingList/ShoppingList.java index 95efe9e9a409dd2c9d13e7faeb23a3c59e29480f..5353af872b56b7fb88dadf86aaf514f8b2a012e0 100644 --- a/src/main/java/mi/hdm/shoppingList/ShoppingList.java +++ b/src/main/java/mi/hdm/shoppingList/ShoppingList.java @@ -15,16 +15,15 @@ import java.util.Optional; */ public class ShoppingList { private static final Logger log = LogManager.getLogger(ShoppingList.class); - private final Map<Ingredient, Boolean> list; - private static final ShoppingList shoppingList = new ShoppingList(); + private final Map<Ingredient, Boolean> list; - private ShoppingList() { + public ShoppingList() { list = new HashMap<>(); } - public static ShoppingList getInstance() { - return shoppingList; + public ShoppingList(Map<Ingredient, Boolean> shoppingListMap) { + list = shoppingListMap; } public void clear() { @@ -43,12 +42,13 @@ public class ShoppingList { public void addAllToShoppingList(Recipe recipe) { recipe.getIngredients().keySet() .forEach(element -> { - if (element instanceof Ingredient i) - addToShoppingList(i); - //add recipes recursively (see below); comment next 2 lines out to avoid adding recipes recursively - else - addAllToShoppingList((Recipe) element); - }); + if (element instanceof Ingredient i) + addToShoppingList(i); + //adds recipes recursively (see below); comment next 2 lines out to avoid adding recipes recursively + else + addAllToShoppingList((Recipe) element); + } + ); } public void flipStatus(Ingredient in) { @@ -75,8 +75,9 @@ public class ShoppingList { for (Ingredient i : list.keySet()) { if (list.get(i)) list.remove(i); removed++; + log.debug("Removed ingredient '{}' from shopping list.", i.getName()); } - log.info("Removed {} ingredients from shopping list", removed); + log.info("Removed {} ingredients from shopping list.", removed); } public Map<Ingredient, Boolean> getList() { diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 8f11b3e4c1c7bbc1792fb56f944b266c96e01114..4dd3f6d7da4b6cc0be7d1b77968ebf3e2ba84db2 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -9,5 +9,6 @@ module gui { exports mi.hdm; exports mi.hdm.controllers; exports mi.hdm.shoppingList; + exports mi.hdm.mealPlan; exports mi.hdm.recipes; } \ No newline at end of file diff --git a/src/main/resources/fxml/Tasty_Pages_Main_Page.fxml b/src/main/resources/fxml/Tasty_Pages_Main_Page.fxml index 348c6b4e5b019903d18da241b5ddafc1deb7b308..3bb8a84890b8414e1cb49c85162f699452c2bd3d 100644 --- a/src/main/resources/fxml/Tasty_Pages_Main_Page.fxml +++ b/src/main/resources/fxml/Tasty_Pages_Main_Page.fxml @@ -32,133 +32,139 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> -<?import javafx.geometry.Insets?> +<?import javafx.geometry.*?> +<?import javafx.scene.control.*?> <?import javafx.scene.Cursor?> -<?import javafx.scene.control.Button?> -<?import javafx.scene.control.MenuButton?> -<?import javafx.scene.control.MenuItem?> -<?import javafx.scene.control.TextField?> -<?import javafx.scene.image.Image?> -<?import javafx.scene.image.ImageView?> -<?import javafx.scene.layout.AnchorPane?> -<?import javafx.scene.layout.ColumnConstraints?> -<?import javafx.scene.layout.GridPane?> -<?import javafx.scene.layout.Pane?> -<?import javafx.scene.layout.RowConstraints?> -<?import javafx.scene.layout.VBox?> -<?import javafx.scene.text.Font?> -<?import javafx.scene.text.Text?> - -<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"> - <children> - <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" style="-fx-background-color: ffffff;" VBox.vgrow="ALWAYS"> - <children> - <MenuButton contentDisplay="GRAPHIC_ONLY" graphicTextGap="0.0" layoutX="18.0" layoutY="21.0" mnemonicParsing="false" style="-fx-background-color: transparent;" textFill="TRANSPARENT"> - <items> - <MenuItem mnemonicParsing="false" text="Home" /> - <MenuItem mnemonicParsing="false" text="Meal Plan" /> - <MenuItem mnemonicParsing="false" text="Shopping List" /> - </items> - <graphic> - <ImageView fitHeight="30.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true"> - <image> - <Image url="@../images/Tasty_Pages_Menu_Button.png" /> - </image> - </ImageView> - </graphic> - <cursor> - <Cursor fx:constant="DEFAULT" /> - </cursor> - <font> - <Font size="1.0E-4" /> - </font> - </MenuButton> - <TextField layoutX="450.0" layoutY="27.0" style="-fx-border-color: D91c1c; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10;" /> - <GridPane layoutX="58.0" layoutY="99.0" prefHeight="390.0" prefWidth="512.0"> - <columnConstraints> - <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> - <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> - <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> - </columnConstraints> - <rowConstraints> - <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> - <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> - </rowConstraints> - <children> - <Pane prefHeight="192.0" prefWidth="159.0" style="-fx-background-color: dedede; -fx-background-radius: 15;"> - <GridPane.margin> - <Insets bottom="6.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - <children> - <Button contentDisplay="CENTER" layoutX="8.0" layoutY="6.0" mnemonicParsing="false" prefHeight="169.0" prefWidth="144.0" style="-fx-background-color: transparent;" text="Button" textFill="TRANSPARENT"> - <graphic> - <ImageView fitHeight="67.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true"> - <image> - <Image url="@../images/Tasty_Pages_Plus_Icon.png" /> - </image> - </ImageView> - </graphic> - </Button> - </children> - </Pane> - <Pane prefHeight="155.0" prefWidth="154.0" style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="1"> - <GridPane.margin> - <Insets bottom="40.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - </Pane> - <Pane prefHeight="155.0" prefWidth="154.0" style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="2"> - <GridPane.margin> - <Insets bottom="40.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - </Pane> - <Pane prefHeight="198.0" prefWidth="163.0" style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.rowIndex="1"> - <GridPane.margin> - <Insets bottom="40.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - </Pane> - <Pane prefHeight="155.0" prefWidth="154.0" style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="1" GridPane.rowIndex="1"> - <GridPane.margin> - <Insets bottom="40.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - </Pane> - <Pane prefHeight="155.0" prefWidth="154.0" style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="2" GridPane.rowIndex="1"> - <GridPane.margin> - <Insets bottom="40.0" left="6.0" right="6.0" top="6.0" /> - </GridPane.margin> - </Pane> - <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" GridPane.columnIndex="1" GridPane.valignment="BOTTOM"> - <GridPane.margin> - <Insets bottom="18.0" left="6.0" /> - </GridPane.margin> - </Text> - <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" GridPane.columnIndex="2" GridPane.valignment="BOTTOM"> - <GridPane.margin> - <Insets bottom="18.0" left="6.0" /> - </GridPane.margin> - </Text> - <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> - <GridPane.margin> - <Insets bottom="18.0" left="6.0" /> - </GridPane.margin> - </Text> - <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> - <GridPane.margin> - <Insets bottom="18.0" left="6.0" /> - </GridPane.margin> - </Text> - <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" GridPane.columnIndex="2" GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> - <GridPane.margin> - <Insets bottom="18.0" left="6.0" /> - </GridPane.margin> - </Text> - </children> - </GridPane> - <ImageView fitHeight="28.0" fitWidth="28.0" layoutX="453.0" layoutY="28.0" pickOnBounds="true" preserveRatio="true"> - <image> - <Image url="@../images/Tasty_Pages_Search_Material_Design_Icons.png" /> - </image> - </ImageView> - </children> - </AnchorPane> - </children> -</VBox> +<?import javafx.scene.image.*?> +<?import javafx.scene.layout.*?> +<?import javafx.scene.text.*?> +<AnchorPane prefHeight="400.0" prefWidth="640.0" style="-fx-background-color: ffffff;" VBox.vgrow="ALWAYS" + xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" + fx:controller="mi.hdm.controllers.MainPageController"> + <children> + <MenuButton contentDisplay="GRAPHIC_ONLY" graphicTextGap="0.0" layoutX="18.0" layoutY="21.0" + mnemonicParsing="false" style="-fx-background-color: transparent;" textFill="TRANSPARENT"> + <items> + <MenuItem mnemonicParsing="false" onAction="#changeSceneToHome" text="Home"/> + <MenuItem mnemonicParsing="false" onAction="#changeSceneToMealPlan" text="Meal Plan"/> + <MenuItem mnemonicParsing="false" onAction="#changeSceneToShoppingList" text="Shopping List"/> + </items> + <graphic> + <ImageView fitHeight="30.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@../images/Tasty_Pages_Menu_Button.png"/> + </image> + </ImageView> + </graphic> + <cursor> + <Cursor fx:constant="DEFAULT"/> + </cursor> + <font> + <Font size="1.0E-4"/> + </font> + </MenuButton> + <TextField layoutX="450.0" layoutY="27.0" + style="-fx-border-color: D91c1c; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10;"/> + <GridPane layoutX="58.0" layoutY="99.0" prefHeight="390.0" prefWidth="512.0" AnchorPane.leftAnchor="58.0"> + <columnConstraints> + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> + </columnConstraints> + <rowConstraints> + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/> + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/> + </rowConstraints> + <children> + <Pane prefHeight="192.0" prefWidth="159.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;"> + <GridPane.margin> + <Insets bottom="6.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + <Button contentDisplay="CENTER" layoutX="8.0" layoutY="6.0" mnemonicParsing="false" + onAction="#addRecipe" prefHeight="169.0" prefWidth="144.0" + style="-fx-background-color: transparent;" text="Button" textFill="TRANSPARENT"> + <graphic> + <ImageView fitHeight="67.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@../images/Tasty_Pages_Plus_Icon.png"/> + </image> + </ImageView> + </graphic> + <cursor> + <Cursor fx:constant="HAND"/> + </cursor> + </Button> + </Pane> + <Pane prefHeight="155.0" prefWidth="154.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="1"> + <GridPane.margin> + <Insets bottom="40.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + </Pane> + <Pane prefHeight="155.0" prefWidth="154.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="2"> + <GridPane.margin> + <Insets bottom="40.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + </Pane> + <Pane prefHeight="198.0" prefWidth="163.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.rowIndex="1"> + <GridPane.margin> + <Insets bottom="40.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + </Pane> + <Pane prefHeight="155.0" prefWidth="154.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="1" + GridPane.rowIndex="1"> + <GridPane.margin> + <Insets bottom="40.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + </Pane> + <Pane prefHeight="155.0" prefWidth="154.0" + style="-fx-background-color: dedede; -fx-background-radius: 15;" GridPane.columnIndex="2" + GridPane.rowIndex="1"> + <GridPane.margin> + <Insets bottom="40.0" left="6.0" right="6.0" top="6.0"/> + </GridPane.margin> + </Pane> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" + GridPane.columnIndex="1" GridPane.valignment="BOTTOM"> + <GridPane.margin> + <Insets bottom="18.0" left="6.0"/> + </GridPane.margin> + </Text> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" + GridPane.columnIndex="2" GridPane.valignment="BOTTOM"> + <GridPane.margin> + <Insets bottom="18.0" left="6.0"/> + </GridPane.margin> + </Text> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" + GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> + <GridPane.margin> + <Insets bottom="18.0" left="6.0"/> + </GridPane.margin> + </Text> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" + GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> + <GridPane.margin> + <Insets bottom="18.0" left="6.0"/> + </GridPane.margin> + </Text> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text" wrappingWidth="122.73394775390625" + GridPane.columnIndex="2" GridPane.rowIndex="1" GridPane.valignment="BOTTOM"> + <GridPane.margin> + <Insets bottom="18.0" left="6.0"/> + </GridPane.margin> + </Text> + </children> + </GridPane> + <ImageView fitHeight="28.0" fitWidth="28.0" layoutX="453.0" layoutY="28.0" pickOnBounds="true" + preserveRatio="true"> + <image> + <Image url="@../images/Tasty_Pages_Search_Material_Design_Icons.png"/> + </image> + </ImageView> + </children> +</AnchorPane> diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index b75fabd227dca2e4f4f1b5919415ef17e2e1e80c..5e7e35c3c057ad9977ed5032478a96fd0f87f4ce 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -14,7 +14,7 @@ <Logger name="mi.hdm.GuiDriver" level="info"> <AppenderRef ref="A1"/> </Logger> - <Root level="debug"> + <Root level="info"> <AppenderRef ref="STDOUT"/> </Root> </Loggers> diff --git a/src/test/java/mi/hdm/recipes/CategoryTest.java b/src/test/java/mi/hdm/recipes/CategoryTest.java index 2c0de70bc751e4319d30f4a77bda4479f16291d4..577fbe2976d09f916c6d48fd4a975afc40c17f5d 100644 --- a/src/test/java/mi/hdm/recipes/CategoryTest.java +++ b/src/test/java/mi/hdm/recipes/CategoryTest.java @@ -2,32 +2,35 @@ package mi.hdm.recipes; import mi.hdm.exceptions.InvalidCategoryException; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class CategoryTest { - CategoryManager underTest = CategoryManager.getInstance(); + private final CategoryManager underTest = new CategoryManager(); + + @BeforeEach + public void setup() { + underTest.clearCategories(); + } @Test public void shouldNotBeAbleToAddIdenticalName() { - underTest.clearCategories(); underTest.addCategory("Mittag", 0x100000); - underTest.addCategory("Mittag", 0x100040); + Assertions.assertThrows(InvalidCategoryException.class, () -> underTest.addCategory("Mittag", 0x100040)); Assertions.assertEquals(1, underTest.getAllCategories().size()); } @Test public void shouldNotBeAbleToAddIdenticalCode() { - underTest.clearCategories(); underTest.addCategory("Morgen", 0x100040); - underTest.addCategory("Mittag", 0x100040); + Assertions.assertThrows(InvalidCategoryException.class, () -> underTest.addCategory("Mittag", 0x100040)); Assertions.assertEquals(1, underTest.getAllCategories().size()); } @Test public void shouldBeAbleToAddCategory() { - underTest.clearCategories(); underTest.addCategory("Morgen", 0x100000); underTest.addCategory("Abend", 0x100010); @@ -37,7 +40,6 @@ public class CategoryTest { @Test public void canRemoveCategoryByName() { //given - underTest.clearCategories(); underTest.addCategory("Jan ist cool", 0xFF0000); //when diff --git a/src/test/java/mi/hdm/recipes/IngredientTest.java b/src/test/java/mi/hdm/recipes/IngredientTest.java index f32ffceacd92f08fa5decad5c00f85f551bae359..12d9cae2d2f9a62f17438c91f4a1377f735c6981 100644 --- a/src/test/java/mi/hdm/recipes/IngredientTest.java +++ b/src/test/java/mi/hdm/recipes/IngredientTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; public class IngredientTest { - IngredientManager underTest = IngredientManager.getInstance(); + IngredientManager underTest = new IngredientManager(); NutritionTable tt = ValidObjectsPool.getValidNutritionTableOne(); @BeforeEach @@ -33,9 +33,7 @@ public class IngredientTest { @Test public void shouldNotBeAbleToAddIdenticalName() { underTest.addIngredient(Measurement.GRAM, "Banana", tt); - underTest.addIngredient(Measurement.PIECE, "Banana", tt); - - Assertions.assertEquals(1, underTest.getAllIngredients().size()); + Assertions.assertThrows(InvalidIngredientException.class, () -> underTest.addIngredient(Measurement.PIECE, "Banana", tt)); } @Test diff --git a/src/test/java/mi/hdm/shoppingList/ShoppingListTest.java b/src/test/java/mi/hdm/shoppingList/ShoppingListTest.java index b2756c64d1aa3d243af7a7360c073631781423cc..ec06b37f4fa1afd4932b91b7f78c94fd218c02af 100644 --- a/src/test/java/mi/hdm/shoppingList/ShoppingListTest.java +++ b/src/test/java/mi/hdm/shoppingList/ShoppingListTest.java @@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; class ShoppingListTest { - private final ShoppingList underTest = ShoppingList.getInstance(); + private final ShoppingList underTest = new ShoppingList(); private final static Ingredient ing1 = ValidObjectsPool.getValidIngredientOne(); private final static Ingredient ing2 = ValidObjectsPool.getValidIngredientTwo();