Skip to content
Snippets Groups Projects
Commit 223febf6 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

(Recipe view) fixed bug where the ingredient label wouldn't fully show

parent cc29aeab
No related branches found
No related tags found
No related merge requests found
package mi.hdm.components;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import mi.hdm.recipes.Measurement;
import javafx.scene.text.Text;
import mi.hdm.recipes.RecipeComponent;
public class IngredientLabel extends HBox {
private final String name;
private final int amount;
private final Measurement measurement;
private final RecipeComponent component;
public IngredientLabel(String name, int amount, Measurement measurement) {
public IngredientLabel(int amount, RecipeComponent component) {
super();
this.name = name;
this.amount = amount;
this.measurement = measurement;
this.component = component;
Label labelAmount = new Label(amount + " " + measurement);
labelAmount.prefWidth(100);
Label labelName = new Label(name);
labelName.prefWidth(300);
Text labelAmount = new Text(amount + " " + component.getMeasurement());
Text labelName = new Text(component.getName());
getChildren().addAll(labelAmount, labelName);
//setAlignment(Pos.BASELINE_LEFT);
setSpacing(5.0);
//setStyle("-fx-padding: 5px");
setSpacing(16.0);
setStyle("-fx-padding: 5px;");
}
public int getAmount() {
return amount;
}
public RecipeComponent getComponent() {
//TODO: create a copy
return component;
}
}
......@@ -7,7 +7,10 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import mi.hdm.components.IngredientLabel;
import mi.hdm.recipes.*;
import mi.hdm.recipes.Ingredient;
import mi.hdm.recipes.IngredientManager;
import mi.hdm.recipes.Recipe;
import mi.hdm.recipes.RecipeManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -60,11 +63,9 @@ public class RecipeViewController extends BaseController {
//TODO: amount and measurement are not displayed, but without the name they are
recipe.getIngredients().forEach((code, amount) -> {
Ingredient i = ingredientManager.getIngredient(code).orElseThrow();
String name = i.getName();
Measurement measurement = i.getMeasurement();
IngredientLabel ingredientLabel = new IngredientLabel(name, amount, measurement);
log.debug("Added ingredient label with the following values: {}, {}, {}", name, amount, measurement);
IngredientLabel ingredientLabel = new IngredientLabel(amount, i);
ingredientVBox.getChildren().add(ingredientLabel);
log.debug("Added ingredient label with the following values: {}, {}, {}", i.getName(), amount, i.getMeasurement());
});
......
......@@ -102,6 +102,7 @@ public class CategoryManager {
}
public static String numberToColorCodeString(int colourCode) {
//TODO: move method into Category class, remove the #
String intToHex = Integer.toHexString(colourCode);
intToHex = intToHex
.indent(6 - intToHex.length())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment