Merge branch 'UI' into 'main'

ui to work with buttons for the rest

See merge request cse1105/2025-2026/teams/csep-team-76!3
This commit is contained in:
Aysegul Aydinlik 2025-11-27 17:24:13 +01:00
commit 4fb216373a
2 changed files with 348 additions and 0 deletions

View file

@ -0,0 +1,192 @@
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 OverviewCtrl {
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 OverviewCtrl(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
private 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");
}
}

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.OverviewCtrl">
<!-- 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="#switchToEngelish" 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="#MazimizeWindow" 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 fx:id="ingredientsListView" text="Ingredients">
<font>
<Font name="System Bold" size="14.0" />
</font></Label>
<ListView prefHeight="167.0" prefWidth="912.0" />
<Button fx:id="addIngredientButton" onAction="#addIngredient" text="Add Ingredient" />
</VBox>
<!-- Preparation -->
<VBox spacing="10">
<Label fx:id="preparationListView" text="Preparation">
<font>
<Font name="System Bold" size="14.0" />
</font></Label>
<ListView prefHeight="200.0" />
<Button fx:id="addPreparationStepButton" onAction="#addPreperationStep" text="Add Step" />
</VBox>
<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>