AddName, AddIngredient and AddStep all work with localization

This commit is contained in:
Oskar Rasieński 2025-12-04 00:26:33 +01:00
commit c53239d71e
11 changed files with 115 additions and 43 deletions

View file

@ -15,33 +15,61 @@
*/ */
package client.scenes; package client.scenes;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import client.utils.ServerUtils; import client.utils.ServerUtils;
import com.google.inject.Inject; import com.google.inject.Inject;
import commons.Recipe; import commons.Recipe;
import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.WebApplicationException;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.stage.Modality; import javafx.stage.Modality;
import java.io.IOException; import java.io.IOException;
public class AddIngredientCtrl { public class AddIngredientCtrl implements LocaleAware {
private final ServerUtils server; private final ServerUtils server;
private final MainCtrl mainCtrl; private final MainCtrl mainCtrl;
private final FoodpalApplicationCtrl foodpalCtrl; private final FoodpalApplicationCtrl foodpalCtrl;
private final LocaleManager localeManager;
@FXML @FXML
public TextField ingredient; public TextField ingredient;
@FXML
public Button okButton;
@FXML
public Button cancelButton;
@FXML
public Label ingredientLabel;
@Inject @Inject
public AddIngredientCtrl(ServerUtils server, MainCtrl mainCtrl, FoodpalApplicationCtrl foodpalCtrl) { public AddIngredientCtrl(ServerUtils server, MainCtrl mainCtrl,
FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) {
this.mainCtrl = mainCtrl; this.mainCtrl = mainCtrl;
this.server = server; this.server = server;
this.foodpalCtrl = foodpalCtrl; this.foodpalCtrl = foodpalCtrl;
this.localeManager = localeManager;
}
@Override
public void updateText() {
ingredientLabel.setText(getLocaleString("add.ingredient.label"));
okButton.setText(getLocaleString("button.ok"));
cancelButton.setText(getLocaleString("button.cancel"));
}
@Override
public LocaleManager getLocaleManager() {
return localeManager;
} }
public void cancel() throws IOException, InterruptedException { public void cancel() throws IOException, InterruptedException {
@ -83,4 +111,5 @@ public class AddIngredientCtrl {
break; break;
} }
} }
} }

View file

@ -21,6 +21,7 @@ import client.utils.ServerUtils;
import com.google.inject.Inject; import com.google.inject.Inject;
import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.WebApplicationException;
import javafx.fxml.FXML;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -37,9 +38,16 @@ public class AddNameCtrl implements LocaleAware {
private final LocaleManager localeManager; private final LocaleManager localeManager;
@FXML
public TextField recipeName; public TextField recipeName;
@FXML
public Label recipeNameLabel; public Label recipeNameLabel;
@FXML
public Button cancelButton; public Button cancelButton;
@FXML
public Button okButton; public Button okButton;
@Inject @Inject
@ -52,8 +60,8 @@ public class AddNameCtrl implements LocaleAware {
@Override @Override
public void updateText() { public void updateText() {
recipeNameLabel.setText(getLocaleString("add.recipe.label")); recipeNameLabel.setText(getLocaleString("add.recipe.label"));
okButton.setText(getLocaleString("add.recipe.button.ok")); okButton.setText(getLocaleString("button.ok"));
cancelButton.setText(getLocaleString("add.recipe.button.cancel")); cancelButton.setText(getLocaleString("button.cancel"));
} }
@Override @Override

View file

@ -15,33 +15,60 @@
*/ */
package client.scenes; package client.scenes;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import client.utils.ServerUtils; import client.utils.ServerUtils;
import com.google.inject.Inject; import com.google.inject.Inject;
import commons.Recipe; import commons.Recipe;
import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.WebApplicationException;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.stage.Modality; import javafx.stage.Modality;
import java.io.IOException; import java.io.IOException;
public class AddStepsCtrl { public class AddStepsCtrl implements LocaleAware {
private final ServerUtils server; private final ServerUtils server;
private final MainCtrl mainCtrl; private final MainCtrl mainCtrl;
private final FoodpalApplicationCtrl foodpalCtrl; private final FoodpalApplicationCtrl foodpalCtrl;
private final LocaleManager localeManager;
@FXML @FXML
public TextField preparationStep; public TextField preparationStep;
@FXML
public Button okButton;
@FXML
public Button cancelButton;
@FXML
public Label preparationStepLabel;
@Inject @Inject
public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl, FoodpalApplicationCtrl foodpalCtrl) { public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl,
FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) {
this.mainCtrl = mainCtrl; this.mainCtrl = mainCtrl;
this.server = server; this.server = server;
this.foodpalCtrl = foodpalCtrl; this.foodpalCtrl = foodpalCtrl;
this.localeManager = localeManager;
}
@Override
public void updateText() {
preparationStepLabel.setText(getLocaleString("add.step.label"));
okButton.setText(getLocaleString("button.ok"));
cancelButton.setText(getLocaleString("button.cancel"));
}
@Override
public LocaleManager getLocaleManager() {
return localeManager;
} }
public void cancel() throws IOException, InterruptedException { public void cancel() throws IOException, InterruptedException {
@ -83,4 +110,5 @@ public class AddStepsCtrl {
break; break;
} }
} }
} }

