refactor: integrate remote main changes (locale)
This commit is contained in:
commit
7d2cadc800
19 changed files with 491 additions and 165 deletions
|
|
@ -53,6 +53,6 @@ public class Main extends Application {
|
|||
var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml");
|
||||
|
||||
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
||||
mainCtrl.initialize(primaryStage, addName, foodpal, addIngredient, addStep);
|
||||
mainCtrl.setup(primaryStage, addName, foodpal, addIngredient, addStep);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
package client;
|
||||
|
||||
import client.scenes.FoodpalApplicationCtrl;
|
||||
import client.utils.LocaleManager;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
|
|
@ -30,5 +31,7 @@ public class MyModule implements Module {
|
|||
binder.bind(MainCtrl.class).in(Scopes.SINGLETON);
|
||||
binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON);
|
||||
binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON);
|
||||
|
||||
binder.bind(LocaleManager.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,28 +15,58 @@
|
|||
*/
|
||||
package client.scenes;
|
||||
|
||||
import client.utils.LocaleAware;
|
||||
import client.utils.LocaleManager;
|
||||
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;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.stage.Modality;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AddNameCtrl {
|
||||
public class AddNameCtrl implements LocaleAware {
|
||||
|
||||
private final ServerUtils server;
|
||||
private final MainCtrl mainCtrl;
|
||||
|
||||
private final LocaleManager localeManager;
|
||||
|
||||
@FXML
|
||||
public TextField recipeName;
|
||||
|
||||
@FXML
|
||||
public Label recipeNameLabel;
|
||||
|
||||
@FXML
|
||||
public Button cancelButton;
|
||||
|
||||
@FXML
|
||||
public Button okButton;
|
||||
|
||||
@Inject
|
||||
public AddNameCtrl(ServerUtils server, MainCtrl mainCtrl) {
|
||||
public AddNameCtrl(ServerUtils server, MainCtrl mainCtrl, LocaleManager localeManager) {
|
||||
this.mainCtrl = mainCtrl;
|
||||
this.server = server;
|
||||
this.localeManager = localeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateText() {
|
||||
recipeNameLabel.setText(getLocaleString("add.recipe.label"));
|
||||
okButton.setText(getLocaleString("button.ok"));
|
||||
cancelButton.setText(getLocaleString("button.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleManager getLocaleManager() {
|
||||
return localeManager;
|
||||
}
|
||||
|
||||
public void cancel() throws IOException, InterruptedException {
|
||||
|
|
@ -78,4 +108,5 @@ public class AddNameCtrl {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,14 +2,20 @@ package client.scenes;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import client.exception.UpdateException;
|
||||
import client.utils.DefaultRecipeFactory;
|
||||
import client.utils.LocaleAware;
|
||||
import client.utils.LocaleManager;
|
||||
import client.utils.ServerUtils;
|
||||
|
||||
import commons.Recipe;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
|
|
@ -21,9 +27,10 @@ import javafx.scene.input.KeyCode;
|
|||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public class FoodpalApplicationCtrl {
|
||||
public class FoodpalApplicationCtrl implements LocaleAware {
|
||||
private final MainCtrl mainCtrl;
|
||||
private final ServerUtils server;
|
||||
private final LocaleManager localeManager;
|
||||
|
||||
public VBox detailsScreen;
|
||||
public HBox editableTitleArea;
|
||||
|
|
@ -40,19 +47,10 @@ 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<Recipe> recipeList;
|
||||
|
||||
|
|
@ -62,13 +60,26 @@ public class FoodpalApplicationCtrl {
|
|||
@FXML
|
||||
private Button removeRecipeButton;
|
||||
|
||||
// === CENTER: RECIPE DETAILS ===
|
||||
@FXML
|
||||
private Label recipeNameLabel;
|
||||
public Button cloneRecipeButton;
|
||||
|
||||
// === CENTER: RECIPE DETAILS ===
|
||||
|
||||
@FXML
|
||||
private Button editRecipeTitleButton;
|
||||
|
||||
@FXML
|
||||
public Button removeRecipeButton2;
|
||||
|
||||
@FXML
|
||||
public Button printRecipeButton;
|
||||
|
||||
@FXML
|
||||
public Label ingredientsLabel;
|
||||
|
||||
@FXML
|
||||
public Label preparationLabel;
|
||||
|
||||
@FXML
|
||||
private ListView<String> ingredientsListView;
|
||||
|
||||
|
|
@ -82,13 +93,14 @@ public class FoodpalApplicationCtrl {
|
|||
private Button addPreparationStepButton;
|
||||
|
||||
@Inject
|
||||
public FoodpalApplicationCtrl(MainCtrl mainCtrl, ServerUtils server) {
|
||||
public FoodpalApplicationCtrl(MainCtrl mainCtrl, ServerUtils server, LocaleManager localeManager) {
|
||||
this.mainCtrl = mainCtrl;
|
||||
this.server = server;
|
||||
this.localeManager = localeManager;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void initialize() throws IOException, InterruptedException {
|
||||
@Override
|
||||
public void initializeComponents() {
|
||||
// Show recipe name in the list
|
||||
recipeList.setCellFactory(list -> new ListCell<>() {
|
||||
@Override
|
||||
|
|
@ -117,20 +129,51 @@ public class FoodpalApplicationCtrl {
|
|||
editableTitleArea.getChildren().clear();
|
||||
editableTitleArea.getChildren().add(new Label(name));
|
||||
}
|
||||
// till the all the code from everyone is implemented for now to not have errors
|
||||
private void showRecipeDetails(Recipe newRecipe) {
|
||||
showName(newRecipe.getName());
|
||||
ingredientsListView.getItems().setAll(newRecipe.getIngredients());
|
||||
preparationListView.getItems().setAll(newRecipe.getPreparationSteps());
|
||||
@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;
|
||||
}
|
||||
|
||||
private void showRecipeDetails(Recipe recipe) {
|
||||
if (recipe == null) {
|
||||
ingredientsListView.getItems().clear();
|
||||
preparationListView.getItems().clear();
|
||||
return;
|
||||
}
|
||||
showName(recipe.getName());
|
||||
ingredientsListView.getItems().setAll(recipe.getIngredients());
|
||||
preparationListView.getItems().setAll(recipe.getPreparationSteps());
|
||||
}
|
||||
|
||||
// Button handlers
|
||||
|
||||
@FXML
|
||||
public void refresh() throws IOException, InterruptedException {
|
||||
// TODO: someone else doing this
|
||||
List<Recipe> recipes = server.getRecipes();
|
||||
public void refresh() {
|
||||
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);
|
||||
|
||||
// Select first recipe in the list by default
|
||||
|
|
@ -144,7 +187,6 @@ public class FoodpalApplicationCtrl {
|
|||
alert.setContentText(msg);
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a recipe, by providing a default name "Untitled recipe (n)"
|
||||
* The UX flow is now:
|
||||
|
|
@ -252,22 +294,12 @@ public class FoodpalApplicationCtrl {
|
|||
|
||||
// Language buttons
|
||||
@FXML
|
||||
private void switchToEnglish() {
|
||||
System.out.println("Switch language to EN");
|
||||
private void switchLocale(ActionEvent event) {
|
||||
Button button = (Button)event.getSource();
|
||||
String lang = (String)button.getUserData();
|
||||
localeManager.setLocale(Locale.of(lang));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void switchToDutch() {
|
||||
System.out.println("Switch language to NL");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void switchToPolish() {
|
||||
System.out.println("Switch language to PL");
|
||||
}
|
||||
|
||||
|
||||
//without caused errors
|
||||
@FXML
|
||||
private void makePrintable() {
|
||||
System.out.println("Recipe printed");
|
||||
|
|
@ -294,6 +326,7 @@ public class FoodpalApplicationCtrl {
|
|||
refresh();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@
|
|||
*/
|
||||
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.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
|
@ -22,28 +26,42 @@ import javafx.util.Pair;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainCtrl {
|
||||
public class MainCtrl implements LocaleAware {
|
||||
private final LocaleManager localeManager;
|
||||
|
||||
@FXML
|
||||
private Stage primaryStage;
|
||||
|
||||
@FXML
|
||||
private AddNameCtrl addNameCtrl;
|
||||
private Scene addName;
|
||||
|
||||
@FXML
|
||||
private FoodpalApplicationCtrl foodpalCtrl;
|
||||
private Scene foodpal;
|
||||
|
||||
@FXML
|
||||
private AddIngredientCtrl addIngredientCtrl;
|
||||
private Scene addIngredient;
|
||||
|
||||
@FXML
|
||||
private AddStepsCtrl addStepsCtrl;
|
||||
private Scene addStep;
|
||||
|
||||
public void initialize(Stage primaryStage,
|
||||
Pair<AddNameCtrl, Parent> addName,
|
||||
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
||||
Pair<AddIngredientCtrl, Parent> addIngredient,
|
||||
Pair<AddStepsCtrl, Parent> addStep
|
||||
) throws IOException, InterruptedException {
|
||||
private String addNameTitle = "add.name.title";
|
||||
private String addIngredientTitle = "add.step.title";
|
||||
private String addStepTitle = "add.ingredient.title";
|
||||
|
||||
@Inject
|
||||
public MainCtrl(LocaleManager localeManager) {
|
||||
this.localeManager = localeManager;
|
||||
}
|
||||
|
||||
public void setup(Stage primaryStage,
|
||||
Pair<AddNameCtrl, Parent> addName,
|
||||
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
||||
Pair<AddIngredientCtrl, Parent> addIngredient,
|
||||
Pair<AddStepsCtrl, Parent> addStep) throws IOException, InterruptedException {
|
||||
|
||||
this.primaryStage = primaryStage;
|
||||
|
||||
|
|
@ -59,14 +77,26 @@ public class MainCtrl {
|
|||
this.addStepsCtrl = addStep.getKey();
|
||||
this.addStep = new Scene(addStep.getValue());
|
||||
|
||||
|
||||
showFoodpal();
|
||||
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() {
|
||||
primaryStage.setTitle("Naming recipes");
|
||||
primaryStage.setTitle(addNameTitle);
|
||||
primaryStage.setScene(addName);
|
||||
addName.setOnKeyPressed(e -> {
|
||||
try {
|
||||
|
|
@ -77,14 +107,14 @@ public class MainCtrl {
|
|||
});
|
||||
}
|
||||
|
||||
public void showFoodpal() throws IOException, InterruptedException {
|
||||
public void showFoodpal() {
|
||||
primaryStage.setTitle("FoodPal");
|
||||
primaryStage.setScene(foodpal);
|
||||
foodpalCtrl.refresh();
|
||||
}
|
||||
|
||||
public void showAddIngredient() {
|
||||
primaryStage.setTitle("To add ingredients");
|
||||
primaryStage.setTitle(addIngredientTitle);
|
||||
primaryStage.setScene(addIngredient);
|
||||
addIngredient.setOnKeyPressed(e -> {
|
||||
try {
|
||||
|
|
@ -97,7 +127,7 @@ public class MainCtrl {
|
|||
}
|
||||
|
||||
public void showAddSteps() {
|
||||
primaryStage.setTitle("To add preparation steps");
|
||||
primaryStage.setTitle(addStepTitle);
|
||||
primaryStage.setScene(addStep);
|
||||
addStep.setOnKeyPressed(e -> {
|
||||
try {
|
||||
|
|
|
|||
42
client/src/main/java/client/utils/LocaleAware.java
Normal file
42
client/src/main/java/client/utils/LocaleAware.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package client.utils;
|
||||
|
||||
import javafx.fxml.Initializable;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public interface LocaleAware extends Initializable {
|
||||
|
||||
/**
|
||||
* Updates all text when locale changes.
|
||||
* Must be implemented by each controller.
|
||||
*/
|
||||
void updateText();
|
||||
|
||||
/**
|
||||
* Returns the injected LocaleManager.
|
||||
* Must be implemented by each controller.
|
||||
*/
|
||||
LocaleManager getLocaleManager();
|
||||
|
||||
@Override
|
||||
default void initialize(URL location, ResourceBundle resources) {
|
||||
updateText();
|
||||
|
||||
getLocaleManager().getBundleProperty().addListener((_, _, _) -> updateText());
|
||||
|
||||
initializeComponents();
|
||||
}
|
||||
|
||||
default void initialize() {
|
||||
initialize(null, null);
|
||||
}
|
||||
|
||||
default String getLocaleString(String key) {
|
||||
return getLocaleManager().getBundle().getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional function for initialization of components. Runs after localization.
|
||||
*/
|
||||
default void initializeComponents() {}
|
||||
}
|
||||
47
client/src/main/java/client/utils/LocaleManager.java
Normal file
47
client/src/main/java/client/utils/LocaleManager.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package client.utils;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class LocaleManager {
|
||||
private final ObjectProperty<Locale> currentLocale = new SimpleObjectProperty<>(Locale.ENGLISH);
|
||||
private final ObjectProperty<ResourceBundle> currentBundle = new SimpleObjectProperty<>();
|
||||
|
||||
private static final String RESOURCE_BUNDLE_PATH = "locale/lang";
|
||||
|
||||
public LocaleManager() {
|
||||
// TODO: Set currentLocale to config value instead of EN default.
|
||||
updateBundle();
|
||||
currentLocale.addListener((_, _, _) -> updateBundle());
|
||||
}
|
||||
|
||||
private void updateBundle() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH,
|
||||
currentLocale.get(),
|
||||
ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES)
|
||||
);
|
||||
currentBundle.set(bundle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setLocale(Locale locale) {
|
||||
currentLocale.set(locale);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Locale getLocale() {
|
||||
return currentLocale.get();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ResourceBundle getBundle() {
|
||||
return currentBundle.get();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ObjectProperty<ResourceBundle> getBundleProperty() {
|
||||
return currentBundle;
|
||||
}
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
@ -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.AddNameCtrl">
|
||||
<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="recipeName" layoutX="109.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
|
||||
<Label layoutX="28.0" layoutY="29.0" text="Recipe Name" />
|
||||
<Label fx:id="recipeNameLabel" layoutX="28.0" layoutY="29.0" text="Recipe Name" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</AnchorPane>
|
||||
|
|
@ -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>
|
||||
|
|
@ -23,57 +23,57 @@
|
|||
<padding>
|
||||
<Insets bottom="10" left="10" right="10" top="10" />
|
||||
</padding>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="198.0" minWidth="10.0" prefWidth="130.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="2.0" prefWidth="70.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="54.0" minHeight="10.0" prefHeight="54.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="25.0" minHeight="6.0" prefHeight="6.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
|
||||
<Label prefHeight="56.0" prefWidth="158.0" text="FoodPal">
|
||||
<font>
|
||||
<Font name="System Bold" size="29.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.rowIndex="2">
|
||||
<buttons>
|
||||
<ToolBar prefHeight="35.0" prefWidth="123.0">
|
||||
<items>
|
||||
<Button fx:id="flagEnButton" minWidth="33.0" onAction="#switchToEnglish" prefHeight="25.0" prefWidth="33.0" text="EN" />
|
||||
<Button fx:id="flagNlButton" onAction="#switchToDutch" text="NL" />
|
||||
<Button fx:id="flagPlButton" onAction="#switchToPolish" text="PL" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</children>
|
||||
</GridPane>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="198.0" minWidth="10.0" prefWidth="130.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="2.0" prefWidth="70.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="54.0" minHeight="10.0" prefHeight="54.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="25.0" minHeight="6.0" prefHeight="6.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
|
||||
<Pane HBox.hgrow="ALWAYS" />
|
||||
<Label prefHeight="56.0" prefWidth="158.0" text="FoodPal">
|
||||
<font>
|
||||
<Font name="System Bold" size="29.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.rowIndex="2">
|
||||
<buttons>
|
||||
<ToolBar prefHeight="35.0" prefWidth="123.0">
|
||||
<items>
|
||||
<Button fx:id="flagEnButton" minWidth="33.0" onAction="#switchLocale" userData="en" prefHeight="25.0" prefWidth="33.0" text="EN" />
|
||||
<Button fx:id="flagNlButton" onAction="#switchLocale" userData="nl" text="NL" />
|
||||
<Button fx:id="flagPlButton" onAction="#switchLocale" userData="pl" text="PL" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</children>
|
||||
</GridPane>
|
||||
|
||||
<HBox spacing="5" />
|
||||
<GridPane prefHeight="90.0" prefWidth="114.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="32.1666259765625" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="24.8333740234375" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="173.0" minWidth="10.0" prefWidth="28.6666259765625" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="34.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Pane HBox.hgrow="ALWAYS" />
|
||||
|
||||
<Button fx:id="refreshButton" onAction="#refresh" prefHeight="25.0" prefWidth="34.0" text="⟳" GridPane.columnIndex="3" GridPane.rowIndex="2" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<HBox spacing="5" />
|
||||
<GridPane prefHeight="90.0" prefWidth="114.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="32.1666259765625" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="315.0" minWidth="10.0" prefWidth="24.8333740234375" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="173.0" minWidth="10.0" prefWidth="28.6666259765625" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="34.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
|
||||
<Button fx:id="refreshButton" onAction="#refresh" prefHeight="25.0" prefWidth="34.0" text="⟳" GridPane.columnIndex="3" GridPane.rowIndex="2" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</HBox>
|
||||
</top>
|
||||
|
||||
|
|
@ -84,17 +84,17 @@
|
|||
<Insets bottom="10" left="10" right="10" top="10" />
|
||||
</padding>
|
||||
|
||||
<Label text="Recipes">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font></Label>
|
||||
<Label fx:id="recipesLabel" text="Recipes">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font></Label>
|
||||
|
||||
<ListView fx:id="recipeList" />
|
||||
|
||||
<HBox spacing="10">
|
||||
<Button fx:id="AddRecipeButton" onAction="#addRecipe" text="Add Recipe" />
|
||||
<Button fx:id="RemoveRecipeButton" onAction="#removeSelectedRecipe" text="Remove Recipe" />
|
||||
<Button fx:id= "CloneREcipeButton" mnemonicParsing="false" onAction="#cloneRecipe" text="Clone" />
|
||||
<Button fx:id="addRecipeButton" onAction="#addRecipe" text="Add Recipe" />
|
||||
<Button fx:id="removeRecipeButton" onAction="#removeSelectedRecipe" text="Remove Recipe" />
|
||||
<Button fx:id= "cloneRecipeButton" mnemonicParsing="false" onAction="#cloneRecipe" text="Clone" />
|
||||
</HBox>
|
||||
</VBox>
|
||||
</left>
|
||||
|
|
@ -110,15 +110,14 @@
|
|||
<HBox spacing="10">
|
||||
<HBox fx:id="editableTitleArea">
|
||||
</HBox>
|
||||
|
||||
<Button fx:id="editRecipeTitleButton" onAction="#editRecipeTitle" text="Edit" />
|
||||
<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="removeRecipeButton2" mnemonicParsing="false" onAction="#removeSelectedRecipe" text="Remove Recipe" />
|
||||
<Button fx:id="printRecipeButton" mnemonicParsing="false" onAction="#makePrintable" text="Print Recipe" />
|
||||
</HBox>
|
||||
|
||||
<!-- Ingredients -->
|
||||
<VBox spacing="10">
|
||||
<Label text="Ingredients">
|
||||
<Label fx:id="ingredientsLabel" text="Ingredients">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
|
|
@ -128,7 +127,7 @@
|
|||
</VBox>
|
||||
|
||||
<!-- Preparation -->
|
||||
<Label text="Preparation">
|
||||
<Label fx:id="preparationLabel" text="Preparation">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
|
|
@ -136,16 +135,16 @@
|
|||
<ListView fx:id="preparationListView" prefHeight="200.0" />
|
||||
<Button fx:id="addPreparationStepButton" onAction="#addPreparationStep" text="Add Step" />
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="890.6666870117188" minWidth="10.0" prefWidth="854.6666870117188" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="445.3333740234375" minWidth="10.0" prefWidth="57.33331298828125" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="890.6666870117188" minWidth="10.0" prefWidth="854.6666870117188" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="445.3333740234375" minWidth="10.0" prefWidth="57.33331298828125" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
</VBox>
|
||||
</center>
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
26
client/src/main/resources/locale/lang.properties
Normal file
26
client/src/main/resources/locale/lang.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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.step.label=Step
|
||||
|
||||
button.ok=Ok
|
||||
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
|
||||
26
client/src/main/resources/locale/lang_en.properties
Normal file
26
client/src/main/resources/locale/lang_en.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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.step.label=Step
|
||||
|
||||
button.ok=Ok
|
||||
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
|
||||
26
client/src/main/resources/locale/lang_nl.properties
Normal file
26
client/src/main/resources/locale/lang_nl.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
add.ingredient.title=Ingredient toevoegen
|
||||
add.recipe.title=Recept aanmaken
|
||||
add.step.title=Stap toevoegen
|
||||
|
||||
add.ingredient.label=Ingredient
|
||||
add.recipe.label=Receptnaam
|
||||
add.step.label=Bereidingsstap
|
||||
|
||||
button.ok=Ok
|
||||
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
|
||||
26
client/src/main/resources/locale/lang_pl.properties
Normal file
26
client/src/main/resources/locale/lang_pl.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
add.ingredient.title=Dodaj składnik
|
||||
add.recipe.title=Utwórz przepis
|
||||
add.step.title=Dodaj instrukcję
|
||||
|
||||
add.ingredient.label=Składnik
|
||||
add.recipe.label=Nazwa przepisu
|
||||
add.step.label=Instrukcja
|
||||
|
||||
button.ok=Ok
|
||||
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
|
||||
|
|
@ -15,16 +15,16 @@
|
|||
*/
|
||||
package client.scenes;
|
||||
|
||||
import client.utils.LocaleManager;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MainCtrlTest {
|
||||
|
||||
private MainCtrl sut;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
sut = new MainCtrl();
|
||||
sut = new MainCtrl(new LocaleManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue