/** * Note: xAxis and yAxis must be instances of NumberAxis. * * @param chart */ public ThresholdedChartWrapper(final XYChart<Number, Number> chart) { this.chart = chart; this.xAxis = (NumberAxis)chart.getXAxis(); this.yAxis = (NumberAxis)chart.getYAxis(); pane.getChildren().add(chart); chart.prefWidthProperty().bind(pane.widthProperty()); chart.prefHeightProperty().bind(pane.heightProperty()); thresholds.addListener(new ListChangeListener<ObservableNumberValue>() { @Override public void onChanged(ListChangeListener.Change<? extends ObservableNumberValue> c) { while (c.next()) { if (c.wasPermutated()) { continue; } else { for (ObservableNumberValue removedItem : c.getRemoved()) { pane.getChildren().remove(vLines.remove(removedItem)); } // pane.getChildren().removeAll(c.getRemoved()); // for (ObservableNumberValue addedItem : c.getAddedSubList()) { // addThreshold(addedItem.getValue().doubleValue()); // } } } } }); }
public void setColor(final ObservableNumberValue val, final Color color) { Line line = vLines.get(val); if (line == null) { logger.warn("No threshold line found for {}", val); return; } line.setStroke(color); }
protected void bindValues() { ObservableNumberValue count = countValue(); StringBinding countText = Bindings.createStringBinding(() -> formatTotalWords(count), count); StringBinding filenameText = Bindings.createStringBinding(() -> filename(file.get()), file); error.bind(Bindings.equal(count, 0)); countDescription.bind(Bindings.when(error).then(ERROR).otherwise(countText)); filename.bind(filenameText); }
@Test public void testObservableNumberValue(){ ObservableNumberValue actual = new SimpleFloatProperty(10f); assertThat(actual).hasValue(10f); assertThat(actual).hasSameValue(actual); }
@Test public void testObservableNumberValue(){ ObservableNumberValue actual = new SimpleIntegerProperty(10); assertThat(actual).hasValue(10); assertThat(actual).hasSameValue(actual); }
@Test public void testObservableNumberValue(){ ObservableNumberValue actual = new SimpleLongProperty(10l); assertThat(actual).hasValue(10l); assertThat(actual).hasSameValue(actual); }
@Test public void testObservableNumberValue(){ ObservableNumberValue actual = new SimpleDoubleProperty(10.2); assertThat(actual).hasValue(10.2); assertThat(actual).hasSameValue(actual); }
@Test public void should_pass_if_actual_has_given_value(){ ObservableNumberValue actual = new SimpleDoubleProperty(10.123); Number expected = 10.123; new ObservableValueAssertions<>(actual).hasValue(expected); }
@Test public void should_fail_if_expectedValue_is_null(){ try{ ObservableNumberValue actual = new SimpleDoubleProperty(10.123); new ObservableValueAssertions<>(actual).hasValue(null); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("expected value may not be null"); } }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ ObservableNumberValue actual = new SimpleDoubleProperty(10.123); new ObservableNumberValueAssertions(actual).hasValue(10.12, offset(0.001)); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("less than <0.001> but difference was <0.0030"); } }
@Test public void should_fail_if_offset_is_null(){ try{ ObservableNumberValue actual = new SimpleDoubleProperty(10.123); new ObservableNumberValueAssertions(actual).hasValue(10.123, null); fail("Should throw an AssertionError"); }catch(NullPointerException error){ assertThat(error).hasMessageContaining("offset may not be null"); } }
public ObservableList<ObservableNumberValue> getThresholds() { return thresholds; }
public ObservableNumberValue addThreshold(final double x) { return addThreshold(x, null); }
public ObservableNumberValue addThreshold(final double x, final Color color) { return addThreshold(new SimpleDoubleProperty(x), color); }
public static DoubleBinding divideIntToDouble(ObservableNumberValue divisor, ObservableNumberValue divider) { return new DivideIntToDoubleBinding(divisor, divider); }
private SqrtBinding(ObservableNumberValue value) { super.bind(value); this.value = value; }
private Pow2Binding(ObservableNumberValue value) { super.bind(value); this.value = value; }
private DivideIntToDoubleBinding(ObservableNumberValue divisor, ObservableNumberValue divider) { super.bind(divisor, divider); this.divisor = divisor; this.divider = divider; }
private void bindValueLabel(final Label valueLabel, final ObservableNumberValue property) { StringBinding binding = Bindings.createStringBinding(() -> formatWords(property), property); valueLabel.textProperty().bind(binding); }
private String formatWords(final ObservableNumberValue property) { return MessageFormat.format("{0} {0,choice,0#Words|1#Word|1<Words}", property.intValue()); }
private void bindPercentLabel(final Label valueLabel, final ObservableNumberValue property) { valueLabel.textProperty().bind(Bindings.format("%.0f%%", property)); }
private String formatTotalWords(final ObservableNumberValue count) { return NumberFormat.getIntegerInstance(CoreConstants.LOCALE).format(count.getValue()); }
@Override protected ObservableNumberValue countValue() { return Bindings.when(includeUnknown).then(seenCount).otherwise(knownCount); }
protected ObservableNumberValueAssert(ObservableNumberValue actual) { super(actual, ObservableNumberValueAssert.class); }
public ObservableNumberValueAssertions(ObservableNumberValue actual) { super(actual, ObservableNumberValueAssertions.class); }
@Test public void testNumberBinding(){ IntegerProperty valueA = new SimpleIntegerProperty(10); IntegerProperty valueB = new SimpleIntegerProperty(20); final NumberBinding binding = valueA.add(valueB); assertThat(binding).hasValue(30); assertThat(binding).dependsOn(valueA); ObservableNumberValue expectedValueObservable = new SimpleIntegerProperty(30); assertThat(binding).hasSameValue(expectedValueObservable); }
@Test public void should_pass_if_actual_has_given_value_with_offset(){ ObservableNumberValue actual = new SimpleDoubleProperty(18509.64945984806); new ObservableNumberValueAssertions(actual).hasValue(18509.6494, offset(0.001)); }
public static DoubleBinding sqrt(ObservableNumberValue value) { return new SqrtBinding(value); }
public static DoubleBinding pow2(ObservableNumberValue value) { return new Pow2Binding(value); }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public ObservableNumberValueAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public IntegerBindingAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public DoublePropertyAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public NumberBindingAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public LongBindingAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public ReadOnlyDoublePropertyAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public DoubleBindingAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public FloatBindingAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public ReadOnlyIntegerPropertyAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public IntegerPropertyAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }
/** * Verifies that the actual observable has the same value as the given observable. * * @param expectedValue the observable value to compare with the actual observables current value. * * @return {@code this} assertion instance. */ public FloatPropertyAssert hasSameValue(ObservableNumberValue expectedValue) { new ObservableValueAssertions<>(actual).hasSameValue(expectedValue); return this; }