View file

@ -18,7 +18,10 @@ public class LocaleManager {
} }
private void updateBundle() { private void updateBundle() {
ResourceBundle bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH, currentLocale.get()); ResourceBundle bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH,
currentLocale.get(),
ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES)
);
currentBundle.set(bundle); currentBundle.set(bundle);
} }

View file

@ -7,9 +7,9 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="94.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.AddIngredientCtrl"> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="94.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.AddIngredientCtrl">
<children> <children>
<Button layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" /> <Button fx:id="okButton" layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
<Button layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" /> <Button fx:id="cancelButton" layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
<TextField fx:id="ingredient" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" /> <TextField fx:id="ingredient" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
<Label layoutX="28.0" layoutY="29.0" text="Ingredient Name" /> <Label fx:id="ingredientLabel" layoutX="28.0" layoutY="29.0" text="Ingredient Name" />
</children> </children>
</AnchorPane> </AnchorPane>

View file

@ -7,9 +7,9 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="94.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.AddStepsCtrl"> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="94.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.AddStepsCtrl">
<children> <children>
<Button layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" /> <Button fx:id="okButton" layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
<Button layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" /> <Button fx:id="cancelButton" layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
<TextField fx:id="preparationStep" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" /> <TextField fx:id="preparationStep" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
<Label layoutX="28.0" layoutY="29.0" text="Preparation step" /> <Label fx:id="preparationStepLabel" layoutX="28.0" layoutY="29.0" text="Preparation step" />
</children> </children>
</AnchorPane> </AnchorPane>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.QuoteOverviewCtrl">
<children>
<Button layoutX="503.0" layoutY="360.0" mnemonicParsing="false" onAction="#addQuote" text="Add Quote" />
<Button layoutX="431.0" layoutY="360.0" mnemonicParsing="false" onAction="#refresh" text="Refresh" />
<TableView fx:id="table" layoutX="14.0" layoutY="14.0" prefHeight="337.0" prefWidth="572.0">
<columns>
<TableColumn fx:id="colFirstName" prefWidth="113.0" text="First Name" />
<TableColumn fx:id="colLastName" prefWidth="114.0" text="Last Name" />
<TableColumn fx:id="colQuote" prefWidth="344.0" text="Quote" />
</columns>
</TableView>
</children>
</AnchorPane>

View file

@ -1,4 +1,10 @@
add.ingredient.title=Add Ingredient
add.recipe.title=Create recipe add.recipe.title=Create recipe
add.step.title=Add Step
add.ingredient.label=Ingredient
add.recipe.label=Recipe Name add.recipe.label=Recipe Name
add.recipe.button.ok=Ok add.step.label=Step
add.recipe.button.cancel=Cancel
button.ok=Ok
button.cancel=Cancel

View file

@ -1,4 +1,10 @@
add.ingredient.title=Add Ingredient
add.recipe.title=Create recipe add.recipe.title=Create recipe
add.step.title=Add Step
add.ingredient.label=Ingredient
add.recipe.label=Recipe Name add.recipe.label=Recipe Name
add.recipe.button.ok=Ok add.step.label=Preparation Step
add.recipe.button.cancel=Cancel
button.ok=Ok
button.cancel=Cancel

View file

@ -1,4 +1,10 @@
add.ingredient.title=Ingredient toevoegen
add.recipe.title=Recept aanmaken add.recipe.title=Recept aanmaken
add.step.title=Stap toevoegen
add.ingredient.label=Ingredient
add.recipe.label=Receptnaam add.recipe.label=Receptnaam
add.recipe.button.ok=Ok add.step.label=Bereidingsstap
add.recipe.button.cancel=Annuleren
button.ok=Ok
button.cancel=Annuleren

View file

@ -1,4 +1,10 @@
add.ingredient.title=Dodaj sk?adnik
add.recipe.title=Utwórz przepis add.recipe.title=Utwórz przepis
add.step.title=Dodaj instrukcje
add.ingredient.label=Sk?adnik
add.recipe.label=Nazwa przepisu add.recipe.label=Nazwa przepisu
add.recipe.button.ok=Ok add.step.label=Instrukcja
add.recipe.button.cancel=Anuluj
button.ok=Ok
button.cancel=Anuluj