Show foodpalApplication when running

This commit is contained in:
Mei Chang van der Werff 2025-12-01 15:39:01 +01:00
commit 1c8f5780d9
4 changed files with 62 additions and 25 deletions

View file

@ -20,6 +20,7 @@ import static com.google.inject.Guice.createInjector;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import client.scenes.FoodpalApplicationCtrl;
import com.google.inject.Injector; import com.google.inject.Injector;
import client.scenes.AddQuoteCtrl; import client.scenes.AddQuoteCtrl;
@ -50,8 +51,9 @@ public class Main extends Application {
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml"); var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml"); var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml");
var mainCtrl = INJECTOR.getInstance(MainCtrl.class); var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, add); mainCtrl.initialize(primaryStage, overview, add, foodpal);
} }
} }

View file

@ -0,0 +1,211 @@
package client.scenes;
import java.util.List;
import commons.Recipe;
import jakarta.inject.Inject;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
public class FoodpalApplicationCtrl {
private final MainCtrl mainCtrl;
// all of these aren't used with only my part of the code
// everything in the top bar ===
@FXML
private Button flagEnButton; //already here for advanced stuff
@FXML
private Button flagNlButton; //already here for advanced stuff
@FXML
private Button flagPlButton; //already here for advanced stuff
@FXML
private Button refreshButton;
@FXML
private Button closeButton; //already here for advanced stuff
@FXML
private Button maximizeButton; //already here for advanced stuff
@FXML
private Button minimizeButton; //already here for advanced stuff
// everything in the left lane
@FXML
private ListView<Recipe> recipeList;
@FXML
private Button addRecipeButton;
@FXML
private Button removeRecipeButton;
// === CENTER: RECIPE DETAILS ===
@FXML
private Label recipeNameLabel;
@FXML
private Button editRecipeTitleButton;
@FXML
private ListView<String> ingredientsListView;
@FXML
private Button addIngredientButton;
@FXML
private ListView<String> preparationListView;
@FXML
private Button addPreparationStepButton;
@Inject
public FoodpalApplicationCtrl(MainCtrl mainCtrl) {
this.mainCtrl = mainCtrl;
}
@FXML
private void initialize() {
// Show recipe name in the list
recipeList.setCellFactory(list -> new ListCell<>() {
@Override
protected void updateItem(Recipe item, boolean empty) {
super.updateItem(item, empty);
setText(empty || item == null ? "" : item.getName());
}
});
// When your selection changes, update details in the panel
recipeList.getSelectionModel().selectedItemProperty().addListener(
(obs, oldRecipe, newRecipe) -> showRecipeDetails(newRecipe)
);
// Double-click to go to detail screen
recipeList.setOnMouseClicked(event -> {
final int DOUBLE_CLICK = 2; //to not get magic number:P
if (event.getClickCount() == DOUBLE_CLICK) {
openSelectedRecipe();
}
});
refresh();
}
// till the all the code from everyone is implemented for now to not have errors
private void showRecipeDetails(Recipe newRecipe) {
}
// Button handlers
@FXML
public void refresh() {
// TODO: someone else doing this
List<Recipe> recipes = showRecipeDetails();
recipeList.getItems().setAll(recipes);
// Select first recipe in the list by default
if (!recipes.isEmpty()) {
recipeList.getSelectionModel().selectFirst();
}
}
// to remove error till everything else is implemented
private List<Recipe> showRecipeDetails() {
return List.of();
}
@FXML
private void addRecipe() {
// Navigate to "create recipe" screen (should be like a pop-up or new screen or just another place in the app)
mainCtrl.showOverview();
}
@FXML
private void removeSelectedRecipe() {
Recipe selected = recipeList.getSelectionModel().getSelectedItem();
if (selected == null) {
return;
}
// TODO: someone else todo
recipeList.getItems().remove(selected);
showRecipeDetails(null);
}
@FXML
private void openSelectedRecipe() {
Recipe selected = recipeList.getSelectionModel().getSelectedItem();
if (selected == null) {
return;
}
// Let MainCtrl open the full detail screen
mainCtrl.showOverview(); //I had showrecipedetail but intelij says showoverview
}
@FXML
private void editRecipeTitle() {
// TODO: someone else todo
// For now reuse openSelectedRecipe()
openSelectedRecipe();
}
@FXML
private void addIngredient() {
// TODO: make it possible to add ingredient to current recipe
System.out.println("Add ingredient clicked");
}
@FXML
private void addPreparationStep() {
// TODO: make it possible to add step to current recipe
System.out.println("Add preparation step clicked");
}
// Language buttons
@FXML
private void switchToEnglish() {
System.out.println("Switch language to EN");
}
@FXML
private void switchToDutch() {
System.out.println("Switch language to NL");
}
@FXML
private void switchToPolish() {
System.out.println("Switch language to PL");
}
@FXML
private void closeWindow() {
System.out.println("Close window");
}
@FXML
private void maximizeWindow() {
System.out.println("Maximize window");
}
@FXML
private void minimizeWindow() {
System.out.println("Minimize window");
}
@FXML
private void MakePrintable() {
System.out.println("Recipe printed");
}
}

View file

