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;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import client.utils.ServerUtils;
import com.google.inject.Inject;
import commons.Recipe;
import jakarta.ws.rs.WebApplicationException;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.stage.Modality;
import java.io.IOException;
public class AddIngredientCtrl {
public class AddIngredientCtrl implements LocaleAware {
private final ServerUtils server;
private final MainCtrl mainCtrl;
private final FoodpalApplicationCtrl foodpalCtrl;
private final LocaleManager localeManager;
@FXML
public TextField ingredient;
@FXML
public Button okButton;
@FXML
public Button cancelButton;
@FXML
public Label ingredientLabel;
@Inject
public AddIngredientCtrl(ServerUtils server, MainCtrl mainCtrl, FoodpalApplicationCtrl foodpalCtrl) {
public AddIngredientCtrl(ServerUtils server, MainCtrl mainCtrl,
FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) {
this.mainCtrl = mainCtrl;
this.server = server;
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 {
@ -83,4 +111,5 @@ public class AddIngredientCtrl {
break;
}
}
}

View file

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

View file

@ -15,33 +15,60 @@
*/
package client.scenes;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import client.utils.ServerUtils;
import com.google.inject.Inject;
import commons.Recipe;
import jakarta.ws.rs.WebApplicationException;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.stage.Modality;
import java.io.IOException;
public class AddStepsCtrl {
public class AddStepsCtrl implements LocaleAware {
private final ServerUtils server;
private final MainCtrl mainCtrl;
private final FoodpalApplicationCtrl foodpalCtrl;
private final LocaleManager localeManager;
@FXML
public TextField preparationStep;
@FXML
public Button okButton;
@FXML
public Button cancelButton;
@FXML
public Label preparationStepLabel;
@Inject
public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl, FoodpalApplicationCtrl foodpalCtrl) {
public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl,
FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) {
this.mainCtrl = mainCtrl;
this.server = server;
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 {
@ -83,4 +110,5 @@ public class AddStepsCtrl {
break;
}
}
}

View file

@ -18,7 +18,10 @@ public class LocaleManager {
}
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);
}

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">
<children>
<Button 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="okButton" layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
<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" />
<Label layoutX="28.0" layoutY="29.0" text="Ingredient Name" />
<Label fx:id="ingredientLabel" layoutX="28.0" layoutY="29.0" text="Ingredient Name" />
</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">
<children>
<Button 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="okButton" layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
<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" />
<Label layoutX="28.0" layoutY="29.0" text="Preparation step" />
<Label fx:id="preparationStepLabel" layoutX="28.0" layoutY="29.0" text="Preparation step" />
</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.step.title=Add Step
add.ingredient.label=Ingredient
add.recipe.label=Recipe Name
add.recipe.button.ok=Ok
add.recipe.button.cancel=Cancel
add.step.label=Step
button.ok=Ok
button.cancel=Cancel

View file

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

View file

@ -1,4 +1,10 @@
add.ingredient.title=Ingredient toevoegen
add.recipe.title=Recept aanmaken
add.step.title=Stap toevoegen
add.ingredient.label=Ingredient
add.recipe.label=Receptnaam
add.recipe.button.ok=Ok
add.recipe.button.cancel=Annuleren
add.step.label=Bereidingsstap
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.step.title=Dodaj instrukcje
add.ingredient.label=Sk?adnik
add.recipe.label=Nazwa przepisu
add.recipe.button.ok=Ok
add.recipe.button.cancel=Anuluj
add.step.label=Instrukcja
button.ok=Ok
button.cancel=Anuluj