Skip to content

Commit

Permalink
JDK-8172095: Let Node.managed become CSS-styleable
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinayagarwal committed Aug 12, 2021
1 parent 852d287 commit 56b8f24
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,13 @@ <h4><a id="node">Node</a></h4>
<td>See <a href="http://www.w3.org/TR/CSS2/visufx.html#visibility">W3C
visibility property</a></td>
</tr>
<tr>
<th class="propertyname" scope="row">-fx-managed</th>
<td class="value"><a href="#typeboolean" class="typelink"><boolean></a></td>
<td class="default">true</td>
<td class="range">&nbsp;</td>
<td>Defines whether this node's layout will be managed by its parent</td>
</tr>
</tbody>
</table>
<h4>Pseudo-classes</h4>
Expand Down
24 changes: 22 additions & 2 deletions modules/javafx.graphics/src/main/java/javafx/scene/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -2653,6 +2653,11 @@ protected void invalidated() {
notifyManagedChanged();
}

@Override
public CssMetaData<Node, Boolean> getCssMetaData() {
return StyleableProperties.MANAGED;
}

@Override
public Object getBean() {
return Node.this;
Expand Down Expand Up @@ -9101,6 +9106,20 @@ public StyleableProperty<Boolean> getStyleableProperty(Node node) {
return (StyleableProperty<Boolean>)node.visibleProperty();
}
};
private static final CssMetaData<Node,Boolean> MANAGED =
new CssMetaData<Node,Boolean>("-fx-managed",
BooleanConverter.getInstance(), Boolean.TRUE) {

@Override
public boolean isSettable(Node node) {
return node.managed == null || !node.managed.isBound();
}

@Override
public StyleableProperty<Boolean> getStyleableProperty(Node node) {
return (StyleableProperty<Boolean>)node.managedProperty();
}
};

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

Expand All @@ -9122,6 +9141,7 @@ public StyleableProperty<Boolean> getStyleableProperty(Node node) {
styleables.add(TRANSLATE_Y);
styleables.add(TRANSLATE_Z);
styleables.add(VISIBILITY);
styleables.add(MANAGED);
STYLEABLES = Collections.unmodifiableList(styleables);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 56b8f24

Please sign in to comment.