diff --git a/client/src/main/java/client/scenes/recipe/RecipeDetailCtrl.java b/client/src/main/java/client/scenes/recipe/RecipeDetailCtrl.java index cdf5724..0bcd1e9 100644 --- a/client/src/main/java/client/scenes/recipe/RecipeDetailCtrl.java +++ b/client/src/main/java/client/scenes/recipe/RecipeDetailCtrl.java @@ -49,6 +49,8 @@ public class RecipeDetailCtrl implements LocaleAware { public Spinner scaleSpinner; public Label inferredKcalLabel; + public Spinner servingsSpinner; + public Label inferredServeSizeLabel; @FXML private IngredientListCtrl ingredientListController; @@ -157,7 +159,7 @@ public class RecipeDetailCtrl implements LocaleAware { // If there is a scale // Prevents issues from first startup - if (scaleSpinner.getValue() != null) { + if (scaleSpinner.getValue() != null && servingsSpinner.getValue() != null) { Double scale = scaleSpinner.getValue(); // see impl. creates a scaled context for the recipe such that its non-scaled value is kept as a reference. this.recipeView = new ScalableRecipeView(recipe, scale); @@ -167,6 +169,10 @@ public class RecipeDetailCtrl implements LocaleAware { Double.isNaN(this.recipeView.scaledKcalProperty().get()) ? 0.0 : this.recipeView.scaledKcalProperty().get()) , this.recipeView.scaledKcalProperty())); + recipeView.servingsProperty().set(servingsSpinner.getValue()); + inferredServeSizeLabel.textProperty().bind(Bindings.createStringBinding( + () -> String.format("Inferred size per serving: %.1f g", recipeView.servingSizeProperty().get()), + recipeView.servingSizeProperty())); // expose the scaled view to list controllers this.ingredientListController.refetchFromRecipe(this.recipeView.getScaled()); this.stepListController.refetchFromRecipe(this.recipeView.getScaled()); @@ -402,6 +408,14 @@ public class RecipeDetailCtrl implements LocaleAware { // triggers a UI update each time the spinner changes to a different value. setCurrentlyViewedRecipe(recipe); }); + servingsSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 1)); + servingsSpinner.setEditable(true); + servingsSpinner.valueProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + setCurrentlyViewedRecipe(recipe); + }); langSelector.getItems().addAll("en", "nl", "pl", "tok"); } }