소스 검색

Use a JCombobox for rest updates.

Sam Jaffe 5 년 전
부모
커밋
e6de2b27ba
2개의 변경된 파일18개의 추가작업 그리고 7개의 파일을 삭제
  1. 15 4
      src/main/lombok/org/leumasjaffe/recipe/view/RestPanel.java
  2. 3 3
      src/test/java/org/leumasjaffe/recipe/view/RestPanelTest.java

+ 15 - 4
src/main/lombok/org/leumasjaffe/recipe/view/RestPanel.java

@@ -12,6 +12,7 @@ import lombok.experimental.FieldDefaults;
 
 import java.awt.GridBagLayout;
 
+import javax.swing.JComboBox;
 import javax.swing.JFormattedTextField;
 import javax.swing.JLabel;
 import java.awt.GridBagConstraints;
@@ -22,7 +23,10 @@ import java.awt.Insets;
 public class RestPanel extends JPanel {
 	ObservableListener<JFormattedTextField, Rest> durationController;
 
-	JLabel lblLocation;
+	JComboBox<Rest.Where> jcbLocation;
+	
+	// TODO
+	Rest model;
 
 	public RestPanel() {
 		GridBagLayout gridBagLayout = new GridBagLayout();
@@ -39,12 +43,12 @@ public class RestPanel extends JPanel {
 		gbc_lblRest.gridy = 0;
 		add(lblRest, gbc_lblRest);
 		
-		lblLocation = new JLabel();
+		jcbLocation = new JComboBox<>(Rest.Where.values());
 		GridBagConstraints gbc_lblLocation = new GridBagConstraints();
 		gbc_lblLocation.insets = new Insets(0, 0, 0, 5);
 		gbc_lblLocation.gridx = 1;
 		gbc_lblLocation.gridy = 0;
-		add(lblLocation, gbc_lblLocation);
+		add(jcbLocation, gbc_lblLocation);
 		
 		DurationPanel panelDuration = new DurationPanel("");
 		GridBagConstraints gbc_panelDuration = new GridBagConstraints();
@@ -52,8 +56,14 @@ public class RestPanel extends JPanel {
 		gbc_panelDuration.gridy = 0;
 		add(panelDuration, gbc_panelDuration);
 		
+		jcbLocation.addItemListener(e -> {
+			panelDuration.txtTime.setEditable(!e.getItem().equals(Rest.Where.NONE));
+			this.model.setWhere(Rest.Where.class.cast(e.getItem()));
+		});
 		durationController = ObservableController.from(panelDuration.txtTime,
 				Rest::getDuration, Rest::setDuration);
+		
+		panelDuration.txtTime.setEditable(false);
 	}
 
 	public RestPanel(final Rest rest) {
@@ -62,7 +72,8 @@ public class RestPanel extends JPanel {
 	}
 	
 	public void setModel(final Rest rest) {
-		lblLocation.setText(rest.getWhere().getHumanReadable());
+		this.model = rest;
+		jcbLocation.setSelectedItem(rest.getWhere());
 		durationController.setObserved(rest);
 	}
 	

+ 3 - 3
src/test/java/org/leumasjaffe/recipe/view/RestPanelTest.java

@@ -2,8 +2,8 @@ package org.leumasjaffe.recipe.view;
 
 import static org.mockito.Mockito.*;
 
+import javax.swing.JComboBox;
 import javax.swing.JFormattedTextField;
-import javax.swing.JLabel;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -24,7 +24,7 @@ class RestPanelTest extends SwingTestCase {
 	
 	Rest stuff;
 	
-	@Spy JLabel lblLocation;
+	@Spy JComboBox<Rest.Where> jcbLocation;
 	@Mock ObservableListener<JFormattedTextField, Rest> durationController;
 	@InjectMocks RestPanel panel = new RestPanel();
 	
@@ -39,7 +39,7 @@ class RestPanelTest extends SwingTestCase {
 
 	@Test
 	void testHasContent() {
-		verify(lblLocation).setText(eq(stuff.getWhere().getHumanReadable()));
+		verify(jcbLocation).setSelectedItem(eq(stuff.getWhere()));
 	}
 
 	@Test