|
|
@@ -10,6 +10,8 @@ import javax.swing.JTextArea;
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
import org.jdesktop.swingx.VerticalLayout;
|
|
|
+import org.leumasjaffe.observer.ObservableListener;
|
|
|
+import org.leumasjaffe.recipe.model.CollatedDuration;
|
|
|
import org.leumasjaffe.recipe.model.Element;
|
|
|
import org.leumasjaffe.recipe.model.RecipeCard;
|
|
|
import org.leumasjaffe.recipe.view.CollatedDurationPanel;
|
|
|
@@ -22,6 +24,8 @@ import java.awt.Font;
|
|
|
@SuppressWarnings("serial")
|
|
|
@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class SummaryPanel extends JPanel {
|
|
|
+ ObservableListener<CollatedDurationPanel, RecipeCard> durationListener;
|
|
|
+ ObservableListener<JPanel, RecipeCard> childListener;
|
|
|
|
|
|
public SummaryPanel(final RecipeCard card) {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
@@ -56,13 +60,12 @@ public class SummaryPanel extends JPanel {
|
|
|
panelHeader.add(txtTitle, gbc_txtTitle);
|
|
|
txtTitle.setColumns(10);
|
|
|
|
|
|
- CollatedDurationPanel panelDuration =
|
|
|
- new CollatedDurationPanel(card.getCollatedDuration());
|
|
|
+ CollatedDurationPanel panelDuration = new CollatedDurationPanel(CollatedDuration.ZERO);
|
|
|
GridBagConstraints gbc_panelDuration = new GridBagConstraints();
|
|
|
gbc_panelDuration.gridx = 0;
|
|
|
gbc_panelDuration.gridy = 1;
|
|
|
- panelHeader.add(panelDuration, gbc_panelDuration);
|
|
|
|
|
|
+ panelHeader.add(panelDuration, gbc_panelDuration);
|
|
|
JPanel panelIngredients = new JPanel();
|
|
|
GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
|
gbc_panelIngredients.insets = new Insets(0, 0, 5, 5);
|
|
|
@@ -105,10 +108,24 @@ public class SummaryPanel extends JPanel {
|
|
|
gbc_txaDesription.gridy = 1;
|
|
|
panel.add(txaDesription, gbc_txaDesription);
|
|
|
|
|
|
- for (final Element element : card.getElements()) {
|
|
|
- panelIngredients.add(new ElementPanel(element));
|
|
|
- panelIngredients.add(new JSeparator());
|
|
|
- }
|
|
|
+ durationListener = new ObservableListener<>(panelDuration,
|
|
|
+ (c, v) -> c.setModel(v.getCollatedDuration()));
|
|
|
+
|
|
|
+ childListener = new ObservableListener<>(panelIngredients, (c, v) -> {
|
|
|
+ if (c.getComponents().length == v.getElements().size()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ c.removeAll();
|
|
|
+ for (final Element element : v.getElements()) {
|
|
|
+ JPanel wrapper = new JPanel(new VerticalLayout());
|
|
|
+ wrapper.add(new ElementPanel(element));
|
|
|
+ wrapper.add(new JSeparator());
|
|
|
+ c.add(wrapper);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ durationListener.setObserved(card);
|
|
|
+ childListener.setObserved(card);
|
|
|
}
|
|
|
|
|
|
}
|