Class CookBookFrame
java.lang.Object
edu.ntnu.stud.controller.framecontroller.CookBookFrame
Frame used to display the cook book. This is the controller class for the
cookBookFrame.fxml file. The frame displays the recipes from a JSON file
in a scrollable view. Each recipe is displayed with an image and a name.
The user can click on the "More" button to view more information about
a specific recipe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Nested class to handle the "Add" and "More" buttons for the recipes.protected class
Nested class to create the components of the CookBook frame.protected static class
Nested class to read the JSON file containing the recipes. -
Constructor Summary
ConstructorsConstructorDescriptionCookBookFrame
(MainApplication mainApplication) The constructor for this class creates a new CookBookFrame object. -
Method Summary
Modifier and TypeMethodDescriptionjavafx.scene.control.ScrollPane
Returns the CookBook frame.readImageFromJson
(int i, org.json.JSONArray jsonArray) Nested method to read the image of a recipe from the JSON file.readNameOfRecipe
(int i, org.json.JSONArray jsonArray) Nested method to read the name of a recipe from the JSON file.javafx.scene.layout.HBox
setAddMoreButtons
(int index, org.json.JSONArray jsonArray, int rowCounter) Nested method to set the "Add" and "More" buttons for a recipe.void
setImageFromJson
(String filepath) Sets the image of a recipe with the given filepath.
-
Constructor Details
-
CookBookFrame
The constructor for this class creates a new CookBookFrame object. The constructor initializes the JSON reader, frame components and button handler, and loads the cookBookFrame.fxml file. These components are used to divide the responsibilities of the class and to create and manage the frame.- Parameters:
mainApplication
- The main application object, used for the buttons to interact with the main application.- Throws:
IOException
- If the fxml file is not found.- See Also:
-
-
Method Details
-
setImageFromJson
Sets the image of a recipe with the given filepath. The method reads the JSON file to get this filepath. If the file is not found, a FileNotFoundException is thrown. The message of the exception is then logged.- Parameters:
filepath
- The path to the JSON file containing the recipes.- See Also:
-
readImageFromJson
Nested method to read the image of a recipe from the JSON file.- Parameters:
i
- The index of the recipe in the JSON file.jsonArray
- The JSON array containing the recipes.- Returns:
- The image of the recipe at the given index.
- See Also:
-
readNameOfRecipe
Nested method to read the name of a recipe from the JSON file.- Parameters:
i
- The index of the recipe in the JSON file.jsonArray
- The JSON array containing the recipes.- Returns:
- The name of the recipe at the given index.
- See Also:
-
setAddMoreButtons
public javafx.scene.layout.HBox setAddMoreButtons(int index, org.json.JSONArray jsonArray, int rowCounter) Nested method to set the "Add" and "More" buttons for a recipe.- Parameters:
index
- The index of the recipe in the JSON file.jsonArray
- The JSON array containing the recipes.rowCounter
- The row number of the recipe in the frame.- Returns:
- The HBox containing the "Add" and "More" buttons for the recipe.
- See Also:
-
getCookBookFrame
public javafx.scene.control.ScrollPane getCookBookFrame()Returns the CookBook frame.- Returns:
- The CookBook frame.
-