|
@@ -2,38 +2,48 @@ package org.leumasjaffe.recipe.view;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
|
|
+import org.jdesktop.swingx.VerticalLayout;
|
|
|
|
|
+import org.leumasjaffe.observer.ObservableListener;
|
|
|
import org.leumasjaffe.recipe.model.Product;
|
|
import org.leumasjaffe.recipe.model.Product;
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagLayout;
|
|
|
import java.awt.Insets;
|
|
import java.awt.Insets;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagConstraints;
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
|
public class ProductSummaryPanel extends JPanel {
|
|
public class ProductSummaryPanel extends JPanel {
|
|
|
|
|
+ ObservableListener<JPanel, Product> listener;
|
|
|
|
|
+
|
|
|
public ProductSummaryPanel(final Product product) {
|
|
public ProductSummaryPanel(final Product product) {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
|
- gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
|
|
- gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
|
|
|
|
- gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
|
|
|
|
+ gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
|
|
|
|
+ gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
|
|
|
|
|
+ gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
setLayout(gridBagLayout);
|
|
|
|
|
|
|
|
JLabel lblProductName = new JLabel(product.getName());
|
|
JLabel lblProductName = new JLabel(product.getName());
|
|
|
GridBagConstraints gbc_lblProductName = new GridBagConstraints();
|
|
GridBagConstraints gbc_lblProductName = new GridBagConstraints();
|
|
|
|
|
+ gbc_lblProductName.insets = new Insets(0, 0, 5, 5);
|
|
|
gbc_lblProductName.gridx = 0;
|
|
gbc_lblProductName.gridx = 0;
|
|
|
gbc_lblProductName.gridy = 0;
|
|
gbc_lblProductName.gridy = 0;
|
|
|
add(lblProductName, gbc_lblProductName);
|
|
add(lblProductName, gbc_lblProductName);
|
|
|
|
|
+
|
|
|
|
|
+ JPanel panel = new JPanel();
|
|
|
|
|
+ panel.setLayout(new VerticalLayout());
|
|
|
|
|
+ GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
|
|
|
+ gbc_panel.gridwidth = 2;
|
|
|
|
|
+ gbc_panel.insets = new Insets(0, 0, 0, 5);
|
|
|
|
|
+ gbc_panel.fill = GridBagConstraints.BOTH;
|
|
|
|
|
+ gbc_panel.gridx = 0;
|
|
|
|
|
+ gbc_panel.gridy = 1;
|
|
|
|
|
+ add(panel, gbc_panel);
|
|
|
|
|
|
|
|
- AutoGrowPanel panelIngredients = new AutoGrowPanel(IngredientPanel::new,
|
|
|
|
|
- new ArrayList<>(product.getIngredients()));
|
|
|
|
|
- GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
|
|
|
- gbc_panelIngredients.gridwidth = 2;
|
|
|
|
|
- gbc_panelIngredients.insets = new Insets(0, 0, 0, 5);
|
|
|
|
|
- gbc_panelIngredients.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- gbc_panelIngredients.gridx = 0;
|
|
|
|
|
- gbc_panelIngredients.gridy = 1;
|
|
|
|
|
- add(panelIngredients, gbc_panelIngredients);
|
|
|
|
|
|
|
+ listener = new ObservableListener<>(panel, (c, t) -> {
|
|
|
|
|
+ c.removeAll();
|
|
|
|
|
+ product.getIngredients().stream().map(IngredientPanel::new).forEach(c::add);
|
|
|
|
|
+ });
|
|
|
|
|
+ listener.setObserved(product);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|