Bläddra i källkod

Add summary of Product ingredients, fix display by removing preferredSize settings.

Sam Jaffe 5 år sedan
förälder
incheckning
c4103ad3f4

+ 3 - 3
src/main/lombok/org/leumasjaffe/recipe/view/IngredientPanel.java

@@ -25,9 +25,9 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 	
 	public IngredientPanel(final Ingredient ingredient) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
-		gridBagLayout.columnWidths = new int[]{0, 100, 40, 40, 40, 0};
+		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
-		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
+		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
@@ -72,7 +72,7 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 		gbc_txtUnit.gridx = 3;
 		gbc_txtUnit.gridy = 0;
 		add(txtUnit, gbc_txtUnit);
-		txtUnit.setColumns(10);
+		txtUnit.setColumns(6);
 		
 		txtPreparation = new JTextField(ingredient.getPreparation());
 		txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));

+ 0 - 2
src/main/lombok/org/leumasjaffe/recipe/view/PreparationPanel.java

@@ -14,7 +14,6 @@ import javax.swing.JLabel;
 import javax.swing.JTextPane;
 import java.awt.Component;
 import javax.swing.Box;
-import java.awt.Dimension;
 
 @SuppressWarnings("serial")
 public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentListenable {
@@ -30,7 +29,6 @@ public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentLi
 		setLayout(gridBagLayout);
 		
 		JPanel panelLeft = new JPanel();
-		panelLeft.setPreferredSize(new Dimension(300, 50));
 		GridBagConstraints gbc_panelLeft = new GridBagConstraints();
 		gbc_panelLeft.insets = new Insets(0, 0, 0, 5);
 		gbc_panelLeft.fill = GridBagConstraints.BOTH;

+ 39 - 0
src/main/lombok/org/leumasjaffe/recipe/view/ProductSummaryPanel.java

@@ -0,0 +1,39 @@
+package org.leumasjaffe.recipe.view;
+
+import javax.swing.JPanel;
+
+import org.leumasjaffe.recipe.model.Product;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.util.ArrayList;
+
+import javax.swing.JLabel;
+import java.awt.GridBagConstraints;
+
+@SuppressWarnings("serial")
+public class ProductSummaryPanel extends JPanel {
+	public ProductSummaryPanel(final Product product) {
+		GridBagLayout gridBagLayout = new GridBagLayout();
+		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};
+		setLayout(gridBagLayout);
+		
+		JLabel lblProductName = new JLabel(product.getName());
+		GridBagConstraints gbc_lblProductName = new GridBagConstraints();
+		gbc_lblProductName.gridx = 0;
+		gbc_lblProductName.gridy = 0;
+		add(lblProductName, gbc_lblProductName);
+		
+		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);
+	}
+}

+ 1 - 0
src/main/lombok/org/leumasjaffe/recipe/view/RecipeFrame.java

@@ -28,6 +28,7 @@ public class RecipeFrame extends JFrame {
 		try {
 			Recipe recipe = mapper.readValue(new File("src/test/resources/example.json"), Recipe.class);
 			for (Product comp : recipe.getProducts()) {
+				summaryPanel.addProduct(comp);
 				tabbedPane.addTab(comp.getName(), new ProductPanel(comp));
 			}
 		} catch (IOException e) {

+ 0 - 1
src/main/lombok/org/leumasjaffe/recipe/view/StepPanel.java

@@ -30,7 +30,6 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		setLayout(gridBagLayout);
 		
 		JPanel panelLeft = new JPanel();
-		panelLeft.setPreferredSize(new Dimension(300, 50));
 		GridBagConstraints gbc_panelLeft = new GridBagConstraints();
 		gbc_panelLeft.insets = new Insets(0, 0, 0, 5);
 		gbc_panelLeft.fill = GridBagConstraints.BOTH;

+ 14 - 4
src/main/lombok/org/leumasjaffe/recipe/view/SummaryPanel.java

@@ -7,14 +7,20 @@ import java.awt.Insets;
 
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JSeparator;
 import javax.swing.JTextField;
 import javax.swing.JTextPane;
 
 import org.jdesktop.swingx.VerticalLayout;
+import org.leumasjaffe.recipe.model.Product;
+
+import lombok.AccessLevel;
+import lombok.experimental.FieldDefaults;
 
 @SuppressWarnings("serial")
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 public class SummaryPanel extends JPanel {
-	JTextField txtTitle;
+	JPanel panelIngredients;
 	
 	public SummaryPanel() {
 		GridBagLayout gridBagLayout = new GridBagLayout();
@@ -39,7 +45,7 @@ public class SummaryPanel extends JPanel {
 		gbl_panelHeader.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		panelHeader.setLayout(gbl_panelHeader);
 		
-		txtTitle = new JTextField();
+		JTextField txtTitle = new JTextField();
 		txtTitle.setText("Title");
 		GridBagConstraints gbc_txtTitle = new GridBagConstraints();
 		gbc_txtTitle.insets = new Insets(0, 0, 0, 5);
@@ -55,8 +61,7 @@ public class SummaryPanel extends JPanel {
 		gbc_lblDuration.gridy = 0;
 		panelHeader.add(lblDuration, gbc_lblDuration);
 		
-		JPanel panelIngredients = new JPanel();
-		panelIngredients.setPreferredSize(new Dimension(200, 100));
+		panelIngredients = new JPanel();
 		GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
 		gbc_panelIngredients.gridheight = 2;
 		gbc_panelIngredients.insets = new Insets(0, 0, 0, 5);
@@ -83,4 +88,9 @@ public class SummaryPanel extends JPanel {
 		gbc_txtpnDescription.gridy = 2;
 		add(txtpnDescription, gbc_txtpnDescription);
 	}
+
+	void addProduct(final Product comp) {
+		panelIngredients.add(new ProductSummaryPanel(comp));
+		panelIngredients.add(new JSeparator());
+	}
 }

+ 17 - 5
src/test/resources/example.json

@@ -13,9 +13,21 @@
             "ingredients": [
               {
                 "name": "onion",
-                "preparation": "Chopped",
+                "preparation": "chopped",
                 "amount": "100 g"
-              }
+              },
+              {
+                "name": "onion",
+                "amount": "1"
+              },
+              {
+              	"name": "oil",
+              	"amount": "1 Tbsp"
+            	},
+              {
+              	"name": "oil",
+              	"amount": "1 Tbsp"
+            	}
             ],
             "duration": {
               "displayAs": "MINUTES",
@@ -28,7 +40,7 @@
           	{
           		"ingredients": [
           			{
-          				"name": "Oil",
+          				"name": "oil",
           				"amount": "1 Tbsp"
           			}
           		],
@@ -43,8 +55,8 @@
           	{
           		"ingredients": [
           			{
-          				"name": "Onion",
-          				"preparation": "Chopped",
+          				"name": "onion",
+          				"preparation": "chopped",
           				"amount": "100 g"
           			}
           		],