Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8305885

Use ReadOnly*PropertyBase class where possible

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx21
    • None
    • javafx
    • None
    • b14

      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();
                  }
              }


            jhendrikx John Hendrikx
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: