org.reactfx.inhibeans.binding.DoubleBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reactfx Show documentation
Show all versions of reactfx Show documentation
Reactive event streams for JavaFX
package org.reactfx.inhibeans.binding;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import org.reactfx.Guard;
import org.reactfx.value.Val;
import com.sun.javafx.binding.ExpressionHelper;
/**
* Inhibitory version of {@link javafx.beans.binding.DoubleBinding}.
*/
@Deprecated
public abstract class DoubleBinding
extends javafx.beans.binding.DoubleBinding
implements Binding {
/**
* @deprecated Use {@link Val#suspendable(javafx.beans.value.ObservableValue)}.
*/
@Deprecated
public static DoubleBinding wrap(ObservableValue extends Number> source) {
return new DoubleBinding() {
{ bind(source); }
@Override
protected double computeValue() { return source.getValue().doubleValue(); }
};
}
private ExpressionHelper helper = null;
private boolean blocked = false;
private boolean fireOnRelease = false;
@Override
public Guard block() {
if(blocked) {
return Guard.EMPTY_GUARD;
} else {
blocked = true;
return this::release;
}
}
private void release() {
blocked = false;
if(fireOnRelease) {
fireOnRelease = false;
ExpressionHelper.fireValueChangedEvent(helper);
}
}
@Override
protected final void onInvalidating() {
if(blocked)
fireOnRelease = true;
else
ExpressionHelper.fireValueChangedEvent(helper);
}
/*******************************************
*** Override adding/removing listeners. ***
*******************************************/
@Override
public void addListener(InvalidationListener listener) {
helper = ExpressionHelper.addListener(helper, this, listener);
}
@Override
public void removeListener(InvalidationListener listener) {
helper = ExpressionHelper.removeListener(helper, listener);
}
@Override
public void addListener(ChangeListener super Number> listener) {
helper = ExpressionHelper.addListener(helper, this, listener);
}
@Override
public void removeListener(ChangeListener super Number> listener) {
helper = ExpressionHelper.removeListener(helper, listener);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy