Many hand rolled properties in JavaFX could benefit from using this base class (it may have been added later).
A typical pattern is that a super class of ReadOnly*PropertyBase is extended (ReadOnly*Property for example), and that all of the methods offered by the base subclass are implemented again (the base class offers implementations for the add and remove listener methods).
An example from Node:
private static abstract class LazyTransformProperty
extends ReadOnlyObjectProperty<Transform> {
private ExpressionHelper<Transform> helper;
@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 Transform> listener) {
helper = ExpressionHelper.addListener(helper, this, listener);
}
@Override
public void removeListener(ChangeListener<? super Transform> listener) {
helper = ExpressionHelper.removeListener(helper, listener);
}
public void invalidate() {
if (valid != INVALID) {
valid = INVALID;
ExpressionHelper.fireValueChangedEvent(helper);
}
}
This would become:
private static abstract class LazyTransformProperty
extends ReadOnlyObjectPropertyBase<Transform> {
public void invalidate() {
if (valid != INVALID) {
valid = INVALID;
fireValueChangedEvent();
}
}
A typical pattern is that a super class of ReadOnly*PropertyBase is extended (ReadOnly*Property for example), and that all of the methods offered by the base subclass are implemented again (the base class offers implementations for the add and remove listener methods).
An example from Node:
private static abstract class LazyTransformProperty
extends ReadOnlyObjectProperty<Transform> {
private ExpressionHelper<Transform> helper;
@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 Transform> listener) {
helper = ExpressionHelper.addListener(helper, this, listener);
}
@Override
public void removeListener(ChangeListener<? super Transform> listener) {
helper = ExpressionHelper.removeListener(helper, listener);
}
public void invalidate() {
if (valid != INVALID) {
valid = INVALID;
ExpressionHelper.fireValueChangedEvent(helper);
}
}
This would become:
private static abstract class LazyTransformProperty
extends ReadOnlyObjectPropertyBase<Transform> {
public void invalidate() {
if (valid != INVALID) {
valid = INVALID;
fireValueChangedEvent();
}
}