diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java index dac2b0efb7ab13ec65ae6e95d98efd66b20e6428..e2df33f50a05c944abaca08c1dee82c52867c6f9 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java @@ -1,4 +1,92 @@ package no.ntnu.idatt1002.demo.controller; -public class AddIngredientController { +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Scene; +import javafx.scene.control.ListView; +import javafx.event.ActionEvent; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ResourceBundle; +import java.util.stream.Collectors; + + +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import no.ntnu.idatt1002.demo.data.recipes.FoodItem; + +public class AddIngredientController implements Initializable { + +/* ArrayList<String> testIngredients = new ArrayList<>( + Arrays.asList("Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries") + *//*Arrays.asList(FoodItem.values().toString())*//* + );*/ + + /*List<String> testIngredients = Arrays.asList("Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries");*/ + String[] testIngredients = {"Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries"}; + + + private List<String> stringIngredients = Arrays.stream(FoodItem.values()).toList().stream().map(value -> value.label).toList(); + private int noLengthOfList = stringIngredients.size(); + String[] arrayIngredients = stringIngredients.stream().toArray(String[] ::new); + //private String[] arrayIngredients + private ObservableList<String> ingredients = FXCollections.observableArrayList(stringIngredients); + + @FXML + private Button addBtn; + + @FXML + private ListView<String> listView; + + @FXML + private TextField searchBar; + + @FXML + private Button searchBtn; + + @FXML + void addToFridge(ActionEvent event) { + System.out.printf("Add ingredient to fridge"); + String item = listView.getSelectionModel().getSelectedItem(); + System.out.printf("The item was: %s", item); + + // Add to existing at hand and write to file. if not null/blank + + } + + @FXML + void search(ActionEvent event) { + System.out.printf("Searching for ingredient to fridge"); + listView.getItems().clear(); + listView.getItems().addAll(searchList(searchBar.getText(), arrayIngredients)); + + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + + /* ObservableList ingredients = FXCollections.observableArrayList(testIngredients);*/ + + + + /* ObservableList<FoodItem> ingredients = FXCollections.observableArrayList( + FoodItem.values());*/ + // Fill list with ingredients + listView.setItems(ingredients); + + } + + private List<String> searchList(String searchWords, String[] listOfStrings) { + String[] searchWordsArray = searchWords.trim().split(" "); + return Arrays.stream(listOfStrings).filter((in) -> { + return Arrays.stream(searchWordsArray).allMatch((word) -> + in.toLowerCase().contains(word.toLowerCase())); + }).collect(Collectors.toList()); + } + } diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java index 9e830b4ea39f1ea3ceeb8466b5e3ed79b2fa486c..7dbe34b9dc67fc4091362a068e34299c19394b46 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java @@ -1,19 +1,90 @@ package no.ntnu.idatt1002.demo.controller; +import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.DialogPane; +import javafx.stage.Stage; +import no.ntnu.idatt1002.demo.data.Economics.FileHandling; import java.io.IOException; +import java.net.URL; +import java.util.Optional; +import java.util.ResourceBundle; -public class SuggestRecipesController { +public class SuggestRecipesController implements Initializable { + FileHandling fileHandling; + @FXML + private Button addToFridgeBtn; + + @FXML + private Button goBackBtn; @FXML - private void addToFridge(ActionEvent event) throws IOException { + private void addIngredient(ActionEvent event) throws IOException { FXMLLoader loader = new FXMLLoader(); - System.out.printf("Time to pop up the pop-up!"); + System.out.println("Time to pop up the pop-up!"); + loader.setLocation(getClass().getResource("/view/AddIngredient.fxml")); + DialogPane addIngredientPane = loader.load(); + + AddIngredientController addIngredientController = loader.getController(); + + Dialog<ButtonType> dialog = new Dialog<>(); + dialog.setDialogPane(addIngredientPane); + dialog.setTitle("Hallays!"); + + Optional<ButtonType> clickedButton = dialog.showAndWait(); + if (clickedButton.get() == ButtonType.OK) { + System.out.printf("Clickecked OK!"); + }else if(clickedButton.get() == ButtonType.CANCEL) { + System.out.printf("Close the dialog"); + } + + + } + + @FXML + private void goBack(ActionEvent event) throws IOException { + FXMLLoader loader = new FXMLLoader(); + + System.out.printf("Back button pressed"); + loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml")); + + Parent root = loader.load(); + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.show(); + + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + fileHandling = new FileHandling(); + + /* + + //Initialize columns + setColumns(); + + //Initialize registers and tableview + incomeRegister = loadIncomeDataFromFile("Income"); + income = FXCollections.observableArrayList(incomeRegister.getItems()); + incomeTableView.setItems(income); + + expenseRegister = loadExpenseDataFromFile("Expense"); + expenses = FXCollections.observableArrayList(expenseRegister.getItems()); + expenseTableView.setItems(expenses);*/ } } diff --git a/src/main/resources/Economics/Expense.register b/src/main/resources/Economics/Expense.register index ec17f6ed2d4603e74ca8e338c12178108b19d29a..92307dbae98c7c3d8218aa817518484f044637c5 100644 --- a/src/main/resources/Economics/Expense.register +++ b/src/main/resources/Economics/Expense.register @@ -15,3 +15,9 @@ amount=10.0 isRecurring=Not recurring category=FOOD +date=2023-04-15 +description=iphone +amount=5000.0 +isRecurring=Not recurring +category=OTHER + diff --git a/src/main/resources/Economics/Income.register b/src/main/resources/Economics/Income.register index 80d6de630145291c7e1a9fd83856c885274554f2..93674a4dfe9cdb1222f2d895a855da5af2890879 100644 --- a/src/main/resources/Economics/Income.register +++ b/src/main/resources/Economics/Income.register @@ -8,3 +8,15 @@ amount=500.0 isRecurring=Not recurring category=SALARY +date=2023-04-15 +description=bday +amount=1000.0 +isRecurring=Not recurring +category=GIFT + +date=2023-04-15 +description=finn +amount=100.0 +isRecurring=Not recurring +category=SALARY + diff --git a/src/main/resources/style.css b/src/main/resources/style.css index 17d5be12ff0d690724fb716afa44d2a0644a524e..013ec34c43a0110b13003521c72c1145e5aab704 100644 --- a/src/main/resources/style.css +++ b/src/main/resources/style.css @@ -1,6 +1,6 @@ .recipe-tile { - -fx-background-color: rgba(151, 175, 151, 0.8); + -fx-background-color: rgb(215, 153, 27); -fx-background-radius: 25; } \ No newline at end of file diff --git a/src/main/resources/view/AddIngredient.fxml b/src/main/resources/view/AddIngredient.fxml index 3cc1336bb2ea43e2ab77ebfe602bdf07eb243b10..89a4fcd2e33da791375ca7be2979d2c84b86e6df 100644 --- a/src/main/resources/view/AddIngredient.fxml +++ b/src/main/resources/view/AddIngredient.fxml @@ -1,30 +1,53 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> -<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.AddIngredientController"> - <children> - <BorderPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> - <center> - <VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER" /> - </center> - <top> - <HBox prefHeight="84.0" prefWidth="600.0" BorderPane.alignment="CENTER"> +<DialogPane xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.AddIngredientController"> + <content> + <AnchorPane prefHeight="400.0" prefWidth="600.0"> + <padding> + <Insets top="20.0" /> + </padding> + <children> + <VBox layoutX="14.0" prefHeight="348.0" prefWidth="600.0"> <children> - <Pane prefHeight="84.0" prefWidth="0.0"> + <HBox prefHeight="100.0" prefWidth="200.0" spacing="20.0"> <children> - <Label text="Add ingredients to the Fridge"> + <TextField fx:id="searchBar" prefHeight="36.0" prefWidth="438.0" promptText="Search for ingredient"> + <padding> + <Insets bottom="10.0" left="20.0" right="20.0" top="10.0" /> + </padding> + <HBox.margin> + <Insets /> + </HBox.margin> + </TextField> + <Button fx:id="searchBtn" alignment="CENTER" contentDisplay="CENTER" defaultButton="true" mnemonicParsing="false" onAction="#search" text="Search" textAlignment="CENTER"> <font> - <Font size="24.0" /> + <Font size="14.0" /> </font> - </Label> + <HBox.margin> + <Insets /> + </HBox.margin> + </Button> </children> - </Pane> - <Pane prefHeight="84.0" prefWidth="93.0"> + <VBox.margin> + <Insets left="25.0" right="25.0" /> + </VBox.margin> + </HBox> + <ListView fx:id="listView" prefHeight="311.0" prefWidth="590.0"> + <padding> + <Insets bottom="10.0" left="20.0" right="20.0" top="10.0" /> + </padding> + <VBox.margin> + <Insets left="25.0" right="25.0" /> + </VBox.margin> + </ListView> + <Pane prefHeight="81.0" prefWidth="600.0"> <children> - <Button layoutX="7.0" layoutY="28.0" mnemonicParsing="false" text="Close"> + <Button fx:id="addBtn" layoutX="275.0" layoutY="7.0" mnemonicParsing="false" onAction="#addToFridge" text="ADD"> <font> <Font size="14.0" /> </font> @@ -32,28 +55,21 @@ </children> </Pane> </children> - </HBox> - </top> - <bottom> - <Pane prefHeight="55.0" prefWidth="600.0" BorderPane.alignment="CENTER"> - <children> - <HBox> - <children> - <Pane prefHeight="815.0" prefWidth="347.0"> - <children> - <TextField layoutX="90.0" layoutY="8.0" prefHeight="31.0" prefWidth="198.0" /> - </children> - </Pane> - <Pane prefHeight="815.0" prefWidth="269.0"> - <children> - <Button layoutX="8.0" layoutY="20.0" mnemonicParsing="false" text="Add" /> - </children> - </Pane> - </children> - </HBox> - </children> - </Pane> - </bottom> - </BorderPane> - </children> -</AnchorPane> + </VBox> + </children></AnchorPane> + </content> + <header> + <Label fx:id="addIngredientPane" alignment="CENTER" contentDisplay="CENTER" text="Add an ingredient to the fridge"> + <font> + <Font size="24.0" /> + </font> + <padding> + <Insets bottom="25.0" top="20.0" /> + </padding> + </Label> + </header> + <buttonTypes> + <ButtonType fx:constant="OK" /> + <ButtonType fx:constant="CANCEL" /> + </buttonTypes> +</DialogPane> diff --git a/src/main/resources/view/SuggestRecipes.fxml b/src/main/resources/view/SuggestRecipes.fxml index 7e07d087628d08102cc1816f9438ca6ab9eefae6..19bffffa654b5536d2058b73ebc62a5ccad500fb 100644 --- a/src/main/resources/view/SuggestRecipes.fxml +++ b/src/main/resources/view/SuggestRecipes.fxml @@ -29,7 +29,7 @@ <ListView prefHeight="472.0" prefWidth="421.0" /> <Pane prefHeight="47.0" prefWidth="421.0"> <children> - <Button fx:id="addFridgeButton" layoutX="80.0" layoutY="9.0" mnemonicParsing="false" onAction="#addToFridge" text="Add another available ingredient"> + <Button fx:id="addToFridgeBtn" layoutX="80.0" layoutY="9.0" mnemonicParsing="false" onAction="#addIngredient" text="Add another available ingredient"> <font> <Font size="14.0" /> </font> @@ -49,7 +49,7 @@ <left> <Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <children> - <Button alignment="CENTER" contentDisplay="CENTER" layoutX="62.0" layoutY="24.0" mnemonicParsing="false" text="Go Back" textAlignment="CENTER"> + <Button fx:id="goBackBtn" alignment="CENTER" contentDisplay="CENTER" layoutX="62.0" layoutY="24.0" mnemonicParsing="false" onAction="#goBack" text="Go Back" textAlignment="CENTER"> <font> <Font size="14.0" /> </font>