feat: bold font recipe name + i18n for controllers

This commit is contained in:
Zhongheng Liu 2025-12-04 22:08:39 +01:00
commit 603de94870
Signed by: steven
GPG key ID: F69B980899C1C09D
5 changed files with 64 additions and 23 deletions

View file

@ -28,9 +28,9 @@ import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
public class FoodpalApplicationCtrl implements LocaleAware { public class FoodpalApplicationCtrl implements LocaleAware {
private final MainCtrl mainCtrl;
private final ServerUtils server; private final ServerUtils server;
private final LocaleManager localeManager; private final LocaleManager localeManager;
private final IngredientListCtrl ingredientListCtrl; private final IngredientListCtrl ingredientListCtrl;
@ -80,13 +80,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
@Inject @Inject
public FoodpalApplicationCtrl( public FoodpalApplicationCtrl(
MainCtrl mainCtrl,
ServerUtils server, ServerUtils server,
LocaleManager localeManager, LocaleManager localeManager,
IngredientListCtrl ingredientListCtrl, IngredientListCtrl ingredientListCtrl,
RecipeStepListCtrl stepListCtrl RecipeStepListCtrl stepListCtrl
) { ) {
this.mainCtrl = mainCtrl;
this.server = server; this.server = server;
this.localeManager = localeManager; this.localeManager = localeManager;
this.ingredientListCtrl = ingredientListCtrl; this.ingredientListCtrl = ingredientListCtrl;
@ -149,8 +147,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
refresh(); refresh();
} }
private void showName(String name) { private void showName(String name) {
final int NAME_FONT_SIZE = 20;
editableTitleArea.getChildren().clear(); editableTitleArea.getChildren().clear();
editableTitleArea.getChildren().add(new Label(name)); Label nameLabel = new Label(name);
nameLabel.setFont(new Font("System Bold", NAME_FONT_SIZE));
editableTitleArea.getChildren().add(nameLabel);
} }
@Override @Override
public void updateText() { public void updateText() {

View file

@ -1,17 +1,18 @@
package client.scenes.recipe; package client.scenes.recipe;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import com.google.inject.Inject;
import commons.Recipe; import commons.Recipe;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import java.util.function.Consumer; import java.util.function.Consumer;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.ListView.EditEvent; import javafx.scene.control.ListView.EditEvent;
@ -19,9 +20,15 @@ import javafx.scene.control.ListView.EditEvent;
* Controller for the ingredient list view in the recipe detail scene. * Controller for the ingredient list view in the recipe detail scene.
* Manages displaying, adding, editing, and deleting ingredients. * Manages displaying, adding, editing, and deleting ingredients.
* *
* @see RecipeStepListCell The custom cell implementation. * @see IngredientListCell The custom cell implementation.
*/ */
public class IngredientListCtrl implements Initializable { public class IngredientListCtrl implements LocaleAware {
private final LocaleManager localeManager;
@Inject
public IngredientListCtrl(LocaleManager localeManager) {
this.localeManager = localeManager;
}
/** /**
* <p> * <p>
* The list of ingredients currently displayed. * The list of ingredients currently displayed.
@ -43,6 +50,9 @@ public class IngredientListCtrl implements Initializable {
@FXML @FXML
public ListView<String> ingredientListView; public ListView<String> ingredientListView;
@FXML
public Label ingredientsLabel;
@FXML @FXML
public Button addIngredientButton; public Button addIngredientButton;
@FXML @FXML
@ -129,8 +139,21 @@ public class IngredientListCtrl implements Initializable {
this.updateCallback.accept(this.ingredients); this.updateCallback.accept(this.ingredients);
} }
@FXML @Override
public void initialize(URL location, ResourceBundle resources) { public void updateText() {
System.out.println("updatetext called on ingredientListCtrl");
ingredientsLabel.setText(getLocaleString("menu.label.ingredients"));
addIngredientButton.setText(getLocaleString("menu.button.add.ingredient"));
deleteIngredientButton.setText(getLocaleString("menu.button.remove.ingredient"));
}
@Override
public LocaleManager getLocaleManager() {
return localeManager;
}
@Override
public void initializeComponents() {
// TODO: set up communication with the server // TODO: set up communication with the server
// this would probably be best done with the callback (so this class doesn't // this would probably be best done with the callback (so this class doesn't
// interact with the server at all) // interact with the server at all)

View file

@ -1,17 +1,18 @@
package client.scenes.recipe; package client.scenes.recipe;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import com.google.inject.Inject;
import commons.Recipe; import commons.Recipe;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import java.util.function.Consumer; import java.util.function.Consumer;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.ListView.EditEvent; import javafx.scene.control.ListView.EditEvent;
@ -21,7 +22,16 @@ import javafx.scene.control.ListView.EditEvent;
* *
* @see RecipeStepListCell The custom cell implementation. * @see RecipeStepListCell The custom cell implementation.
*/ */
public class RecipeStepListCtrl implements Initializable { public class RecipeStepListCtrl implements LocaleAware {
private final LocaleManager localeManager;
@FXML
public Label stepsLabel;
@Inject
public RecipeStepListCtrl(LocaleManager localeManager) {
this.localeManager = localeManager;
}
/** /**
* <p> * <p>
* The list of recipe steps currently displayed. * The list of recipe steps currently displayed.
@ -129,18 +139,25 @@ public class RecipeStepListCtrl implements Initializable {
this.updateCallback.accept(this.steps); this.updateCallback.accept(this.steps);
} }
@FXML @Override
public void initialize(URL location, ResourceBundle resources) { public void updateText() {
// TODO: set up communication with the server stepsLabel.setText(getLocaleString("menu.label.preparation"));
// this would probably be best done with the callback (so this class doesn't addStepButton.setText(getLocaleString("menu.button.add.step"));
// interact with the server at all) deleteStepButton.setText(getLocaleString("menu.button.remove.step"));
}
@Override
public LocaleManager getLocaleManager() {
return localeManager;
}
@Override
public void initializeComponents() {
this.recipeStepListView.setEditable(true); this.recipeStepListView.setEditable(true);
this.recipeStepListView.setCellFactory( this.recipeStepListView.setCellFactory(
list -> { list -> {
return new RecipeStepListCell(); return new RecipeStepListCell();
}); });
this.recipeStepListView.setOnEditCommit(this::handleIngredientEdit); this.recipeStepListView.setOnEditCommit(this::handleIngredientEdit);
this.addStepButton.setOnAction(this::handleIngredientAdd); this.addStepButton.setOnAction(this::handleIngredientAdd);
this.deleteStepButton.setOnAction(this::handleIngredientDelete); this.deleteStepButton.setOnAction(this::handleIngredientDelete);

View file

@ -15,7 +15,7 @@
<children> <children>
<HBox alignment="CENTER_LEFT" spacing="20.0"> <HBox alignment="CENTER_LEFT" spacing="20.0">
<children> <children>
<Label text="Ingredients"> <Label fx:id="ingredientsLabel" text="Ingredients">
<padding> <padding>
<Insets bottom="5.0" top="5.0" /> <Insets bottom="5.0" top="5.0" />
</padding> </padding>

View file

@ -15,7 +15,7 @@
<children> <children>
<HBox alignment="CENTER_LEFT" spacing="20.0"> <HBox alignment="CENTER_LEFT" spacing="20.0">
<children> <children>
<Label text="Steps"> <Label fx:id="stepsLabel" text="Steps">
<padding> <padding>
<Insets bottom="5.0" top="5.0" /> <Insets bottom="5.0" top="5.0" />
</padding> </padding>