changeset 4300:71b246b6efa0

RT-30545 AnchorPane Layout Issue
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 16 Jul 2013 13:13:57 +0200
parents e3c3c884cce1
children 66df77e2c6b2 57ddbe09941c
files modules/graphics/src/main/java/javafx/scene/Node.java modules/graphics/src/stub/java/javafx/scene/NodeTest.java
diffstat 2 files changed, 82 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/Node.java	Tue Jul 16 15:07:54 2013 +0400
+++ b/modules/graphics/src/main/java/javafx/scene/Node.java	Tue Jul 16 13:13:57 2013 +0200
@@ -2387,6 +2387,17 @@
                 @Override
                 protected void invalidated() {
                     impl_transformsChanged();
+                    final Parent p = getParent();
+                    if (p != null && !p.performingLayout) {
+                        if (isManaged()) {
+                            // Let parent fix the layout
+                            p.requestLayout();
+                        } else {
+                            // Parent size changed, parent's parent might need to re-layout
+                            p.clearSizeCache();
+                            p.requestParentLayout();
+                        }
+                    }
                 }
 
                 @Override
@@ -2448,6 +2459,17 @@
                 @Override
                 protected void invalidated() {
                     impl_transformsChanged();
+                    final Parent p = getParent();
+                    if (p != null && !p.performingLayout) {
+                        if (isManaged()) {
+                            // Let parent fix the layout
+                            p.requestLayout();
+                        } else {
+                            // Parent size changed, parent's parent might need to re-layout
+                            p.clearSizeCache();
+                            p.requestParentLayout();
+                        }
+                    }
                 }
 
                 @Override
@@ -4813,7 +4835,7 @@
 
         return tmin;
     }
-    
+
 
     // Good to find a home for commonly use util. code such as EPS.
     // and almostZero. This code currently defined in multiple places,
@@ -7578,9 +7600,9 @@
     private void updateTreeVisible() {
         boolean isTreeVisible = isVisible();
         if (isTreeVisible) {
-            final Parent p = getParent(); 
+            final Parent p = getParent();
             isTreeVisible = p != null ? getParent().impl_isTreeVisible() :
-                    clipParent != null ? clipParent.impl_isTreeVisible() : 
+                    clipParent != null ? clipParent.impl_isTreeVisible() :
                     getSubScene() == null || getSubScene().impl_isTreeVisible();
         }
         setTreeVisible(isTreeVisible);
@@ -8381,14 +8403,14 @@
              styleHelper.setObservableStyleMap(styleMap);
          }
      }
-     
+
     /**
      * Flags used to indicate in which way this node is dirty (or whether it
      * is clean) and what must happen during the next CSS cycle on the
      * scenegraph.
      */
     CssFlags cssFlag = CssFlags.CLEAN;
-    
+
     /**
      * Needed for testing.
      */
--- a/modules/graphics/src/stub/java/javafx/scene/NodeTest.java	Tue Jul 16 15:07:54 2013 +0400
+++ b/modules/graphics/src/stub/java/javafx/scene/NodeTest.java	Tue Jul 16 13:13:57 2013 +0200
@@ -49,6 +49,7 @@
 
 import java.lang.reflect.Method;
 import java.util.Comparator;
+import javafx.scene.layout.AnchorPane;
 
 import static org.junit.Assert.*;
 /**
@@ -1026,7 +1027,7 @@
         syncNode(c);
         assertEquals(2, sg.getChildren().size());
         assertEquals(100.0, sc.getRadius(), 0.01);
-        
+
     }
 
     @Test
@@ -1285,4 +1286,57 @@
         final Point2D trPoint = scene.getRoot().localToScene(0, 0);
         assertEquals(180, trPoint.getX(), 0.1);
     }
+
+
+    @Test
+    public void testLayoutXYTriggersParentSizeChange() {
+        final Group rootGroup = new Group();
+        final Group subGroup = new Group();
+        rootGroup.getChildren().add(subGroup);
+
+        Rectangle r = new Rectangle(50,50);
+        r.setManaged(false);
+        Rectangle staticR = new Rectangle(1,1);
+        subGroup.getChildren().addAll(r, staticR);
+
+        assertEquals(50,subGroup.getLayoutBounds().getWidth(), 1e-10);
+        assertEquals(50,subGroup.getLayoutBounds().getHeight(), 1e-10);
+
+        r.setLayoutX(50);
+
+        rootGroup.layout();
+
+        assertEquals(100,subGroup.getLayoutBounds().getWidth(), 1e-10);
+        assertEquals(50,subGroup.getLayoutBounds().getHeight(), 1e-10);
+
+    }
+
+    @Test
+    public void testLayoutXYWontBreakLayout() {
+        final Group rootGroup = new Group();
+        final AnchorPane pane = new AnchorPane();
+        rootGroup.getChildren().add(pane);
+
+        Rectangle r = new Rectangle(50,50);
+        pane.getChildren().add(r);
+
+        AnchorPane.setLeftAnchor(r, 10d);
+        AnchorPane.setTopAnchor(r, 10d);
+
+        rootGroup.layout();
+
+        assertEquals(10, r.getLayoutX(), 1e-10);
+        assertEquals(10, r.getLayoutY(), 1e-10);
+
+        r.setLayoutX(50);
+
+        assertEquals(50, r.getLayoutX(), 1e-10);
+        assertEquals(10, r.getLayoutY(), 1e-10);
+
+        rootGroup.layout();
+
+        assertEquals(10, r.getLayoutX(), 1e-10);
+        assertEquals(10, r.getLayoutY(), 1e-10);
+
+    }
 }