|
|
@@ -9,11 +9,13 @@ import java.awt.event.FocusListener;
|
|
|
|
|
|
import javax.swing.event.DocumentListener;
|
|
|
|
|
|
+import org.leumasjaffe.observer.ForwardingObservableListener;
|
|
|
import org.leumasjaffe.observer.ObservableController;
|
|
|
import org.leumasjaffe.observer.ObservableListener;
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
import org.leumasjaffe.recipe.view.formatter.AmountFormatter;
|
|
|
+import org.leumasjaffe.recipe.viewmodel.ScaleFactor;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
import lombok.Getter;
|
|
|
@@ -28,11 +30,15 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.ChildCompon
|
|
|
ObservableListener<JTextField, Ingredient> nameController;
|
|
|
ObservableListener<JFormattedTextField, Ingredient> amountController;
|
|
|
ObservableListener<JTextField, Ingredient> preparationController;
|
|
|
+ ForwardingObservableListener<Ingredient> forward = new ForwardingObservableListener<>();
|
|
|
+
|
|
|
@Getter(AccessLevel.PACKAGE) JTextField txtName;
|
|
|
@Getter(AccessLevel.PACKAGE) JFormattedTextField txtAmount;
|
|
|
@Getter(AccessLevel.PACKAGE) JTextField txtPreparation;
|
|
|
+ ScaleFactor scale;
|
|
|
|
|
|
- public IngredientPanel(boolean editable) {
|
|
|
+ public IngredientPanel(final ScaleFactor scale, boolean editable) {
|
|
|
+ this.scale = scale;
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
@@ -81,17 +87,17 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.ChildCompon
|
|
|
nameController = ObservableController.from(txtName,
|
|
|
Ingredient::getName, Ingredient::setName);
|
|
|
amountController = ObservableController.from(txtAmount,
|
|
|
- Ingredient::getAmount, Ingredient::setAmount);
|
|
|
+ i -> i.getAmount().scale(scale.getScale()), Ingredient::setAmount);
|
|
|
preparationController = ObservableController.from(txtPreparation,
|
|
|
Ingredient::getPreparation, Ingredient::setPreparation,
|
|
|
ing -> {
|
|
|
ing.setPreparation("");
|
|
|
ObserverDispatch.notifySubscribers(ing);
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public IngredientPanel(final Ingredient ingredient, boolean editable) {
|
|
|
- this(editable);
|
|
|
+ public IngredientPanel(final Ingredient ingredient, final ScaleFactor scale, boolean editable) {
|
|
|
+ this(scale, editable);
|
|
|
setModel(ingredient);
|
|
|
}
|
|
|
|
|
|
@@ -99,6 +105,7 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.ChildCompon
|
|
|
nameController.setObserved(ingredient);
|
|
|
amountController.setObserved(ingredient);
|
|
|
preparationController.setObserved(ingredient);
|
|
|
+ forward.setObserved(ingredient, scale);
|
|
|
}
|
|
|
|
|
|
@Override
|