@ -30,16 +30,26 @@ public class MainCtrl {
private AddQuoteCtrl addCtrl; private AddQuoteCtrl addCtrl;
private Scene add; private Scene add;
public void initialize(Stage primaryStage, Pair<QuoteOverviewCtrl, Parent> overview, private FoodpalApplicationCtrl foodpalCtrl;
Pair<AddQuoteCtrl, Parent> add) { private Scene foodpal;
public void initialize(Stage primaryStage,
Pair<QuoteOverviewCtrl, Parent> overview,
Pair<AddQuoteCtrl, Parent> add,
Pair<FoodpalApplicationCtrl, Parent> foodpal){
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
this.overviewCtrl = overview.getKey(); this.overviewCtrl = overview.getKey();
this.overview = new Scene(overview.getValue()); this.overview = new Scene(overview.getValue());
this.addCtrl = add.getKey(); this.addCtrl = add.getKey();
this.add = new Scene(add.getValue()); this.add = new Scene(add.getValue());
showOverview(); this.foodpalCtrl = foodpal.getKey();
this.foodpal = new Scene(foodpal.getValue());
showFoodpal();
primaryStage.show(); primaryStage.show();
} }
@ -54,4 +64,10 @@ public class MainCtrl {
primaryStage.setScene(add); primaryStage.setScene(add);
add.setOnKeyPressed(e -> addCtrl.keyPressed(e)); add.setOnKeyPressed(e -> addCtrl.keyPressed(e));
} }
public void showFoodpal(){
primaryStage.setTitle("FoodPal");
primaryStage.setScene(foodpal);
foodpalCtrl.refresh();
}
} }

View file

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<BorderPane prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.FoodpalApplicationCtrl">
<!-- TOP BAR -->
<top>
<HBox spacing="10">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="198.0" minWidth="10.0" prefWidth="130.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="2.0" prefWidth="70.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="54.0" minHeight="10.0" prefHeight="54.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="25.0" minHeight="6.0" prefHeight="6.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label prefHeight="56.0" prefWidth="158.0" text="FoodPal">
<font>
<Font name="System Bold" size="29.0" />
</font>
</Label>
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.rowIndex="2">
<buttons>
<ToolBar prefHeight="35.0" prefWidth="123.0">
<items>
<Button fx:id="flagEnButton" minWidth="33.0" onAction="#switchToEnglish" prefHeight="25.0" prefWidth="33.0" text="EN" />
<Button fx:id="flagNlButton" onAction="#switchToDutch" text="NL" />
<Button fx:id="flagPlButton" onAction="#switchToPolish" text="PL" />
</items>
</ToolBar>
</buttons>
</ButtonBar>
</children>
</GridPane>
<Pane HBox.hgrow="ALWAYS" />
<HBox spacing="5" />
<GridPane prefHeight="90.0" prefWidth="114.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="32.1666259765625" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="24.8333740234375" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="173.0" minWidth="10.0" prefWidth="28.6666259765625" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="34.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="closeButton" onAction="#closeWindow" text="X" GridPane.columnIndex="3" />
<Button fx:id="maximizeButton" onAction="#maximizeWindow" text="□" GridPane.columnIndex="2" />
<Button fx:id="minimizeButton" onAction="#minimizeWindow" text="-" GridPane.columnIndex="1" />
<Button fx:id="refreshButton" onAction="#refresh" prefHeight="25.0" prefWidth="34.0" text="⟳" GridPane.columnIndex="3" GridPane.rowIndex="2" />
</children>
</GridPane>
</HBox>
</top>
<!-- LEFT: RECIPE LIST -->
<left>
<VBox spacing="10">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<Label text="Recipes">
<font>
<Font name="System Bold" size="15.0" />
</font></Label>
<ListView fx:id="recipeList" />
<HBox spacing="10">
<Button fx:id="AddRecipeButton" onAction="#addRecipe" text="Add Recipe" />
<Button fx:id="RemoveRecipeButton" onAction="#removeSelectedRecipe" text="Remove Recipe" />
<Button mnemonicParsing="false" text="Clone" />
</HBox>
</VBox>
</left>
<!-- CENTER: RECIPE DETAILS -->
<center>
<VBox spacing="20">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<!-- Recipe title row -->
<HBox spacing="10">
<Label fx:id="replaceNameLabel" text="Recipe Name">
<font>
<Font name="System Bold" size="14.0" />
</font></Label>
<Button fx:id="editRecipeTitleButton" onAction="#editRecipeTitle" text="Edit" />
<Button fx:id="RemoveRecipeButton2" mnemonicParsing="false" onAction="#removeSelectedRecipe" text="Remove Recipe" />
<Button fx:id="printRecipe" mnemonicParsing="false" onAction="#MakePrintable" text="Print Recipe" />
</HBox>
<!-- Ingredients -->
<VBox spacing="10">
<Label text="Ingredients">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<ListView fx:id="ingredientsListView" prefHeight="167.0" prefWidth="912.0" />
<Button fx:id="addIngredientButton" onAction="#addIngredient" text="Add Ingredient" />
</VBox>
<!-- Preparation -->
<Label text="Preparation">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<ListView fx:id="preparationListView" prefHeight="200.0" />
<Button fx:id="addPreparationStepButton" onAction="#addPreparationStep" text="Add Step" />
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="890.6666870117188" minWidth="10.0" prefWidth="854.6666870117188" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="445.3333740234375" minWidth="10.0" prefWidth="57.33331298828125" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</VBox>
</center>
</BorderPane>