changeset 1082:2ab615afad9e

RT-16011 Need mechanism for PG nodes to know when they are no longer part of a scene graph
author Martin Sladecek <martin.sladecek@oracle.com>
date Thu, 17 May 2012 10:49:48 +0200
parents a7a2d369bcd4
children efa0fd389c78
files javafx-ui-common/src/com/sun/javafx/scene/DirtyBits.java javafx-ui-common/src/javafx/scene/Node.java javafx-ui-common/test/unit/javafx/scene/NodeTest.java test-stub-toolkit/src/com/sun/javafx/pgstub/StubNode.java
diffstat 4 files changed, 44 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/scene/DirtyBits.java	Wed May 16 13:37:38 2012 +0200
+++ b/javafx-ui-common/src/com/sun/javafx/scene/DirtyBits.java	Thu May 17 10:49:48 2012 +0200
@@ -36,6 +36,7 @@
     NODE_TRANSFORM,
     NODE_BOUNDS,
     NODE_VISIBLE,
+    NODE_TREE_VISIBLE,
     NODE_DEPTH_TEST,
     NODE_BLENDMODE,
     NODE_CSS,
--- a/javafx-ui-common/src/javafx/scene/Node.java	Wed May 16 13:37:38 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/Node.java	Thu May 17 10:49:48 2012 +0200
@@ -355,7 +355,7 @@
                 s.addToDirtyList(this);
         }
 
-        impl_setDirty(dirtyBit);
+        dirtyBits |= dirtyBit.getMask();
     }
 
     /**
@@ -370,17 +370,6 @@
     }
 
     /**
-     * Set the specified dirty bit.
-     *
-     * @treatAsPrivate implementation detail
-     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
-     */
-    @Deprecated
-    private void impl_setDirty(DirtyBits dirtyBit) {
-        dirtyBits |= dirtyBit.getMask();
-    }
-
-    /**
      * Clear the specified dirty bit
      *
      * @treatAsPrivate implementation detail
@@ -514,6 +503,10 @@
                                   ? null
                                   : Blend.impl_getToolkitMode(mode));
         }
+
+        if (impl_isDirty(DirtyBits.NODE_TREE_VISIBLE) && !treeVisible) {
+            peer.dispose();
+        }
     }
 
     /*************************************************************************
@@ -708,6 +701,7 @@
                     if (getClip() != null) {
                         getClip().setScene(_scene);
                     }
+                    updateTreeVisible();
                     updateCanReceiveFocus();
                     if (isFocusTraversable()) {
                         if (oldScene != null) {
@@ -6424,7 +6418,8 @@
     }
 
     private void updateTreeVisible() {
-        setTreeVisible(isVisible() && ((getParent() == null) || getParent().impl_isTreeVisible()));
+        setTreeVisible(isVisible() && ((getParent() != null && getParent().impl_isTreeVisible()) ||
+                (getScene() != null && getScene().getRoot() == this)));
     }
 
     private boolean treeVisible;
@@ -6436,6 +6431,7 @@
             updateCanReceiveFocus();
             focusSetDirty(getScene());
             ((TreeVisiblePropertyReadOnly)treeVisibleProperty()).invalidate();
+            impl_markDirty(DirtyBits.NODE_TREE_VISIBLE);
         }
     }
 
--- a/javafx-ui-common/test/unit/javafx/scene/NodeTest.java	Wed May 16 13:37:38 2012 +0200
+++ b/javafx-ui-common/test/unit/javafx/scene/NodeTest.java	Thu May 17 10:49:48 2012 +0200
@@ -986,4 +986,33 @@
         assertEquals("", node.styleProperty().get());
         assertEquals("", node.getStyle());
     }
+
+    @Test
+    public void testNode_treeVisible() {
+        final Node n = new Rectangle();
+        Group g = new Group();
+        Scene s = new Scene(g);
+        assertTrue(g.impl_isTreeVisible());
+        assertFalse(n.impl_isTreeVisible());
+
+        g.getChildren().add(n);
+        assertTrue(n.impl_isTreeVisible());
+
+        g.getChildren().clear();
+        assertTrue(g.impl_isTreeVisible());
+        assertFalse(n.impl_isTreeVisible());
+
+        s.setRoot(new Group());
+        assertFalse(g.impl_isTreeVisible());
+
+        g.getChildren().add(n);
+        s.setRoot(g);
+        assertTrue(g.impl_isTreeVisible());
+        assertTrue(n.impl_isTreeVisible());
+
+        g.setVisible(false);
+        assertFalse(g.impl_isTreeVisible());
+        assertFalse(n.impl_isTreeVisible());
+    }
+
 }
--- a/test-stub-toolkit/src/com/sun/javafx/pgstub/StubNode.java	Wed May 16 13:37:38 2012 +0200
+++ b/test-stub-toolkit/src/com/sun/javafx/pgstub/StubNode.java	Thu May 17 10:49:48 2012 +0200
@@ -107,4 +107,9 @@
     public void effectChanged() {
         // ignore
     }
+
+    @Override
+    public void dispose() {
+        // ignore
+    }
 }