Search in sources :

Example 1 with When

use of javafx.beans.binding.When in project NMEAParser by tvesalainen.

the class ResizableCanvas method setParent.

private void setParent(ObservableValue<? extends Parent> observable, Parent oldValue, Parent newParent) {
    if (newParent instanceof Region) {
        Region region = (Region) newParent;
        ReadOnlyDoubleProperty regionWidth = region.widthProperty();
        ReadOnlyDoubleProperty regionHeight = region.heightProperty();
        if (square) {
            widthProperty().bind(new When(regionWidth.lessThanOrEqualTo(regionHeight)).then(regionWidth).otherwise(regionHeight));
            heightProperty().bind(new When(regionHeight.lessThanOrEqualTo(regionWidth)).then(regionHeight).otherwise(regionWidth));
        } else {
            widthProperty().bind(regionWidth);
            heightProperty().bind(regionHeight);
        }
    } else {
        System.err.println(newParent + " not suitable for ResizableCanvas");
    }
}
Also used : ReadOnlyDoubleProperty(javafx.beans.property.ReadOnlyDoubleProperty) When(javafx.beans.binding.When) Region(javafx.scene.layout.Region)

Example 2 with When

use of javafx.beans.binding.When in project NMEAParser by tvesalainen.

the class ViewerService method bindBackgroundColors.

public StringBinding bindBackgroundColors() {
    ObjectBinding<DayPhase> autoPhaseProperty = propertyStore.dayPhaseProperty();
    Binding<DayPhase> forcedPhaseProperty = preferences.getBinding("dayPhase");
    Binding<Boolean> solarAutomation = preferences.getBinding("solarAutomation");
    Binding<DayPhase> dayPhaseProperty = new When((ObservableBooleanValue) solarAutomation).then(autoPhaseProperty).otherwise((ObservableObjectValue) forcedPhaseProperty);
    StringBinding colorBinding = Bindings.createStringBinding(() -> {
        switch(dayPhaseProperty.getValue()) {
            case DAY:
                return colorToString(dayBackgroundColorBinding.getValue());
            case NIGHT:
                return colorToString(nightBackgroundColorBinding.getValue());
            case TWILIGHT:
                return colorToString(twilightBackgroundColorBinding.getValue());
            default:
                throw new UnsupportedOperationException(autoPhaseProperty.getValue() + " not supported");
        }
    }, solarAutomation, autoPhaseProperty, forcedPhaseProperty, dayBackgroundColorBinding, nightBackgroundColorBinding, twilightBackgroundColorBinding);
    return colorBinding;
}
Also used : DayPhase(org.vesalainen.navi.SolarWatch.DayPhase) When(javafx.beans.binding.When) StringBinding(javafx.beans.binding.StringBinding)

Aggregations

When (javafx.beans.binding.When)2 StringBinding (javafx.beans.binding.StringBinding)1 ReadOnlyDoubleProperty (javafx.beans.property.ReadOnlyDoubleProperty)1 Region (javafx.scene.layout.Region)1 DayPhase (org.vesalainen.navi.SolarWatch.DayPhase)1