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");
}
}
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;
}
Aggregations