From 56b8f24b94386d5d808f5736e3bc1b6d2ecb2353 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Thu, 12 Aug 2021 22:38:29 +0530 Subject: [PATCH] JDK-8172095: Let Node.managed become CSS-styleable --- .../docs/javafx/scene/doc-files/cssref.html | 7 ++++++ .../src/main/java/javafx/scene/Node.java | 24 +++++++++++++++++-- .../test/java/test/javafx/scene/NodeTest.java | 8 +++++++ .../javafx/scene/Node_cssMethods_Test.java | 4 ++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/modules/javafx.graphics/src/main/docs/javafx/scene/doc-files/cssref.html b/modules/javafx.graphics/src/main/docs/javafx/scene/doc-files/cssref.html index c64dc03cd39..5e33edaed1a 100644 --- a/modules/javafx.graphics/src/main/docs/javafx/scene/doc-files/cssref.html +++ b/modules/javafx.graphics/src/main/docs/javafx/scene/doc-files/cssref.html @@ -1750,6 +1750,13 @@

Node

See W3C visibility property + + -fx-managed + + true +   + Defines whether this node's layout will be managed by its parent +

Pseudo-classes

diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/Node.java b/modules/javafx.graphics/src/main/java/javafx/scene/Node.java index f061fa8264d..f2722556593 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/Node.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/Node.java @@ -2637,12 +2637,12 @@ public final void setManaged(boolean value) { } public final boolean isManaged() { - return managed == null ? true : managed.get(); + return managed == null || managed.get(); } public final BooleanProperty managedProperty() { if (managed == null) { - managed = new BooleanPropertyBase(true) { + managed = new StyleableBooleanProperty(true) { @Override protected void invalidated() { @@ -2653,6 +2653,11 @@ protected void invalidated() { notifyManagedChanged(); } + @Override + public CssMetaData getCssMetaData() { + return StyleableProperties.MANAGED; + } + @Override public Object getBean() { return Node.this; @@ -9101,6 +9106,20 @@ public StyleableProperty getStyleableProperty(Node node) { return (StyleableProperty)node.visibleProperty(); } }; + private static final CssMetaData MANAGED = + new CssMetaData("-fx-managed", + BooleanConverter.getInstance(), Boolean.TRUE) { + + @Override + public boolean isSettable(Node node) { + return node.managed == null || !node.managed.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(Node node) { + return (StyleableProperty)node.managedProperty(); + } + }; private static final List> STYLEABLES; @@ -9122,6 +9141,7 @@ public StyleableProperty getStyleableProperty(Node node) { styleables.add(TRANSLATE_Y); styleables.add(TRANSLATE_Z); styleables.add(VISIBILITY); + styleables.add(MANAGED); STYLEABLES = Collections.unmodifiableList(styleables); } diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/NodeTest.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/NodeTest.java index d6b3d451176..8c718e3cd3c 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/NodeTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/NodeTest.java @@ -1894,6 +1894,14 @@ public void rtlSceneSizeShouldBeComputedCorrectly() { assertEquals(100.0, scene.getWidth(), 0.00001); } + @Test public void managedSetFromCSS() { + final AnchorPane node = new AnchorPane(); + node.setStyle("-fx-managed: false"); + Scene s = new Scene(node); + node.applyCss(); + assertFalse(node.isManaged()); + } + private Node createTestRect() { final Rectangle rect = new StubRect(); Scene scene = new Scene(new Group(rect)); diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/Node_cssMethods_Test.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/Node_cssMethods_Test.java index fafc5547975..b9868941740 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/Node_cssMethods_Test.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/Node_cssMethods_Test.java @@ -87,8 +87,8 @@ public boolean equals(final Object expected, }), config("cursor", null, "-fx-cursor", Cursor.MOVE), config("effect", null, "-fx-effect", new Shadow()), - config("focusTraversable", false, - "-fx-focus-traversable", true), + config("focusTraversable", false, "-fx-focus-traversable", true), + config("managed", true, "-fx-managed", false, false), config("opacity", 1.0, "-fx-opacity", 0.5), config("opacity", 0.5, "-fx-opacity", null, 0.0), config("viewOrder", 0.0, "-fx-view-order", 0.5),