diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index b3faacf..78c7ae7 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -2,9 +2,11 @@ package client.scenes; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Locale; +import client.utils.LocaleAware; import client.utils.LocaleManager; import client.utils.ServerUtils; import commons.Recipe; @@ -16,13 +18,11 @@ import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; -public class FoodpalApplicationCtrl { +public class FoodpalApplicationCtrl implements LocaleAware { private final MainCtrl mainCtrl; private final ServerUtils server; private final LocaleManager localeManager; - - // 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 @@ -33,19 +33,13 @@ public class FoodpalApplicationCtrl { @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 + public Label recipesLabel; + @FXML private ListView recipeList; @@ -55,6 +49,9 @@ public class FoodpalApplicationCtrl { @FXML private Button removeRecipeButton; + @FXML + public Button cloneRecipeButton; + // === CENTER: RECIPE DETAILS === @FXML private Label recipeNameLabel; @@ -62,6 +59,18 @@ public class FoodpalApplicationCtrl { @FXML private Button editRecipeTitleButton; + @FXML + public Button removeRecipeButton2; + + @FXML + public Button printRecipeButton; + + @FXML + public Label ingredientsLabel; + + @FXML + public Label preparationLabel; + @FXML private ListView ingredientsListView; @@ -81,8 +90,7 @@ public class FoodpalApplicationCtrl { this.localeManager = localeManager; } - @FXML - private void initialize() throws IOException, InterruptedException { + public void initializeComponents() { // Show recipe name in the list recipeList.setCellFactory(list -> new ListCell<>() { @Override @@ -108,20 +116,50 @@ public class FoodpalApplicationCtrl { refresh(); } + @Override + public void updateText() { + addRecipeButton.setText(getLocaleString("menu.button.add.recipe")); + removeRecipeButton.setText(getLocaleString("menu.button.remove.recipe")); + cloneRecipeButton.setText(getLocaleString("menu.button.clone")); + + editRecipeTitleButton.setText(getLocaleString("menu.button.edit")); + removeRecipeButton2.setText(getLocaleString("menu.button.remove.recipe")); + printRecipeButton.setText(getLocaleString("menu.button.print")); + + recipesLabel.setText(getLocaleString("menu.label.recipes")); + ingredientsLabel.setText(getLocaleString("menu.label.ingredients")); + preparationLabel.setText(getLocaleString("menu.label.preparation")); + + addIngredientButton.setText(getLocaleString("menu.button.add.ingredient")); + addPreparationStepButton.setText(getLocaleString("menu.button.add.step")); + } + + @Override + public LocaleManager getLocaleManager() { + return localeManager; + } + // till the all the code from everyone is implemented for now to not have errors private void showRecipeDetails(Recipe newRecipe) { recipeNameLabel.setText(newRecipe.getName()); ingredientsListView.getItems().setAll(newRecipe.getIngredients()); preparationListView.getItems().setAll(newRecipe.getPreparationSteps()); - } // Button handlers @FXML - public void refresh() throws IOException, InterruptedException { + public void refresh() { // TODO: someone else doing this - List recipes = server.getRecipes(); + + List recipes; + try { + recipes = server.getRecipes(); + } catch (IOException | InterruptedException e) { + recipes = Collections.emptyList(); + System.err.println("Failed to load recipes: " + e.getMessage()); + } + recipeList.getItems().setAll(recipes); // Select first recipe in the list by default @@ -195,25 +233,19 @@ public class FoodpalApplicationCtrl { // Language buttons @FXML private void switchToEnglish() { - System.out.println("Switch language to EN"); localeManager.setLocale(Locale.of("en")); } @FXML private void switchToDutch() { - System.out.println("Switch language to NL"); localeManager.setLocale(Locale.of("nl")); } @FXML private void switchToPolish() { - System.out.println("Switch language to PL"); localeManager.setLocale(Locale.of("pl")); - } - - //without caused errors @FXML private void makePrintable() { System.out.println("Recipe printed"); @@ -240,6 +272,7 @@ public class FoodpalApplicationCtrl { refresh(); } + } diff --git a/client/src/main/resources/client/scenes/FoodpalApplication.fxml b/client/src/main/resources/client/scenes/FoodpalApplication.fxml index 57ad5f9..45ec08f 100644 --- a/client/src/main/resources/client/scenes/FoodpalApplication.fxml +++ b/client/src/main/resources/client/scenes/FoodpalApplication.fxml @@ -23,57 +23,57 @@ - - - - - - - - - - - - - - - - - -