|
@@ -5,11 +5,11 @@ import javax.swing.JPanel;
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
import org.leumasjaffe.observer.ObservableListener;
|
|
import org.leumasjaffe.observer.ObservableListener;
|
|
|
import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
|
|
import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
|
|
|
|
|
+import org.leumasjaffe.recipe.model.Duration;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
import org.leumasjaffe.recipe.model.Preparation;
|
|
import org.leumasjaffe.recipe.model.Preparation;
|
|
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
import lombok.AccessLevel;
|
|
|
-import lombok.Getter;
|
|
|
|
|
import lombok.experimental.FieldDefaults;
|
|
import lombok.experimental.FieldDefaults;
|
|
|
|
|
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagLayout;
|
|
@@ -27,9 +27,9 @@ public class PreparationPanel extends JPanel {
|
|
|
ReplaceChildrenController<Preparation, Ingredient> controller;
|
|
ReplaceChildrenController<Preparation, Ingredient> controller;
|
|
|
ObservableListener<JPanel, Preparation> childListener;
|
|
ObservableListener<JPanel, Preparation> childListener;
|
|
|
|
|
|
|
|
- @Getter(AccessLevel.PACKAGE) JPanel panelIngredients;
|
|
|
|
|
|
|
+ DurationPanel panelDuration;
|
|
|
|
|
|
|
|
- public PreparationPanel(Preparation preparation) {
|
|
|
|
|
|
|
+ public PreparationPanel() {
|
|
|
controller = new ReplaceChildrenController<>(Preparation::getIngredients,
|
|
controller = new ReplaceChildrenController<>(Preparation::getIngredients,
|
|
|
IngredientPreparationPanel::new);
|
|
IngredientPreparationPanel::new);
|
|
|
|
|
|
|
@@ -69,14 +69,14 @@ public class PreparationPanel extends JPanel {
|
|
|
gbc_horizontalGlue.gridy = 0;
|
|
gbc_horizontalGlue.gridy = 0;
|
|
|
panelLeft.add(horizontalGlue, gbc_horizontalGlue);
|
|
panelLeft.add(horizontalGlue, gbc_horizontalGlue);
|
|
|
|
|
|
|
|
- DurationPanel panelDuration = new DurationPanel("Requires", preparation.getDuration());
|
|
|
|
|
|
|
+ panelDuration = new DurationPanel("Requires", Duration.ZERO);
|
|
|
GridBagConstraints gbc_panelDuration = new GridBagConstraints();
|
|
GridBagConstraints gbc_panelDuration = new GridBagConstraints();
|
|
|
gbc_panelDuration.insets = new Insets(0, 0, 5, 0);
|
|
gbc_panelDuration.insets = new Insets(0, 0, 5, 0);
|
|
|
gbc_panelDuration.gridx = 2;
|
|
gbc_panelDuration.gridx = 2;
|
|
|
gbc_panelDuration.gridy = 0;
|
|
gbc_panelDuration.gridy = 0;
|
|
|
panelLeft.add(panelDuration, gbc_panelDuration);
|
|
panelLeft.add(panelDuration, gbc_panelDuration);
|
|
|
|
|
|
|
|
- panelIngredients = new JPanel();
|
|
|
|
|
|
|
+ JPanel panelIngredients = new JPanel();
|
|
|
panelIngredients.setLayout(new VerticalLayout(5));
|
|
panelIngredients.setLayout(new VerticalLayout(5));
|
|
|
GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
|
gbc_panelIngredients.gridwidth = 3;
|
|
gbc_panelIngredients.gridwidth = 3;
|
|
@@ -85,11 +85,19 @@ public class PreparationPanel extends JPanel {
|
|
|
gbc_panelIngredients.gridx = 0;
|
|
gbc_panelIngredients.gridx = 0;
|
|
|
gbc_panelIngredients.gridy = 1;
|
|
gbc_panelIngredients.gridy = 1;
|
|
|
panelLeft.add(panelIngredients, gbc_panelIngredients);
|
|
panelLeft.add(panelIngredients, gbc_panelIngredients);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// This indirection allows for testing of controller
|
|
// This indirection allows for testing of controller
|
|
|
childListener = new ObservableListener<>(panelIngredients,
|
|
childListener = new ObservableListener<>(panelIngredients,
|
|
|
(c, v) -> controller.accept(c, v));
|
|
(c, v) -> controller.accept(c, v));
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public PreparationPanel(final Preparation preparation) {
|
|
|
|
|
+ this();
|
|
|
|
|
+ setModel(preparation);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setModel(final Preparation preparation) {
|
|
|
|
|
+ panelDuration.setModel(preparation.getDuration());
|
|
|
childListener.setObserved(preparation);
|
|
childListener.setObserved(preparation);
|
|
|
}
|
|
}
|
|
|
|
|
|