RFR: 8290765: Remove parent disabled/treeVisible listeners
Nir Lisker
nlisker at openjdk.org
Thu Aug 25 12:37:44 UTC 2022
On Thu, 21 Jul 2022 04:43:15 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
> `Node` adds InvalidationListeners to its parent's `disabled` and `treeVisible` properties and calls its own `updateDisabled()` and `updateTreeVisible(boolean)` methods when the property values change.
>
> These listeners are not required, since `Node` can easily call the `updateDisabled()` and `updateTreeVisible(boolean)` methods on its children, saving the memory cost of maintaining listeners and bindings.
modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 1919:
> 1917: }
> 1918: }
> 1919: }
Because we can use Java 17 now, you can use pattern matching for `instanceof`. Also, from what I see, `getChildren()` can never return `null`. So, we can write
if (Node.this instanceof Parent parent) {
parent.getChildren().forEach(child -> child.updateDisabled());
}
-------------
PR: https://git.openjdk.org/jfx/pull/841
More information about the openjfx-dev
mailing list