Bläddra i källkod

Add an up to parameter to rests that allows us to specify a wait that shouldn't be counted in the total recipe time.

Sam Jaffe 5 år sedan
förälder
incheckning
20d9a121cc

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

@@ -26,4 +26,5 @@ public class Rest extends Observable.Instance {
 	
 	Where where = Where.NONE;
 	Duration duration = Duration.ZERO;
+	Duration upTo = Duration.ZERO;
 }

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

@@ -22,6 +22,7 @@ import java.awt.Insets;
 @FieldDefaults(level=AccessLevel.PRIVATE)
 public class RestPanel extends JPanel {
 	ObservableListener<JFormattedTextField, Rest> durationController;
+	ObservableListener<JFormattedTextField, Rest> upToController;
 
 	JComboBox<Rest.Where> jcbLocation;
 	
@@ -30,9 +31,9 @@ public class RestPanel extends JPanel {
 
 	public RestPanel() {
 		GridBagLayout gridBagLayout = new GridBagLayout();
-		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
+		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
-		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
+		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
@@ -55,13 +56,21 @@ public class RestPanel extends JPanel {
 		gbc_panelDuration.gridx = 2;
 		gbc_panelDuration.gridy = 0;
 		add(panelDuration, gbc_panelDuration);
-		
+
+		DurationPanel panelUpTo = new DurationPanel("and up to");
+		GridBagConstraints gbc_panelUpTo = new GridBagConstraints();
+		gbc_panelUpTo.gridx = 3;
+		gbc_panelUpTo.gridy = 0;
+		add(panelUpTo, gbc_panelUpTo);
+
 		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);
+		upToController = ObservableController.from(panelUpTo.txtTime,
+				Rest::getUpTo, Rest::setUpTo);
 		
 		panelDuration.txtTime.setEditable(false);
 	}
@@ -75,6 +84,7 @@ public class RestPanel extends JPanel {
 		this.model = rest;
 		jcbLocation.setSelectedItem(rest.getWhere());
 		durationController.setObserved(rest);
+		upToController.setObserved(rest);
 	}
 	
 	@Override

+ 12 - 0
src/test/java/org/leumasjaffe/recipe/model/PhaseTest.java

@@ -66,6 +66,18 @@ class PhaseTest {
 		assertEquals(new Duration("25 s"), phase.getCollatedDuration().totalTime);
 	}
 	
+	@Test
+	void testCollatedDurationIgnoresRestUpToDuration() {
+		final Phase phase = new Phase();
+		phase.getRest().setWhere(Rest.Where.REFRIGERATOR);
+		phase.getRest().setUpTo(new Duration("15 s"));
+		final Step step = new Step();
+		step.setDuration(new Duration("10 s"));
+		phase.getCooking().add(step);
+
+		assertEquals(new Duration("10 s"), phase.getCollatedDuration().totalTime);
+	}
+	
 	@Test
 	void testSumsTogetherStepDurations() {
 		final Phase phase = new Phase();

+ 1 - 1
src/test/java/org/leumasjaffe/recipe/view/PhasePanelTest.java

@@ -25,7 +25,7 @@ class PhasePanelTest extends SwingTestCase {
 	
 	final Preparation prep = new Preparation();
 	final Step stub = new Step();
-	final Rest rest = new Rest(Rest.Where.REFRIGERATOR, new Duration("10 s"));
+	final Rest rest = new Rest(Rest.Where.REFRIGERATOR, new Duration("10 s"), Duration.ZERO);
 	
 	@Mock Phase stuff;
 	PhasePanel panel;

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

@@ -30,7 +30,7 @@ class RestPanelTest extends SwingTestCase {
 	
 	@BeforeEach
 	void setUp() {
-		stuff = new Rest(Rest.Where.REFRIGERATOR, new Duration(Duration.Display.SECONDS, 0, 30));
+		stuff = new Rest(Rest.Where.REFRIGERATOR, new Duration("30 s"), Duration.ZERO);
 		panel.setModel(stuff);
 		
 		listener.setObserved(stuff);