ConfigurationContext extends GraphicalContext<BorderPane> { static Spinner<Double> buildSpinner( double min, double max, double initialValue, double step, Property<Number> configProperty ) { Spinner<Double> spinner = new Spinner<>(min, max, initialValue, step); spinner.setEditable(true); spinner.setPrefWidth(PREF_WIDTH); spinner.setPrefHeight(PREF_HEIGHT); spinner.valueProperty().addListener((observable, oldValue, newValue) -> { if (newValue >= min || newValue <= max) { final int newPropertyValue = (int) (1000 * spinner.getValue()); configProperty.setValue(newPropertyValue); } else if (newValue > max) { final int newPropertyValue = (int) (1000 * max); configProperty.setValue(newPropertyValue); } else if (newValue < min) { final int newPropertyValue = (int) (1000 * min); configProperty.setValue(newPropertyValue); } }); return spinner; } ConfigurationContext(GazePlay gazePlay); @Override ObservableList<Node> getChildren();  }
@Test void shouldBuildSpinner() { SimpleIntegerProperty length = new SimpleIntegerProperty(); Spinner<Double> result = ConfigurationContext.buildSpinner(0.3, 10, 0.5, 0.1, length); assertEquals(0.5, result.getValue()); result.increment(5); assertEquals(1, result.getValue()); assertEquals(1000, length.get()); }
@Test void shouldSetSpinnerValueToMaxIfHigher() { SimpleIntegerProperty length = new SimpleIntegerProperty(); Spinner<Double> result = ConfigurationContext.buildSpinner(0.3, 10, 0.5, 0.1, length); assertEquals(0.5, result.getValue()); result.getEditor().setText("11"); result.commitValue(); assertEquals(10, result.getValue()); assertEquals(10000, length.get()); }
@Test void shouldSetSpinnerValueToMinIfLower() { SimpleIntegerProperty length = new SimpleIntegerProperty(); Spinner<Double> result = ConfigurationContext.buildSpinner(0.3, 10, 0.5, 0.1, length); assertEquals(0.5, result.getValue()); result.getEditor().setText("0.2"); result.commitValue(); assertEquals(0.3, result.getValue()); assertEquals(300, length.get()); }