Search in sources :

Example 1 with DayPhase

use of org.vesalainen.navi.SolarWatch.DayPhase 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

StringBinding (javafx.beans.binding.StringBinding)1 When (javafx.beans.binding.When)1 DayPhase (org.vesalainen.navi.SolarWatch.DayPhase)1