Skip to content

Commit

Permalink
Created detailed recipe UI
Browse files Browse the repository at this point in the history
Co-authored-by: Trung Dat Luu dashluu9121997@gmail.com
Co-authored-by: Timothy Nguyen timothyhnguyen234@gmail.com
  • Loading branch information
AllKeng committed Nov 7, 2023
1 parent 6d0c367 commit b112c73
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
57 changes: 57 additions & 0 deletions app/src/main/java/code/client/View/DetailsAppFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package code.client.View;

import java.util.ArrayList;

import code.client.Model.Recipe;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class DetailsAppFrame {
private ArrayList<Scene> scenes;
private Stage primaryStage;

public Scene getScene() {
VBox root = new VBox();
root.setSpacing(20);
root.setAlignment(Pos.CENTER);
root.setStyle("-fx-background-color: #F0F8FF;");

VBox setupContainer = new VBox();
setupContainer.setSpacing(10);

// Hardcoded value for now, recipe value for it should be changing
Recipe temp = new Recipe("1", "Fried Chicken and Egg Fried Rice");
temp.addIngredient("2 chicken breasts, diced");
temp.addIngredient("2 large eggs");
temp.addIngredient("2 cups cooked rice");
temp.addIngredient("2 tablespoons vegetable oil");
temp.addInstruction("1. Heat the vegetable oil in a large pan over medium-high heat.");

RecipeDetailsUI details = new RecipeDetailsUI(temp);

TextField title = details.getTitleField();
title.setAlignment(Pos.CENTER);
title.setStyle("-fx-font-weight: bold; -fx-font-size: 20;");
root.getChildren().add(title);

setupContainer.getChildren().add(details);
root.getChildren().add(setupContainer);

return new Scene(root, 700, 600);
}

/**
* This method provides the UI holder with the different scenes that can be
* switched between.
*
* @param primaryStage - Main stage that has the window
* @param scenes - list of different scenes to switch between.
*/
public void setScenes(Stage primaryStage, ArrayList<Scene> scenes) {
this.scenes = scenes;
this.primaryStage = primaryStage;
}
}
45 changes: 45 additions & 0 deletions app/src/main/java/code/client/View/RecipeDetailsUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package code.client.View;

import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;

import java.util.Iterator;

import code.client.Model.Recipe;

public class RecipeDetailsUI extends HBox {
private final TextField titleTextField;
private final TextArea ingredientTextArea;
private final TextArea instructionTextArea;

public RecipeDetailsUI(Recipe recipe) {
titleTextField = new TextField();
ingredientTextArea = new TextArea();
instructionTextArea = new TextArea();

titleTextField.setText(recipe.getTitle());

StringBuilder ingredientBuilder = new StringBuilder();
Iterator<String> ingredientIterator = recipe.getIngredientIterator();
while (ingredientIterator.hasNext()) {
ingredientBuilder.append(ingredientIterator.next() + "\n");
}
ingredientTextArea.setText(ingredientBuilder.toString());

StringBuilder instructionBuilder = new StringBuilder();
Iterator<String> instructionIterator = recipe.getInstructionIterator();
while (instructionIterator.hasNext()) {
instructionBuilder.append(instructionIterator.next() + "\n");
}
instructionTextArea.setText(instructionBuilder.toString());

// getChildren().add(titleTextField);
getChildren().add(ingredientTextArea);
getChildren().add(instructionTextArea);
}

public TextField getTitleField() {
return titleTextField;
}
}

0 comments on commit b112c73

Please sign in to comment.