소스 검색

Update ProductPanel, change PhasePanel to CardPanel with better syntax.

Sam Jaffe 5 년 전
부모
커밋
02467f56ef

+ 30 - 0
src/main/lombok/org/leumasjaffe/recipe/view/CardPanel.java

@@ -0,0 +1,30 @@
+package org.leumasjaffe.recipe.view;
+
+import javax.swing.JPanel;
+
+import org.leumasjaffe.recipe.model.Card;
+import org.leumasjaffe.recipe.model.Rest;
+import org.leumasjaffe.recipe.model.Step;
+import org.jdesktop.swingx.VerticalLayout;
+
+@SuppressWarnings("serial")
+public class CardPanel extends JPanel {
+	private int steps = 0;
+	
+	public CardPanel(final Card card) {		
+		setLayout(new VerticalLayout(5));
+		
+		card.getPreparation().ifPresent(this::addStep);
+		card.getCooking().forEach(this::addStep);
+		card.getRest().ifPresent(this::addRest);
+	}
+	
+	void addStep(final Step step) {
+		add(new StepPanel(steps++, step));
+	}
+	
+	void addRest(final Rest rest) {
+		add(new RestPanel(rest));
+	}
+
+}

+ 0 - 22
src/main/lombok/org/leumasjaffe/recipe/view/PhasePanel.java

@@ -1,22 +0,0 @@
-package org.leumasjaffe.recipe.view;
-
-import javax.swing.JPanel;
-import javax.swing.JSeparator;
-
-import org.leumasjaffe.recipe.model.Product;
-import org.leumasjaffe.recipe.model.Step;
-import org.jdesktop.swingx.VerticalLayout;
-
-@SuppressWarnings("serial")
-public class PhasePanel extends JPanel {
-
-	public PhasePanel(Product.Phase phase) {
-		setLayout(new VerticalLayout(5));
-		int i = 0;
-		for (Step comp : phase.getSteps()) {
-			add(new StepPanel(i++, comp));
-			add(new JSeparator());
-		}
-	}
-
-}

+ 5 - 20
src/main/lombok/org/leumasjaffe/recipe/view/ProductPanel.java

@@ -3,9 +3,8 @@ package org.leumasjaffe.recipe.view;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 
+import org.leumasjaffe.recipe.model.Card;
 import org.leumasjaffe.recipe.model.Product;
-import org.leumasjaffe.recipe.model.RecipeComponent;
-import org.leumasjaffe.recipe.model.Rest;
 import org.jdesktop.swingx.VerticalLayout;
 
 import javax.swing.JButton;
@@ -18,30 +17,16 @@ public class ProductPanel extends JScrollPane {
 		JPanel panelColumnHeader = new JPanel();
 		setColumnHeaderView(panelColumnHeader);
 		
-		JButton btnAddStep = new JButton("Add Step");
+		JButton btnAddStep = new JButton("Add Card");
 		panelColumnHeader.add(btnAddStep);
 		
 		panelViewPort = new JPanel();
 		setViewportView(panelViewPort);
 		panelViewPort.setLayout(new VerticalLayout(5));
 		
-		for (RecipeComponent comp : product.getComponents()) {
-			if (comp instanceof Rest) {
-				addRest((Rest) comp);
-			} else if (comp instanceof Product.Phase) {
-				addPhase((Product.Phase) comp);
-			}
+		for (final Card card : product.getCards()) {
+			panelViewPort.add(new CardPanel(card));
+			panelViewPort.add(new JSeparator());
 		}
 	}
-	
-	void addPhase(final Product.Phase phase) {
-		panelViewPort.add(new PhasePanel(phase));
-		panelViewPort.add(new JSeparator());
-	}
-	
-	void addRest(final Rest rest) {
-		panelViewPort.add(new RestPanel(rest));
-		panelViewPort.add(new JSeparator());
-	}
-
 }