Quellcode durchsuchen

Add preparation and instructions into the view.

Sam Jaffe vor 5 Jahren
Ursprung
Commit
1f7ef6ae5e

+ 1 - 1
src/main/lombok/org/leumasjaffe/recipe/model/Ingredient.java

@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
 @Data @AllArgsConstructor @NoArgsConstructor
 public class Ingredient {
 	String name;
-	String preparation;
+	String preparation = "";
 	Amount amount;
 	
 	Ingredient plus(final Ingredient rhs) {

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

@@ -21,12 +21,13 @@ import javax.swing.JLabel;
 public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentListenable {
 	private JTextField txtName;
 	private JTextField txtUnit;
+	private JTextField txtPreparation;
 	
 	public IngredientPanel(final Ingredient ingredient) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
-		gridBagLayout.columnWidths = new int[]{0, 100, 40, 40, 0};
+		gridBagLayout.columnWidths = new int[]{0, 100, 40, 40, 40, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
-		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
+		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
@@ -65,12 +66,23 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 		txtUnit = new JTextField(ingredient.getAmount().unitName());
 		txtUnit.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtUnit = new GridBagConstraints();
+		gbc_txtUnit.insets = new Insets(0, 0, 0, 5);
 		gbc_txtUnit.anchor = GridBagConstraints.ABOVE_BASELINE;
 		gbc_txtUnit.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtUnit.gridx = 3;
 		gbc_txtUnit.gridy = 0;
 		add(txtUnit, gbc_txtUnit);
 		txtUnit.setColumns(10);
+		
+		txtPreparation = new JTextField(ingredient.getPreparation());
+		txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
+		GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
+		gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
+		gbc_txtPreparation.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtPreparation.gridx = 4;
+		gbc_txtPreparation.gridy = 0;
+		add(txtPreparation, gbc_txtPreparation);
+		txtPreparation.setColumns(10);
 	}
 
 	@Override

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

@@ -30,7 +30,7 @@ public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentLi
 		setLayout(gridBagLayout);
 		
 		JPanel panelLeft = new JPanel();
-		panelLeft.setPreferredSize(new Dimension(200, 50));
+		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;
@@ -44,7 +44,7 @@ public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentLi
 		gbl_panelLeft.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
 		panelLeft.setLayout(gbl_panelLeft);
 		
-		lblIndex = new JLabel("");
+		lblIndex = new JLabel("Prep");
 		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
 		gbc_lblIndex.fill = GridBagConstraints.HORIZONTAL;
 		gbc_lblIndex.insets = new Insets(0, 0, 5, 5);
@@ -59,7 +59,7 @@ public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentLi
 		gbc_horizontalGlue.gridy = 0;
 		panelLeft.add(horizontalGlue, gbc_horizontalGlue);
 		
-		JLabel lblDuration = new JLabel("Duration");
+		JLabel lblDuration = new JLabel("Requires: " + step.getDuration().toString());
 		GridBagConstraints gbc_lblDuration = new GridBagConstraints();
 		gbc_lblDuration.insets = new Insets(0, 0, 5, 0);
 		gbc_lblDuration.gridx = 2;
@@ -74,15 +74,6 @@ public class PreparationPanel extends JPanel implements AutoGrowPanel.DocumentLi
 		gbc_panelIngredients.gridx = 0;
 		gbc_panelIngredients.gridy = 1;
 		panelLeft.add(panelIngredients, gbc_panelIngredients);
-		
-		txtpnInstructions = new JTextPane();
-		txtpnInstructions.setPreferredSize(new Dimension(200, 30));
-		txtpnInstructions.setText("Instructions");
-		GridBagConstraints gbc_txtpnInstructions = new GridBagConstraints();
-		gbc_txtpnInstructions.fill = GridBagConstraints.BOTH;
-		gbc_txtpnInstructions.gridx = 1;
-		gbc_txtpnInstructions.gridy = 0;
-		add(txtpnInstructions, gbc_txtpnInstructions);
 	}
 
 	@Override

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

@@ -30,7 +30,7 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		setLayout(gridBagLayout);
 		
 		JPanel panelLeft = new JPanel();
-		panelLeft.setPreferredSize(new Dimension(200, 50));
+		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;
@@ -59,7 +59,7 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		gbc_horizontalGlue.gridy = 0;
 		panelLeft.add(horizontalGlue, gbc_horizontalGlue);
 		
-		JLabel lblDuration = new JLabel("Duration");
+		JLabel lblDuration = new JLabel("Requires: " + step.getDuration().toString());
 		GridBagConstraints gbc_lblDuration = new GridBagConstraints();
 		gbc_lblDuration.insets = new Insets(0, 0, 5, 0);
 		gbc_lblDuration.gridx = 2;
@@ -77,7 +77,7 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		
 		txtpnInstructions = new JTextPane();
 		txtpnInstructions.setPreferredSize(new Dimension(200, 30));
-		txtpnInstructions.setText("Instructions");
+		txtpnInstructions.setText(step.getInstruction());
 		GridBagConstraints gbc_txtpnInstructions = new GridBagConstraints();
 		gbc_txtpnInstructions.fill = GridBagConstraints.BOTH;
 		gbc_txtpnInstructions.gridx = 1;

+ 35 - 2
src/test/resources/example.json

@@ -13,7 +13,7 @@
             "ingredients": [
               {
                 "name": "onion",
-                "preparation": "",
+                "preparation": "Chopped",
                 "amount": "100 g"
               }
             ],
@@ -23,7 +23,40 @@
               "minSeconds": 300,
               "maxSeconds": 600
             }
-          }
+          },
+          "cooking": [
+          	{
+          		"ingredients": [
+          			{
+          				"name": "Oil",
+          				"amount": "1 Tbsp"
+          			}
+          		],
+	            "duration": {
+	              "displayAs": "SECONDS",
+	              "approximate": true,
+	              "minSeconds": 30,
+	              "maxSeconds": 60
+	            },
+          		"instruction": "Heat oil over high heat"
+          	},
+          	{
+          		"ingredients": [
+          			{
+          				"name": "Onion",
+          				"preparation": "Chopped",
+          				"amount": "100 g"
+          			}
+          		],
+	            "duration": {
+	              "displayAs": "MINUTES",
+	              "approximate": true,
+	              "minSeconds": 300,
+	              "maxSeconds": 900
+	            },
+          		"instruction": "Sauté the onions until soft and translucent, stirring to prevent burning"
+          	}
+          ]
         }
       ]
     }