private void initProgressBinding() { DoubleExpression tmp = constantOf(0); for (Command command : registeredCommands) { final ReadOnlyDoubleProperty progressProperty = command.progressProperty(); /** * When the progress of a command is "undefined", the progress property has a value of -1. * But in our use case we like to have a value of 0 in this case. * Therefore we create a custom binding here. */ final DoubleBinding normalizedProgress = Bindings .createDoubleBinding(() -> (progressProperty.get() == -1) ? 0.0 : progressProperty.get(), progressProperty); tmp = tmp.add(normalizedProgress); } int divisor = registeredCommands.isEmpty() ? 1 : registeredCommands.size(); progress.bind(Bindings.divide(tmp, divisor)); }
private void bindCoords() { final DoubleExpression radius = model.sizeProperty().multiply(0.5); final Translate translation = new Translate(); translation.xProperty().bind(transformRadius); final Rotate rotation = new Rotate(); rotation.pivotXProperty().bind(transformRadius.subtract(radius).multiply(-1)); rotation.pivotYProperty().bind(radius); rotation.angleProperty().bind(transformAngle); button.getTransforms().addAll(translation, rotation); final Rotate twist = new Rotate(); twist.pivotXProperty().bind(radius); twist.pivotYProperty().bind(radius); twist.angleProperty().bind(transformAngle.multiply(-1.0d)); button.getTransforms().add(twist); model.visibleProperty().addListener((observable) -> { updateVisibility(); }); }
public RadialItem addItem(MenuItem item) { final DoubleExpression idx = new SimpleDoubleProperty(items.size()); final NumberExpression itemRange = new When(params.directionProperty().isEqualTo(Direction.CW)) .then(idx.divide(itemsCount.subtract(1))) .otherwise(itemsCount.subtract(idx.add(1)).divide(itemsCount.subtract(1))); final DoubleExpression itemAngleDeg = correctedStreakAngleDeg.add(angularTotalSizeDeg.multiply(itemRange)).subtract(angularTotalSizeDeg.multiply(0.5)); final RadialItem itemButton = new RadialItem(params, item.getGraphic(), item.getText(), this, itemAngleDeg, (parentSection != null) ? parentSection.nominalRadius : new SimpleDoubleProperty(0), (item instanceof Menu)); items.add(itemButton); radialPane.getChildren().add(itemButton); return itemButton; }
@Override public void changed(ObservableValue<? extends Number> sourceProperty, Number oldValue, Number newValue) { if (!updating) { final DoubleProperty property1 = propertyRef1.get(); final DoubleExpression property2 = propertyRef2.get(); if ((property1 == null) || (property2 == null)) { if (property2 != null) { property2.removeListener(this); } } else { try { updating = true; property1.setValue(property2.getValue()); } catch (RuntimeException e) { property1.setValue(oldValue.doubleValue()); throw new RuntimeException( "TransparentBinding binding failed, setting to the previous value", e); } finally { updating = false; } } } }
public MenuItem createZoomMenus() { Integer zoomValue = getDefaultZoom(); R.mainStyle.fontSizeProperty().bind(DoubleExpression.doubleExpression(zoomSpinner.valueProperty()).multiply(0.13d)); zoomSpinner.getValueFactory().setValue(zoomValue.doubleValue()); Label l = new Label("Zoom", zoomSpinner); l.setContentDisplay(ContentDisplay.RIGHT); return new CustomMenuItem(l, false); }
public ObservableBounds(DoubleExpression minX, DoubleExpression minY, DoubleExpression maxX, DoubleExpression maxY) { this(); requireNonNull(minX, "Parameter 'minX' is null"); requireNonNull(minY, "Parameter 'minY' is null"); requireNonNull(maxX, "Parameter 'maxX' is null"); requireNonNull(maxY, "Parameter 'maxY' is null"); this.minX.bind(minX); this.minY.bind(minY); this.maxX.bind(maxX); this.maxY.bind(maxY); }
public ObservableBounds(DoubleExpression minX, DoubleExpression minY, DoubleExpression minZ, DoubleExpression maxX, DoubleExpression maxY, DoubleExpression maxZ) { this(minX, minY, maxX, maxY); requireNonNull(minZ, "Parameter 'minZ' is null"); requireNonNull(maxZ, "Parameter 'maxZ' is null"); this.minZ.bind(minZ); this.maxZ.bind(maxZ); }
private void regenerateMenu(Menu menu, Node parentNode, RadialMenuSectionDynamic parentSection) { final Optional<RadialItem> oParentItem = ((parentNode != null) && (parentSection != null)) ? parentSection.getItems().stream().filter(radialItem -> radialItem.getNode().equals(parentNode)).findFirst() : Optional.empty(); final DoubleExpression streakAngle = oParentItem.isPresent() ? oParentItem.get().angleProperty() : null; final RadialMenuSectionDynamic menuSection = new RadialMenuSectionDynamic(params, radialPane, parentSection, streakAngle); if (params.getTopSection() == null) params.setTopSection(menuSection); menu.getItems().forEach((item) -> { final RadialItem itemButton = menuSection.addItem(item); if (item instanceof Menu) { final Menu subMenu = (Menu) item; createTrigger(itemButton, subMenu, menuSection); regenerateMenu(subMenu, itemButton, menuSection); } else { createAction(itemButton, item); } }); sections.put(menu, menuSection); }
@Test public void testDoubleExpression(){ final DoubleExpression actual = DoubleExpression.doubleExpression(new SimpleDoubleProperty(12.2)); assertThat(actual).hasValue(12.2); assertThat(actual).hasSameValue(actual); }
public static TransparentBinding bind(DoubleProperty property1, DoubleExpression property2) { checkParameters(property1, property2); final TransparentBinding binding = new TransparentBinding(property1, property2); property1.setValue(property2.getValue()); property2.addListener(binding); return binding; }
private BidirectionalDifferenceBinding(DoubleProperty property1, DoubleProperty property2, DoubleExpression difference) { cachedHashCode = property1.hashCode() * property2.hashCode() * difference.hashCode(); propertyRef1 = new WeakReference<DoubleProperty>(property1); propertyRef2 = new WeakReference<DoubleProperty>(property2); differenceRef = new WeakReference<DoubleExpression>(difference); }
public static BidirectionalDifferenceBinding bind(DoubleProperty property1, DoubleProperty property2, DoubleExpression difference) { checkParameters(property1, property2, difference); final BidirectionalDifferenceBinding binding = new BidirectionalDifferenceBinding( property1, property2, difference); property2.setValue(property1.getValue() - difference.getValue()); property1.addListener(binding); property2.addListener(binding); difference.addListener(binding); return binding; }
public ObservablePoint2D(DoubleExpression x, DoubleExpression y) { LOGGER.trace("ObservablePoint2D(x={}, y={})", x, y); this.x.bind(x); this.y.bind(y); }
public ObservableDimension2D(DoubleExpression width, DoubleExpression height) { LOGGER.trace("ObservableDimension2D(width={}, height={})", width, height); this.width.bind(width); this.height.bind(height); }
public RadialItem(Params params, Node graphics, String text, RadialMenuSectionDynamic parentPane, DoubleExpression angle, DoubleExpression fromRadius, boolean withCaret) { this.button = generateButton(params, graphics, text); this.angle.bind(angle); this.parentPane = parentPane; this.fromRadius = fromRadius; diameter.bind(button.prefHeightProperty()); transformOpacity.set(0); transformAngle.set(0); transformRadius.set(0); final DoubleBinding itemRadius = diameter.multiply(0.5); final Translate translation = new Translate(); translation.xProperty().bind(transformRadius); final Rotate rotation = new Rotate(); rotation.pivotXProperty().bind(transformRadius.subtract(itemRadius).multiply(-1)); rotation.pivotYProperty().bind(itemRadius); rotation.angleProperty().bind(transformAngle); final Rotate twist = new Rotate(); twist.pivotXProperty().bind(itemRadius); twist.pivotYProperty().bind(itemRadius); twist.angleProperty().bind(transformAngle.multiply(-1.0d)); setVisible(false); setMouseTransparent(true); getTransforms().addAll(translation, rotation); button.getTransforms().add(twist); opacityProperty().bind(transformOpacity); getChildren().add(button); if (withCaret) { this.caret = generateCaret(); final Translate caretTranslation = new Translate(); caretTranslation.xProperty().bind(diameter.add(params.buttonWidthOffsetProperty().multiply(0.5))); caret.getTransforms().add(caretTranslation); getChildren().add(caret); } else { caret = null; } //this.setBackground(new Background(new BackgroundFill(Color.YELLOWGREEN, null, null))); //this.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, BorderWidths.DEFAULT))); }
private void setupCircle(Circle c, DoubleExpression centerOffset, DoubleExpression radius) { c.radiusProperty().bind(radius); c.centerXProperty().bind(centerOffset); c.centerYProperty().bind(centerOffset); }
private void setupCircle(Circle c, DoubleExpression centerX, DoubleExpression centerY, double radius) { c.radiusProperty().set(radius); c.centerXProperty().bind(centerX); c.centerYProperty().bind(centerY); }
public RadialMenuSectionDynamic(Params params, RadialPane radialPane, RadialMenuSectionDynamic parentSection, DoubleExpression streakAngleDeg) { this.params = params; this.radialPane = radialPane; this.parentSection = parentSection; this.radialPane.addRadialSection(this); if (streakAngleDeg != null) { this.streakAngleDeg.bind(streakAngleDeg); } else { this.streakAngleDeg.bind(params.angleFromDegProperty() .add(params.angleToDegProperty().subtract(params.angleFromDegProperty()).multiply(0.5d))); } itemsCount = new SimpleListProperty<>(items).sizeProperty(); final DoubleExpression itemRadiusHalf = params.buttonSizeProperty().multiply(0.5); if (parentSection != null) { innerRadius.bind(parentSection.outerRadiusProperty().add(itemRadiusHalf.multiply(params.spacingFactorProperty().multiply(2)))); } else { innerRadius.bind(params.minRadiusProperty()); } final DoubleExpression angleDeg = params.angleToDegProperty().subtract(params.angleFromDegProperty()); final DoubleExpression angleRad = new FunctionDoubleBinding(Math::toRadians, angleDeg); final DoubleExpression availablePerimeter = angleRad.multiply(innerRadius.add(itemRadiusHalf)); final DoubleExpression gapSize = params.buttonSizeProperty().multiply(params.gapFactorProperty()); final DoubleExpression allItemsSize = params.buttonSizeProperty().multiply(itemsCount.subtract(1)); final DoubleExpression totalSize = allItemsSize.add(gapSize.multiply(itemsCount.subtract(1))); final NumberBinding candidateNominalRadius = new When(availablePerimeter.greaterThan(totalSize)) .then(innerRadius.add(itemRadiusHalf)) .otherwise(totalSize.divide(angleRad)); final DoubleExpression candidateAngularTotalSizeDeg = new FunctionDoubleBinding(Math::toDegrees, totalSize.divide(candidateNominalRadius)); final DoubleExpression candidateAngularItemSizeDeg = candidateAngularTotalSizeDeg.divide(itemsCount); final DoubleExpression angularTotalSizeWithOverlapDeg = candidateAngularTotalSizeDeg.add(candidateAngularItemSizeDeg); nominalRadius.bind(candidateNominalRadius.add(new When(angularTotalSizeWithOverlapDeg.greaterThan(TWO_PI)) .then(totalSize.divide(angularTotalSizeWithOverlapDeg.subtract(TWO_PI))) .otherwise(0))); angularTotalSizeDeg = new FunctionDoubleBinding(Math::toDegrees, totalSize.divide(nominalRadius)); // TODO: Make sure, that outerRadius is reasonably small to prevent "large texture" errors outerRadius.bind(nominalRadius.add(itemRadiusHalf.add(params.buttonWidthOffsetProperty()))); params.centerOffsetProperty().add(outerRadius); fromAngleDeg.bind(this.streakAngleDeg.subtract(angularTotalSizeDeg.multiply(0.5))); toAngleDeg.bind(this.streakAngleDeg.add(angularTotalSizeDeg.multiply(0.5))); correctedStreakAngleDeg.bind(this.streakAngleDeg.add(new When(fromAngleDeg.lessThan(params.angleFromDegProperty())) .then(params.angleFromDegProperty().subtract(fromAngleDeg)) .otherwise(new When(toAngleDeg.greaterThan(params.angleToDegProperty())) .then(params.angleToDegProperty().subtract(toAngleDeg)) .otherwise(0)))); toAngleDeg.bind(fromAngleDeg.add(angularTotalSizeDeg)); angularItemSizeDeg.bind(angularTotalSizeDeg.divide(itemsCount)); final Circle perimeter = setupPerimeter(params); radialPane.getChildren().add(perimeter); params.centerOffsetProperty().addListener(observable -> radialPane.layout()); totalSize.addListener((sender, oldV, newV) -> System.out.println(this + " [" + itemsCount.intValue() + "] totalSize: " + newV)); nominalRadius.addListener((sender, oldV, newV)-> System.out.println(this + " [" + itemsCount.intValue() + "] nominalRadius: " + newV)); angularTotalSizeDeg.addListener((sender, oldV, newV)-> System.out.println(this + " [" + itemsCount.intValue() + "] ang. size (deg): " + newV)); }
private TransparentBinding(DoubleProperty property1, DoubleExpression property2) { cachedHashCode = property1.hashCode() * property2.hashCode(); propertyRef1 = new WeakReference<DoubleProperty>(property1); propertyRef2 = new WeakReference<DoubleExpression>(property2); }
protected DoubleExpression getProperty2() { return propertyRef2.get(); }
protected DoubleExpression getDifference() { return differenceRef.get(); }
@Override public void changed(ObservableValue<? extends Number> sourceProperty, Number oldValue, Number newValue) { if (!updating) { final DoubleProperty property1 = propertyRef1.get(); final DoubleProperty property2 = propertyRef2.get(); final DoubleExpression difference = differenceRef.get(); if ((property1 == null) || (property2 == null) || (difference == null)) { if (property1 != null) { property1.removeListener(this); } if (property2 != null) { property2.removeListener(this); } if (difference != null) { difference.removeListener(this); } } else { try { updating = true; if (property2 == sourceProperty) { if (!property1.isBound()) { property1.set(newValue.doubleValue() - difference.doubleValue()); } else { System.out .println("Property 2 changed, Property 1 bound"); } } else if (property1 == sourceProperty) { if (!property2.isBound()) { property2.set(newValue.doubleValue() + difference.doubleValue()); } else { System.out .println("Property 1 changed, Property 2 bound"); } } else { if (!property2.isBound()) { property2.set(property1.doubleValue() + newValue.doubleValue()); } else if (!property1.isBound()) { property1.set(property2.doubleValue() - newValue.doubleValue()); } else { System.out .println("Difference Changed, Properties 1 & 2 bound"); } } } catch (RuntimeException e) { e.printStackTrace(); if (property2 == sourceProperty) { property2.set(oldValue.doubleValue()); System.out .println("Exception thrown, Property 2 reset"); } else if (property1 == sourceProperty) { property1.set(oldValue.doubleValue()); System.out .println("Exception thrown, Property 1 reset"); } throw new RuntimeException( "BidirectionalDifferenceBinding binding failed, setting to the previous value", e); } finally { updating = false; } } } }
@Override protected DoubleExpression generateLayoutYToStubYExpression() { return textLabel.heightProperty(); }
protected DoubleExpression generateLayoutYToStubYExpression() { return this.heightProperty().divide(2); }
public DoubleExpression layoutToStubYProperty() { if (layoutToStubY == null) { layoutToStubY = generateLayoutYToStubYExpression(); } return layoutToStubY; }
@Override protected DoubleExpression generateLayoutYToStubYExpression() { return PropertyMath.max(in.layoutToStubYProperty(),out.layoutToStubYProperty(),ruleNode.layoutToStubYProperty()).add(info.heightProperty()); }
@Override protected DoubleExpression generateLayoutYToStubYExpression() { return PropertyMath.max(in.layoutToStubYProperty(),out.layoutToStubYProperty(),ruleNode.layoutToStubYProperty()); }