All locale should work now
This commit is contained in:
parent
91c8469282
commit
ebd896cbee
6 changed files with 53 additions and 14 deletions
|
|
@ -53,6 +53,6 @@ public class Main extends Application {
|
||||||
var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml");
|
var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml");
|
||||||
|
|
||||||
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
||||||
mainCtrl.initialize(primaryStage, addName, foodpal, addIngredient, addStep);
|
mainCtrl.setup(primaryStage, addName, foodpal, addIngredient, addStep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package client.scenes;
|
package client.scenes;
|
||||||
|
|
||||||
|
import client.utils.LocaleAware;
|
||||||
|
import client.utils.LocaleManager;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
@ -22,28 +26,42 @@ import javafx.util.Pair;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainCtrl {
|
public class MainCtrl implements LocaleAware {
|
||||||
|
private final LocaleManager localeManager;
|
||||||
|
|
||||||
|
@FXML
|
||||||
private Stage primaryStage;
|
private Stage primaryStage;
|
||||||
|
|
||||||
|
@FXML
|
||||||
private AddNameCtrl addNameCtrl;
|
private AddNameCtrl addNameCtrl;
|
||||||
private Scene addName;
|
private Scene addName;
|
||||||
|
|
||||||
|
@FXML
|
||||||
private FoodpalApplicationCtrl foodpalCtrl;
|
private FoodpalApplicationCtrl foodpalCtrl;
|
||||||
private Scene foodpal;
|
private Scene foodpal;
|
||||||
|
|
||||||
|
@FXML
|
||||||
private AddIngredientCtrl addIngredientCtrl;
|
private AddIngredientCtrl addIngredientCtrl;
|
||||||
private Scene addIngredient;
|
private Scene addIngredient;
|
||||||
|
|
||||||
|
@FXML
|
||||||
private AddStepsCtrl addStepsCtrl;
|
private AddStepsCtrl addStepsCtrl;
|
||||||
private Scene addStep;
|
private Scene addStep;
|
||||||
|
|
||||||
public void initialize(Stage primaryStage,
|
private String addNameTitle = "Naming recipes (default)";
|
||||||
|
private String addIngredientTitle = "To add ingredients (default)";
|
||||||
|
private String addStepTitle = "To add preparation steps (default)";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public MainCtrl(LocaleManager localeManager) {
|
||||||
|
this.localeManager = localeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setup(Stage primaryStage,
|
||||||
Pair<AddNameCtrl, Parent> addName,
|
Pair<AddNameCtrl, Parent> addName,
|
||||||
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
||||||
Pair<AddIngredientCtrl, Parent> addIngredient,
|
Pair<AddIngredientCtrl, Parent> addIngredient,
|
||||||
Pair<AddStepsCtrl, Parent> addStep
|
Pair<AddStepsCtrl, Parent> addStep) throws IOException, InterruptedException {
|
||||||
) throws IOException, InterruptedException {
|
|
||||||
|
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
|
|
||||||
|
|
@ -59,14 +77,26 @@ public class MainCtrl {
|
||||||
this.addStepsCtrl = addStep.getKey();
|
this.addStepsCtrl = addStep.getKey();
|
||||||
this.addStep = new Scene(addStep.getValue());
|
this.addStep = new Scene(addStep.getValue());
|
||||||
|
|
||||||
|
|
||||||
showFoodpal();
|
showFoodpal();
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
|
initialize(); // Initialize LocaleManager stuff manually since MainCtrl isn't loaded from FXML.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateText() {
|
||||||
|
addNameTitle = getLocaleString("add.recipe.title");
|
||||||
|
addStepTitle = getLocaleString("add.step.title");
|
||||||
|
addIngredientTitle = getLocaleString("add.ingredient.title");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocaleManager getLocaleManager() {
|
||||||
|
return localeManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void showAddName() {
|
public void showAddName() {
|
||||||
primaryStage.setTitle("Naming recipes");
|
primaryStage.setTitle(addNameTitle);
|
||||||
primaryStage.setScene(addName);
|
primaryStage.setScene(addName);
|
||||||
addName.setOnKeyPressed(e -> {
|
addName.setOnKeyPressed(e -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -84,7 +114,7 @@ public class MainCtrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAddIngredient() {
|
public void showAddIngredient() {
|
||||||
primaryStage.setTitle("To add ingredients");
|
primaryStage.setTitle(addIngredientTitle);
|
||||||
primaryStage.setScene(addIngredient);
|
primaryStage.setScene(addIngredient);
|
||||||
addIngredient.setOnKeyPressed(e -> {
|
addIngredient.setOnKeyPressed(e -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -97,7 +127,7 @@ public class MainCtrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAddSteps() {
|
public void showAddSteps() {
|
||||||
primaryStage.setTitle("To add preparation steps");
|
primaryStage.setTitle(addStepTitle);
|
||||||
primaryStage.setScene(addStep);
|
primaryStage.setScene(addStep);
|
||||||
addStep.setOnKeyPressed(e -> {
|
addStep.setOnKeyPressed(e -> {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ public interface LocaleAware extends Initializable {
|
||||||
initializeComponents();
|
initializeComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void initialize() {
|
||||||
|
initialize(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
default String getLocaleString(String key) {
|
default String getLocaleString(String key) {
|
||||||
return getLocaleManager().getBundle().getString(key);
|
return getLocaleManager().getBundle().getString(key);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,22 @@ public class LocaleManager {
|
||||||
currentBundle.set(bundle);
|
currentBundle.set(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void setLocale(Locale locale) {
|
public void setLocale(Locale locale) {
|
||||||
currentLocale.set(locale);
|
currentLocale.set(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return currentLocale.get();
|
return currentLocale.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public ResourceBundle getBundle() {
|
public ResourceBundle getBundle() {
|
||||||
return currentBundle.get();
|
return currentBundle.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public ObjectProperty<ResourceBundle> getBundleProperty() {
|
public ObjectProperty<ResourceBundle> getBundleProperty() {
|
||||||
return currentBundle;
|
return currentBundle;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
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 instrukcję
|
||||||
|
|
||||||
add.ingredient.label=Składnik
|
add.ingredient.label=Składnik
|
||||||
add.recipe.label=Nazwa przepisu
|
add.recipe.label=Nazwa przepisu
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package client.scenes;
|
package client.scenes;
|
||||||
|
|
||||||
|
import client.utils.LocaleManager;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ public class MainCtrlTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
sut = new MainCtrl();
|
sut = new MainCtrl(new LocaleManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue