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.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
public class FoodpalApplicationCtrl implements LocaleAware {
private final MainCtrl mainCtrl;
private final ServerUtils server;
private final LocaleManager localeManager;
private final IngredientListCtrl ingredientListCtrl;
@ -80,13 +80,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
@Inject
public FoodpalApplicationCtrl(
MainCtrl mainCtrl,
ServerUtils server,
LocaleManager localeManager,
IngredientListCtrl ingredientListCtrl,
RecipeStepListCtrl stepListCtrl
) {
this.mainCtrl = mainCtrl;
this.server = server;
this.localeManager = localeManager;
this.ingredientListCtrl = ingredientListCtrl;
@ -149,8 +147,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
refresh();
}
private void showName(String name) {
final int NAME_FONT_SIZE = 20;
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
public void updateText() {

View file

@ -1,17 +1,18 @@
package client.scenes.recipe;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import com.google.inject.Inject;
import commons.Recipe;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
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.
* 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>
* The list of ingredients currently displayed.
@ -43,6 +50,9 @@ public class IngredientListCtrl implements Initializable {
@FXML
public ListView<String> ingredientListView;
@FXML
public Label ingredientsLabel;
@FXML
public Button addIngredientButton;
@FXML
@ -129,8 +139,21 @@ public class IngredientListCtrl implements Initializable {
this.updateCallback.accept(this.ingredients);
}
@FXML
public void initialize(URL location, ResourceBundle resources) {
@Override
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
// this would probably be best done with the callback (so this class doesn't
// interact with the server at all)

View file

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

View file

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

View file

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