Browse Source

Add model editing to title and other things about the RecipeCard.

Sam Jaffe 5 years ago
parent
commit
516d09425e
1 changed files with 22 additions and 13 deletions
  1. 22 13
      src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

+ 22 - 13
src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

@@ -10,6 +10,7 @@ import javax.swing.JTextArea;
 import javax.swing.JTextField;
 
 import org.jdesktop.swingx.VerticalLayout;
+import org.leumasjaffe.observer.ObservableController;
 import org.leumasjaffe.observer.ObservableListener;
 import org.leumasjaffe.observer.ObserverDispatch;
 import org.leumasjaffe.recipe.controller.ReplaceChildrenController;
@@ -25,11 +26,13 @@ import lombok.experimental.FieldDefaults;
 @FieldDefaults(level=AccessLevel.PRIVATE)
 public class SummaryPanel extends JPanel {
 	ReplaceChildrenController<RecipeCard, Element> controller;
+	ObservableListener<JTextField, RecipeCard> titleListener;
+	ObservableListener<JTextArea, RecipeCard> descriptionListener;
 	ObservableListener<CollatedDurationPanel, RecipeCard> durationListener;
 	ObservableListener<JPanel, RecipeCard> childListener;
 	
 	JTextField txtTitle;
-	JTextArea txaDesription;
+	JTextArea txaDescription;
 	
 	public SummaryPanel() {
 		controller = new ReplaceChildrenController<>(RecipeCard::getElements, element -> {
@@ -42,7 +45,7 @@ public class SummaryPanel extends JPanel {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
-		gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
+		gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
@@ -107,16 +110,22 @@ public class SummaryPanel extends JPanel {
 		gbc_panelPhoto.gridy = 0;
 		panel.add(panelPhoto, gbc_panelPhoto);
 		
-		txaDesription = new JTextArea(5, 20);
-		txaDesription.setWrapStyleWord(true);
-		txaDesription.setLineWrap(true);
-		GridBagConstraints gbc_txaDesription = new GridBagConstraints();
-		gbc_txaDesription.insets = new Insets(0, 0, 5, 0);
-		gbc_txaDesription.fill = GridBagConstraints.BOTH;
-		gbc_txaDesription.gridx = 0;
-		gbc_txaDesription.gridy = 1;
-		panel.add(txaDesription, gbc_txaDesription);
+		txaDescription = new JTextArea(5, 20);
+		txaDescription.setWrapStyleWord(true);
+		txaDescription.setLineWrap(true);
+		GridBagConstraints gbc_txaDescription = new GridBagConstraints();
+		gbc_txaDescription.insets = new Insets(0, 0, 5, 0);
+		gbc_txaDescription.fill = GridBagConstraints.BOTH;
+		gbc_txaDescription.gridx = 0;
+		gbc_txaDescription.gridy = 1;
+		panel.add(txaDescription, gbc_txaDescription);
 		
+		titleListener = ObservableController.from(txtTitle,
+				RecipeCard::getTitle, RecipeCard::setTitle);
+
+		descriptionListener = ObservableController.from(txaDescription,
+				RecipeCard::getDescription, RecipeCard::setDescription);
+
 		durationListener = new ObservableListener<>(panelDuration,
 				(c, v) -> c.setModel(v.getCollatedDuration()));
 		
@@ -131,8 +140,8 @@ public class SummaryPanel extends JPanel {
 	}
 	
 	public void setModel(final RecipeCard card) {
-		txtTitle.setText(card.getTitle());
-		txaDesription.setText(card.getDescription());
+		titleListener.setObserved(card);
+		descriptionListener.setObserved(card);
 		durationListener.setObserved(card);
 		childListener.setObserved(card);
 	}