Skip to content

Commit d356340

Browse files
abhinayagarwalkevinrushforth
authored andcommitted
8172095: Let Node.managed become CSS-styleable
Reviewed-by: kcr, arapte
1 parent b2ecfac commit d356340

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

modules/javafx.graphics/src/main/docs/javafx/scene/doc-files/cssref.html

+7
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,13 @@ <h4><a id="node">Node</a></h4>
17501750
<td>See <a href="http://www.w3.org/TR/CSS2/visufx.html#visibility">W3C
17511751
visibility property</a></td>
17521752
</tr>
1753+
<tr>
1754+
<th class="propertyname" scope="row">-fx-managed</th>
1755+
<td class="value"><a href="#typeboolean" class="typelink">&lt;boolean&gt;</a></td>
1756+
<td class="default">true</td>
1757+
<td class="range">&nbsp;</td>
1758+
<td>Defines whether this node's layout will be managed by its parent</td>
1759+
</tr>
17531760
</tbody>
17541761
</table>
17551762
<h4>Pseudo-classes</h4>

modules/javafx.graphics/src/main/java/javafx/scene/Node.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -2637,12 +2637,12 @@ public final void setManaged(boolean value) {
26372637
}
26382638

26392639
public final boolean isManaged() {
2640-
return managed == null ? true : managed.get();
2640+
return managed == null || managed.get();
26412641
}
26422642

26432643
public final BooleanProperty managedProperty() {
26442644
if (managed == null) {
2645-
managed = new BooleanPropertyBase(true) {
2645+
managed = new StyleableBooleanProperty(true) {
26462646

26472647
@Override
26482648
protected void invalidated() {
@@ -2653,6 +2653,11 @@ protected void invalidated() {
26532653
notifyManagedChanged();
26542654
}
26552655

2656+
@Override
2657+
public CssMetaData<Node, Boolean> getCssMetaData() {
2658+
return StyleableProperties.MANAGED;
2659+
}
2660+
26562661
@Override
26572662
public Object getBean() {
26582663
return Node.this;
@@ -9101,6 +9106,20 @@ public StyleableProperty<Boolean> getStyleableProperty(Node node) {
91019106
return (StyleableProperty<Boolean>)node.visibleProperty();
91029107
}
91039108
};
9109+
private static final CssMetaData<Node,Boolean> MANAGED =
9110+
new CssMetaData<Node,Boolean>("-fx-managed",
9111+
BooleanConverter.getInstance(), Boolean.TRUE) {
9112+
9113+
@Override
9114+
public boolean isSettable(Node node) {
9115+
return node.managed == null || !node.managed.isBound();
9116+
}
9117+
9118+
@Override
9119+
public StyleableProperty<Boolean> getStyleableProperty(Node node) {
9120+
return (StyleableProperty<Boolean>)node.managedProperty();
9121+
}
9122+
};
91049123

91059124
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
91069125

@@ -9122,6 +9141,7 @@ public StyleableProperty<Boolean> getStyleableProperty(Node node) {
91229141
styleables.add(TRANSLATE_Y);
91239142
styleables.add(TRANSLATE_Z);
91249143
styleables.add(VISIBILITY);
9144+
styleables.add(MANAGED);
91259145
STYLEABLES = Collections.unmodifiableList(styleables);
91269146

91279147
}

modules/javafx.graphics/src/test/java/test/javafx/scene/NodeTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,34 @@ public void settingVisibleThroughPropertyShouldAffectBothGetterAndProperty() {
10901090
assertFalse(node.visibleProperty().get());
10911091
}
10921092

1093+
@Test
1094+
public void testDefaultValueForManagedIsTrueWhenReadFromGetter() {
1095+
final Node node = new Rectangle();
1096+
assertTrue(node.isManaged());
1097+
}
1098+
1099+
@Test
1100+
public void testDefaultValueForManagedIsTrueWhenReadFromProperty() {
1101+
final Node node = new Rectangle();
1102+
assertTrue(node.managedProperty().get());
1103+
}
1104+
1105+
@Test
1106+
public void settingManagedThroughSetterShouldAffectBothGetterAndProperty() {
1107+
final Node node = new Rectangle();
1108+
node.setManaged(false);
1109+
assertFalse(node.isManaged());
1110+
assertFalse(node.managedProperty().get());
1111+
}
1112+
1113+
@Test
1114+
public void settingManagedThroughPropertyShouldAffectBothGetterAndProperty() {
1115+
final Node node = new Rectangle();
1116+
node.managedProperty().set(false);
1117+
assertFalse(node.isManaged());
1118+
assertFalse(node.managedProperty().get());
1119+
}
1120+
10931121
@Test
10941122
public void testDefaultStyleIsEmptyString() {
10951123
final Node node = new Rectangle();
@@ -1894,6 +1922,14 @@ public void rtlSceneSizeShouldBeComputedCorrectly() {
18941922
assertEquals(100.0, scene.getWidth(), 0.00001);
18951923
}
18961924

1925+
@Test public void managedSetFromCSS() {
1926+
final AnchorPane node = new AnchorPane();
1927+
node.setStyle("-fx-managed: false");
1928+
Scene s = new Scene(node);
1929+
node.applyCss();
1930+
assertFalse(node.isManaged());
1931+
}
1932+
18971933
private Node createTestRect() {
18981934
final Rectangle rect = new StubRect();
18991935
Scene scene = new Scene(new Group(rect));

modules/javafx.graphics/src/test/java/test/javafx/scene/Node_cssMethods_Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public boolean equals(final Object expected,
8787
}),
8888
config("cursor", null, "-fx-cursor", Cursor.MOVE),
8989
config("effect", null, "-fx-effect", new Shadow()),
90-
config("focusTraversable", false,
91-
"-fx-focus-traversable", true),
90+
config("focusTraversable", false, "-fx-focus-traversable", true),
91+
config("managed", true, "-fx-managed", false, false),
9292
config("opacity", 1.0, "-fx-opacity", 0.5),
9393
config("opacity", 0.5, "-fx-opacity", null, 0.0),
9494
config("viewOrder", 0.0, "-fx-view-order", 0.5),

0 commit comments

Comments
 (0)