Everything except window titles works with resource bundles

This commit is contained in:
Oskar Rasieński 2025-12-04 01:15:27 +01:00
commit 91c8469282
6 changed files with 197 additions and 100 deletions

View file

@ -2,9 +2,11 @@ package client.scenes;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import client.utils.LocaleAware;
import client.utils.LocaleManager; import client.utils.LocaleManager;
import client.utils.ServerUtils; import client.utils.ServerUtils;
import commons.Recipe; import commons.Recipe;
@ -16,13 +18,11 @@ import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
public class FoodpalApplicationCtrl { public class FoodpalApplicationCtrl implements LocaleAware {
private final MainCtrl mainCtrl; private final MainCtrl mainCtrl;
private final ServerUtils server; private final ServerUtils server;
private final LocaleManager localeManager; private final LocaleManager localeManager;
// all of these aren't used with only my part of the code
// everything in the top bar === // everything in the top bar ===
@FXML @FXML
private Button flagEnButton; //already here for advanced stuff private Button flagEnButton; //already here for advanced stuff
@ -33,19 +33,13 @@ public class FoodpalApplicationCtrl {
@FXML @FXML
private Button flagPlButton; //already here for advanced stuff private Button flagPlButton; //already here for advanced stuff
@FXML
private Button refreshButton;
@FXML @FXML
private Button closeButton; //already here for advanced stuff 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 // everything in the left lane
@FXML
public Label recipesLabel;
@FXML @FXML
private ListView<Recipe> recipeList; private ListView<Recipe> recipeList;
@ -55,6 +49,9 @@ public class FoodpalApplicationCtrl {
@FXML @FXML
private Button removeRecipeButton; private Button removeRecipeButton;
@FXML
public Button cloneRecipeButton;
// === CENTER: RECIPE DETAILS === // === CENTER: RECIPE DETAILS ===
@FXML @FXML
private Label recipeNameLabel; private Label recipeNameLabel;
@ -62,6 +59,18 @@ public class FoodpalApplicationCtrl {
@FXML @FXML
private Button editRecipeTitleButton; private Button editRecipeTitleButton;
@FXML
public Button removeRecipeButton2;
@FXML
public Button printRecipeButton;
@FXML
public Label ingredientsLabel;
@FXML
public Label preparationLabel;
@FXML @FXML
private ListView<String> ingredientsListView; private ListView<String> ingredientsListView;
@ -81,8 +90,7 @@ public class FoodpalApplicationCtrl {
this.localeManager = localeManager; this.localeManager = localeManager;
} }
@FXML public void initializeComponents() {
private void initialize() throws IOException, InterruptedException {
// Show recipe name in the list // Show recipe name in the list
recipeList.setCellFactory(list -> new ListCell<>() { recipeList.setCellFactory(list -> new ListCell<>() {
@Override @Override
@ -108,20 +116,50 @@ public class FoodpalApplicationCtrl {
refresh(); 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 // till the all the code from everyone is implemented for now to not have errors
private void showRecipeDetails(Recipe newRecipe) { private void showRecipeDetails(Recipe newRecipe) {
recipeNameLabel.setText(newRecipe.getName()); recipeNameLabel.setText(newRecipe.getName());
ingredientsListView.getItems().setAll(newRecipe.getIngredients()); ingredientsListView.getItems().setAll(newRecipe.getIngredients());
preparationListView.getItems().setAll(newRecipe.getPreparationSteps()); preparationListView.getItems().setAll(newRecipe.getPreparationSteps());
} }
// Button handlers // Button handlers
@FXML @FXML
public void refresh() throws IOException, InterruptedException { public void refresh() {
// TODO: someone else doing this // TODO: someone else doing this
List<Recipe> recipes = server.getRecipes();
List<Recipe> 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); recipeList.getItems().setAll(recipes);
// Select first recipe in the list by default // Select first recipe in the list by default
@ -195,25 +233,19 @@ public class FoodpalApplicationCtrl {
// Language buttons // Language buttons
@FXML @FXML
private void switchToEnglish() { private void switchToEnglish() {
System.out.println("Switch language to EN");
localeManager.setLocale(Locale.of("en")); localeManager.setLocale(Locale.of("en"));
} }
@FXML @FXML
private void switchToDutch() { private void switchToDutch() {
System.out.println("Switch language to NL");
localeManager.setLocale(Locale.of("nl")); localeManager.setLocale(Locale.of("nl"));
} }
@FXML @FXML
private void switchToPolish() { private void switchToPolish() {
System.out.println("Switch language to PL");
localeManager.setLocale(Locale.of("pl")); localeManager.setLocale(Locale.of("pl"));
} }
//without caused errors
@FXML @FXML
private void makePrintable() { private void makePrintable() {
System.out.println("Recipe printed"); System.out.println("Recipe printed");
@ -240,6 +272,7 @@ public class FoodpalApplicationCtrl {
refresh(); refresh();
} }
} }

View file

@ -84,7 +84,7 @@
<Insets bottom="10" left="10" right="10" top="10" /> <Insets bottom="10" left="10" right="10" top="10" />
</padding> </padding>
<Label text="Recipes"> <Label fx:id="recipesLabel" text="Recipes">
<font> <font>
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
</font></Label> </font></Label>
@ -92,9 +92,9 @@
<ListView fx:id="recipeList" /> <ListView fx:id="recipeList" />
<HBox spacing="10"> <HBox spacing="10">
<Button fx:id="AddRecipeButton" onAction="#addRecipe" text="Add Recipe" /> <Button fx:id="addRecipeButton" onAction="#addRecipe" text="Add Recipe" />
<Button fx:id="RemoveRecipeButton" onAction="#removeSelectedRecipe" text="Remove Recipe" /> <Button fx:id="removeRecipeButton" onAction="#removeSelectedRecipe" text="Remove Recipe" />
<Button fx:id= "CloneREcipeButton" mnemonicParsing="false" onAction="#cloneRecipe" text="Clone" /> <Button fx:id= "cloneRecipeButton" mnemonicParsing="false" onAction="#cloneRecipe" text="Clone" />
</HBox> </HBox>
</VBox> </VBox>
</left> </left>
@ -113,13 +113,13 @@
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font></Label> </font></Label>
<Button fx:id="editRecipeTitleButton" onAction="#editRecipeTitle" text="Edit" /> <Button fx:id="editRecipeTitleButton" onAction="#editRecipeTitle" text="Edit" />
<Button fx:id="RemoveRecipeButton2" mnemonicParsing="false" onAction="#removeSelectedRecipe" text="Remove Recipe" /> <Button fx:id="removeRecipeButton2" mnemonicParsing="false" onAction="#removeSelectedRecipe" text="Remove Recipe" />
<Button fx:id="printRecipe" mnemonicParsing="false" onAction="#makePrintable" text="Print Recipe" /> <Button fx:id="printRecipeButton" mnemonicParsing="false" onAction="#makePrintable" text="Print Recipe" />
</HBox> </HBox>
<!-- Ingredients --> <!-- Ingredients -->
<VBox spacing="10"> <VBox spacing="10">
<Label text="Ingredients"> <Label fx:id="ingredientsLabel" text="Ingredients">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
@ -129,7 +129,7 @@
</VBox> </VBox>
<!-- Preparation --> <!-- Preparation -->
<Label text="Preparation"> <Label fx:id="preparationLabel" text="Preparation">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>

View file

@ -8,3 +8,19 @@ add.step.label=Step
button.ok=Ok button.ok=Ok
button.cancel=Cancel button.cancel=Cancel
menu.label.recipes=Recipes
menu.label.ingredients=Ingredients
menu.label.preparation=Preparation
menu.button.add.recipe=Add Recipe
menu.button.add.ingredient=Add Ingredient
menu.button.add.step=Add Step
menu.button.remove.recipe=Remove Recipe
menu.button.remove.ingredient=Remove Ingredient
menu.button.remove.step=Remove Step
menu.button.edit=Edit
menu.button.clone=Clone
menu.button.print=Print recipe

View file

@ -4,7 +4,23 @@ add.step.title=Add Step
add.ingredient.label=Ingredient add.ingredient.label=Ingredient
add.recipe.label=Recipe Name add.recipe.label=Recipe Name
add.step.label=Preparation Step add.step.label=Step
button.ok=Ok button.ok=Ok
button.cancel=Cancel button.cancel=Cancel
menu.label.recipes=Recipes
menu.label.ingredients=Ingredients
menu.label.preparation=Preparation
menu.button.add.recipe=Add Recipe
menu.button.add.ingredient=Add Ingredient
menu.button.add.step=Add Step
menu.button.remove.recipe=Remove Recipe
menu.button.remove.ingredient=Remove Ingredient
menu.button.remove.step=Remove Step
menu.button.edit=Edit
menu.button.clone=Clone
menu.button.print=Print recipe

View file

@ -8,3 +8,19 @@ add.step.label=Bereidingsstap
button.ok=Ok button.ok=Ok
button.cancel=Annuleren button.cancel=Annuleren
menu.label.recipes=Recepten
menu.label.ingredients=Ingrediënten
menu.label.preparation=Bereiding
menu.button.add.recipe=Recept toevoegen
menu.button.add.ingredient=Ingrediënt toevoegen
menu.button.add.step=Stap toevoegen
menu.button.remove.recipe=Recept verwijderen
menu.button.remove.ingredient=Ingrediënt verwijderen
menu.button.remove.step=Stap verwijderen
menu.button.edit=Bewerken
menu.button.clone=Dupliceren
menu.button.print=Recept afdrukken

View file

@ -1,10 +1,26 @@
add.ingredient.title=Dodaj sk?adnik add.ingredient.title=Dodaj składnik
add.recipe.title=Utwórz przepis add.recipe.title=Utwórz przepis
add.step.title=Dodaj instrukcje add.step.title=Dodaj instrukcje
add.ingredient.label=Sk?adnik add.ingredient.label=Składnik
add.recipe.label=Nazwa przepisu add.recipe.label=Nazwa przepisu
add.step.label=Instrukcja add.step.label=Instrukcja
button.ok=Ok button.ok=Ok
button.cancel=Anuluj button.cancel=Anuluj
menu.label.recipes=Przepisy
menu.label.ingredients=Składniki
menu.label.preparation=Przygotowanie
menu.button.add.recipe=Dodaj przepis
menu.button.add.ingredient=Dodaj składnik
menu.button.add.step=Dodaj instrukcję
menu.button.remove.recipe=Usuń przepis
menu.button.remove.ingredient=Usuń składnik
menu.button.remove.step=Usuń instrukcję
menu.button.edit=Edytuj
menu.button.clone=Duplikuj
menu.button.print=Drukuj przepis