Przeglądaj źródła

Change DurationPanel to use the new Formatter.
Make CollatedDurationPanel's children not editable.

Sam Jaffe 5 lat temu
rodzic
commit
58a0780ca9

+ 11 - 6
src/main/lombok/org/leumasjaffe/recipe/view/CollatedDurationPanel.java

@@ -6,7 +6,6 @@ import javax.swing.SwingConstants;
 
 import org.jdesktop.swingx.HorizontalLayout;
 import org.leumasjaffe.recipe.model.CollatedDuration;
-import org.leumasjaffe.recipe.model.Duration;
 
 import lombok.AccessLevel;
 import lombok.experimental.FieldDefaults;
@@ -18,20 +17,26 @@ public class CollatedDurationPanel extends JPanel {
 	DurationPanel panelCookingTime;
 	DurationPanel panelTotalTime;
 	
-	public CollatedDurationPanel(final CollatedDuration duration) {
+	public CollatedDurationPanel() {
 		setLayout(new HorizontalLayout(5));
 		
-		panelPrepTime = new DurationPanel("Prep", Duration.ZERO);
+		panelPrepTime = new DurationPanel("Prep");
+		panelPrepTime.setEditable(false);
 		add(panelPrepTime);
 		add(new JSeparator(SwingConstants.VERTICAL));
 		
-		panelCookingTime = new DurationPanel("Cooking", Duration.ZERO);
+		panelCookingTime = new DurationPanel("Cooking");
+		panelCookingTime.setEditable(false);
 		add(panelCookingTime);
 		add(new JSeparator(SwingConstants.VERTICAL));
 		
-		panelTotalTime = new DurationPanel("Total", Duration.ZERO);
+		panelTotalTime = new DurationPanel("Total");
+		panelTotalTime.setEditable(false);
 		add(panelTotalTime);
-		
+	}
+	
+	public CollatedDurationPanel(final CollatedDuration duration) {
+		this();
 		setModel(duration);
 	}
 	

+ 17 - 7
src/main/lombok/org/leumasjaffe/recipe/view/DurationPanel.java

@@ -4,14 +4,20 @@ import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 
+import javax.swing.JFormattedTextField;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import org.leumasjaffe.recipe.model.Duration;
+import org.leumasjaffe.recipe.view.formatter.DurationFormatter;
 
 @SuppressWarnings("serial")
 public class DurationPanel extends JPanel {
-	private JLabel lblTime;
+	private JFormattedTextField txtTime;
+	
+	/**
+	 * @wbp.parser.constructor
+	 */
 	public DurationPanel(String name) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0};
@@ -27,11 +33,11 @@ public class DurationPanel extends JPanel {
 		gbc_lblName.gridy = 0;
 		add(lblName, gbc_lblName);
 		
-		lblTime = new JLabel();
-		GridBagConstraints gbc_lblTime = new GridBagConstraints();
-		gbc_lblTime.gridx = 1;
-		gbc_lblTime.gridy = 0;
-		add(lblTime, gbc_lblTime);
+		txtTime = new JFormattedTextField(new DurationFormatter());
+		GridBagConstraints gbc_txtTime = new GridBagConstraints();
+		gbc_txtTime.gridx = 1;
+		gbc_txtTime.gridy = 0;
+		add(txtTime, gbc_txtTime);
 	}
 
 	public DurationPanel(String name, Duration duration) {
@@ -40,6 +46,10 @@ public class DurationPanel extends JPanel {
 	}
 
 	public void setModel(final Duration duration) {
-		lblTime.setText(duration.toString());
+		txtTime.setValue(duration);
+	}
+
+	public void setEditable(boolean b) {
+		txtTime.setEditable(b);
 	}
 }