public PointingHeroIcon(ObservableEntity oe) { super(oe); shape = new Polygon( 0, -200, -120, 200, 120, 200 ); shape.fillProperty().bind(getPlayerColor()); ObjectBinding<Vector> angRotVector = oe.getPropertyBinding(Vector.class, "CBodyComponent.m_angRotation", null); DoubleBinding angRot = Bindings.createDoubleBinding(() -> (double) angRotVector.get().getElement(1), angRotVector); IntegerBinding angDiff = Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "m_anglediff", 0)); shape.translateXProperty().bind(getMapX()); shape.translateYProperty().bind(getMapY()); shape.rotateProperty().bind(getBaseAngle().add(angRot).add(angDiff)); }
@Test public void testDivideSafeIntegerWithDefaultValue(){ IntegerProperty a = new SimpleIntegerProperty(); IntegerProperty b = new SimpleIntegerProperty(); IntegerProperty defaultValue = new SimpleIntegerProperty(10); final IntegerBinding quotient = NumberBindings.divideSafe(a, b, defaultValue); assertThat(quotient).hasSameValue(defaultValue); a.set(10); assertThat(quotient).hasSameValue(defaultValue); b.set(5); assertThat(quotient).hasValue(2); a.set(12); assertThat(quotient).hasValue(2); b.set(0); assertThat(quotient).hasSameValue(defaultValue); }
private IntegerBinding convertXModelCoordinateToXPixelCoordinate(ObservableDoubleValue xModel) { return new IntegerBinding() { { this.bind(xModel,oneUnitInModelEqualsHowManyPixels,pixelOffsetToSimulateNegativeXCoordinate); } @Override protected int computeValue() { int newValue = (int) Math.round(xModel.get() * oneUnitInModelEqualsHowManyPixels.get() + pixelOffsetToSimulateNegativeXCoordinate.doubleValue()); assert newValue >= 0; //new value must always be positive! return newValue; } }; }
private IntegerBinding convertYModelCoordinateToYPixelCoordinate(ObservableDoubleValue yModel) { return new IntegerBinding() { { this.bind(yModel,oneUnitInModelEqualsHowManyPixels,pixelOffsetToSimulateNegativeYCoordinate); } @Override protected int computeValue() { int newValue = (int) Math.round(yModel.get() * oneUnitInModelEqualsHowManyPixels.get() + pixelOffsetToSimulateNegativeYCoordinate.doubleValue()); assert newValue >= 0; //new value must always be positive! return newValue; } }; }
@Test public void test() { IntegerProperty src = new SimpleIntegerProperty(0); IntegerBinding twice = src.multiply(2); Var<Number> twiceVar = Var.fromVal(twice, n -> src.set(n.intValue() / 2)); List<Number> values = new ArrayList<>(); EventStreams.valuesOf(twiceVar).subscribe(values::add); src.set(1); twiceVar.setValue(4); twiceVar.setValue(5); // no effect twiceVar.setValue(7); // will become 6 assertEquals(Arrays.asList(0, 2, 4, 6), values); }
public static IntegerBinding toIntegerBinding(ObservableValue<? extends Number> ov) { return new IntegerBinding() { { bind(ov); } @Override protected int computeValue() { return ov.getValue() == null ? 0 : ov.getValue().intValue(); } }; }
protected ObjectBinding<Paint> getTeamColor() { IntegerBinding teamNum = getTeamNum(); return Bindings.createObjectBinding(() -> { int n = teamNum.get(); switch (n) { case 2: return Color.GREEN; case 3: return Color.RED; default: return Color.GRAY; } }, teamNum); }
protected ObjectBinding<Paint> getPlayerColor() { IntegerBinding playerId = getPlayerId(); return Bindings.createObjectBinding(() -> { int n = playerId.get(); if (n < 0 || n > 9) { return Color.WHITE; } else { return PLAYER_COLORS[n]; } }, playerId); }
public IntegerBinding failedRunsCountProperty() { return Bindings.createIntegerBinding(new Callable<Integer>() { @Override public Integer call() throws Exception { int result = 0; for (TestRunModel testRunModel : getTestRuns()) { if (testRunModel.getRun().isFailedRun()) result++; } return result; } }, testRunsProperty()); }
private Pane setupStatesPane() { final Label titleLabel = new Label("All execution states (0)"); nbStates.addListener((v, o, n) -> { String s = "All execution states (" + n.intValue() + ")"; Platform.runLater(() -> { titleLabel.setText(s); titleLabel.setContentDisplay(ContentDisplay.RIGHT); final ImageView nodeGraphic = new ImageView(); nodeGraphic.setImage(playGraphic); titleLabel.setGraphic(nodeGraphic); isInReplayMode.addListener((val, old, neu) -> { if (old != neu) { if (neu) { nodeGraphic.setImage(replayGraphic); } else { nodeGraphic.setImage(playGraphic); } } }); }); }); titleLabel.setFont(statesFont); VBox.setMargin(titleLabel, HALF_MARGIN_INSETS); titleLabel.setAlignment(Pos.CENTER); final ScrollBar scrollBar = new ScrollBar(); scrollBar.setVisibleAmount(1); scrollBar.setBlockIncrement(10); scrollBar.setMin(0); final IntegerBinding statesRange = visibleStatesRange.subtract(1); scrollBar.disableProperty().bind(statesRange.lessThanOrEqualTo(0)); scrollBar.maxProperty().bind(statesRange); scrollBar.valueProperty().addListener((v, o, n) -> { if (o.intValue() != n.intValue() && n.intValue() != currentState.intValue()) { currentState.set(n.intValue()); } }); currentState.addListener((v, o, n) -> { if (o.intValue() != n.intValue() && n.intValue() != scrollBar.valueProperty().intValue()) { scrollBar.setValue(n.intValue()); } }); final HBox hBox = new HBox(); final Polygon arrow = new Polygon(2.5, 10, 10, 5, 2.5, 0); HBox.setMargin(arrow, HALF_MARGIN_INSETS); final Label toggleValuesLabel = new Label("Timeline for dynamic information "); toggleValuesLabel.setFont(statesFont); hBox.setAlignment(Pos.CENTER_LEFT); hBox.getChildren().addAll(arrow, toggleValuesLabel); hBox.setCursor(Cursor.HAND); hBox.setOnMouseClicked((e) -> { if (bodyScrollPane.isVisible()) { bodyScrollPane.setVisible(false); arrow.setRotate(0); } else { bodyScrollPane.setVisible(true); arrow.setRotate(90); } }); VBox.setMargin(hBox, HALF_MARGIN_INSETS); headerPane.getChildren().addAll(scrollBar, titleLabel, statesPane, hBox); VBox.setMargin(statesPane, MARGIN_INSETS); return headerPane; }
public void CalculateNewIndicatorCanvasHeight(){ //This binding will make sure the main chart height is always roughly twice as indicator's height IntegerBinding size = (IntegerBinding) Bindings.size(chartPaneList).add(new SimpleIntegerProperty(2)); NumberBinding sub = Bindings.divide(chartAreaHeight, size); indicatorCanvasHeightProperty.setValue(sub.getValue()); }
public IntegerBinding selectInteger(Function<S, ? extends ObservableIntegerValue> childPropertyAccessor) { return selectInteger(childPropertyAccessor, 0); }
public IntegerBinding selectInteger(Function<S, ? extends ObservableIntegerValue> childPropertyAccessor, int defaultValue) { return new IntegerBindingAdapter(new ChainBinding<>(rootProperty, childPropertyAccessor), defaultValue); }
public IntegerBinding mapToInteger(Function<S, Integer> childValueAccessor) { return mapToInteger(childValueAccessor, 0); }
public IntegerBinding mapToInteger(Function<S, Integer> childValueAccessor, Integer defaultValue) { return new IntegerBindingAdapter(mapToObject(childValueAccessor), defaultValue); }
protected IntegerBinding getCellX() { return Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "CBodyComponent.m_cellX", 0)); }
protected IntegerBinding getCellY() { return Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "CBodyComponent.m_cellY", 0)); }
protected IntegerBinding getPlayerId() { return Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "m_iPlayerID", -1)); }
protected IntegerBinding getTeamNum() { return Bindings.selectInteger(oe.getPropertyBinding(Integer.class, "m_iTeamNum", 0)); }
protected IntegerBinding defaultPortProperty(DbmsHandlerComponent dbmsHandlerComponent) { return Bindings.createIntegerBinding(() -> DatabaseUtil.findDbmsType(dbmsHandlerComponent, this).getDefaultPort(), typeNameProperty() ); }
private IntegerBinding defaultPortProperty(T document, DbmsHandlerComponent dbmsHandlerComponent) { return Bindings.createIntegerBinding(() -> DatabaseUtil.findDbmsType(dbmsHandlerComponent, document).getDefaultPort(), document.typeNameProperty() ); }
protected IntegerBindingAssert(IntegerBinding actual) { super(actual, IntegerBindingAssert.class); }
@Test public void testDivideSafeInteger(){ IntegerProperty a = new SimpleIntegerProperty(); IntegerProperty b = new SimpleIntegerProperty(); final IntegerBinding quotient = NumberBindings.divideSafe(a, b); assertThat(quotient).hasValue(0); a.set(10); assertThat(quotient).hasValue(0); b.set(5); assertThat(quotient).hasValue(2); a.set(12); assertThat(quotient).hasValue(2); b.set(0); assertThat(quotient).hasValue(0); }
@Override public void initialize(final URL location, final ResourceBundle resources) { labels = resources; try { outputFile.getChild().textProperty().bindBidirectional(bufferedOutput); outputFile.bindValidation(bufferedOutput); delete.disableProperty().bind(sourceConfigurations.expandedPaneProperty() .isNull() .or(Bindings.size(sourceConfigurations.getPanes()).lessThan(2))); final IntegerBinding indexOfExpendedPane = new IntegerBinding() { { bind(sourceConfigurations.expandedPaneProperty()); } @Override public void dispose() { super.unbind(sourceConfigurations.expandedPaneProperty()); } @Override protected int computeValue() { return sourceConfigurations.getPanes().indexOf(sourceConfigurations.getExpandedPane()); } @Override public ObservableList<?> getDependencies() { return FXCollections.singletonObservableList(sourceConfigurations.expandedPaneProperty()); } }; upSource.disableProperty() .bind(sourceConfigurations.expandedPaneProperty().isNull().or(indexOfExpendedPane.lessThan(1))); downSource.disableProperty().bind(sourceConfigurations.expandedPaneProperty().isNull().or( indexOfExpendedPane.greaterThan(Bindings.size(sourceConfigurations.getPanes()).subtract(2)))); save.disableProperty().bind(Bindings.not(bufferingManager.validProperty())); cancel.disableProperty().bind(Bindings.not(bufferingManager.bufferingProperty())); run.disableProperty() .bind(bufferingManager.bufferingProperty().or(Bindings.not(bufferingManager.validProperty()))); } catch (final Exception e) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "", e); } }
public ControlsViewModel(TodoItemStore store) { final ObservableList<TodoItem> items = store.getItems(); ObservableList<TodoItem> completedItems = FilterHelper.filterInverted(items, TodoItem::completedProperty); final IntegerBinding size = Bindings.size(completedItems); final StringBinding itemsLabel = Bindings.when(size.isEqualTo(1)).then("item").otherwise("items"); itemsLeftLabelText.bind(Bindings.concat(size, " ", itemsLabel, " left")); }
@Test public void testIntegerBinding(){ IntegerProperty value = new SimpleIntegerProperty(10); final IntegerBinding actual = value.add(20); assertThat(actual).hasValue(30); assertThat(actual).hasSameValue(actual); }
/** * 建立包裝目前觀察值為整數型態的繫節。 * * @param thiz 來源觀察值 * @param mapper 轉換目前觀察值為整數型態的函數 * @return 整數型態的繫節(依賴目前的觀察物件) */ default IntegerBinding asInteger(Function<? super T, ? extends Integer> mapper) { ObservableValue<T> thiz = (ObservableValue<T>) this; return Bindings.createIntegerBinding(() -> mapper.apply(thiz.getValue()), thiz); }
/** * Binding for {@link java.lang.Math#abs(int)} * * @param a the argument whose absolute value is to be determined * @return the absolute value of the argument. */ public static IntegerBinding abs(final ObservableIntegerValue a) { return createIntegerBinding(() -> Math.abs(a.get()), a); }
/** * Binding for {@link java.lang.Math#addExact(int, int)} * * @param x the first value * @param y the second value * @return the result * @throws ArithmeticException if the result overflows an int */ public static IntegerBinding addExact(final ObservableIntegerValue x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.addExact(x.get(), y.get()), x, y); }
/** * Binding for {@link java.lang.Math#addExact(int, int)} * * @param x the first value * @param y the second value * @return the result * @throws ArithmeticException if the result overflows an int */ public static IntegerBinding addExact(final int x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.addExact(x, y.get()), y); }
/** * Binding for {@link java.lang.Math#addExact(int, int)} * * @param x the first value * @param y the second value * @return the result * @throws ArithmeticException if the result overflows an int */ public static IntegerBinding addExact(final ObservableIntegerValue x, final int y) { return createIntegerBinding(() -> Math.addExact(x.get(), y), x); }
/** * Binding for {@link java.lang.Math#decrementExact(int)} * * @param a the value to decrement * @return the result * @throws ArithmeticException if the result overflows an int */ public static IntegerBinding decrementExact(final ObservableIntegerValue a) { return createIntegerBinding(() -> Math.decrementExact(a.get()), a); }
/** * Binding for {@link java.lang.Math#floorDiv(int, int)} * * @param x the dividend * @param y the divisor * @return the largest (closest to positive infinity) * {@code int} value that is less than or equal to the algebraic quotient. * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorDiv(final ObservableIntegerValue x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.floorDiv(x.get(), y.get()), x, y); }
/** * Binding for {@link java.lang.Math#floorDiv(int, int)} * * @param x the dividend * @param y the divisor * @return the largest (closest to positive infinity) * {@code int} value that is less than or equal to the algebraic quotient. * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorDiv(final int x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.floorDiv(x, y.get()), y); }
/** * Binding for {@link java.lang.Math#floorDiv(int, int)} * * @param x the dividend * @param y the divisor * @return the largest (closest to positive infinity) * {@code int} value that is less than or equal to the algebraic quotient. * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorDiv(final ObservableIntegerValue x, final int y) { return createIntegerBinding(() -> Math.floorDiv(x.get(), y), x); }
/** * Binding for {@link java.lang.Math#floorMod(int, int)} * * @param x the dividend * @param y the divisor * @return the floor modulus {@code x - (floorDiv(x, y) * y)} * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorMod(final ObservableIntegerValue x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.floorMod(x.get(), y.get()), x, y); }
/** * Binding for {@link java.lang.Math#floorMod(int, int)} * * @param x the dividend * @param y the divisor * @return the floor modulus {@code x - (floorDiv(x, y) * y)} * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorMod(final int x, final ObservableIntegerValue y) { return createIntegerBinding(() -> Math.floorMod(x, y.get()), y); }
/** * Binding for {@link java.lang.Math#floorMod(int, int)} * * @param x the dividend * @param y the divisor * @return the floor modulus {@code x - (floorDiv(x, y) * y)} * @throws ArithmeticException if the divisor {@code y} is zero */ public static IntegerBinding floorMod(final ObservableIntegerValue x, final int y) { return createIntegerBinding(() -> Math.floorMod(x.get(), y), x); }