changeset 4291:0318a5d3d917

RT-31283 Custom Node: The arrow shifts, not aligning correctly.
author Martin Sladecek <martin.sladecek@oracle.com>
date Mon, 15 Jul 2013 14:15:01 +0200
parents 8091df24a8e5
children f5a3e0dfc93a
files modules/graphics/src/main/java/javafx/scene/Group.java modules/graphics/src/stub/java/javafx/scene/GroupTest.java
diffstat 2 files changed, 23 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/Group.java	Mon Jul 15 12:19:04 2013 +0200
+++ b/modules/graphics/src/main/java/javafx/scene/Group.java	Mon Jul 15 14:15:01 2013 +0200
@@ -30,6 +30,7 @@
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.BooleanPropertyBase;
 import javafx.collections.ObservableList;
+import javafx.geometry.Bounds;
 
 
 
@@ -152,34 +153,29 @@
         return super.getChildren();
     }
 
+
     @Override
-    protected double computePrefWidth(double height) {
-        if (isAutoSizeChildren()) {
-            return super.computePrefWidth(height);
-        } else {
-            return getLayoutBounds().getWidth();
-        }
+    protected Bounds impl_computeLayoutBounds() {
+        layout(); // Needs to done prematurely, as we otherwise don't know the bounds of the children
+        return super.impl_computeLayoutBounds();
     }
-    
-    
-    @Override
-    protected double computePrefHeight(double width) {
-        if (isAutoSizeChildren()) {
-            return super.computePrefHeight(width);
-        } else {
-            return getLayoutBounds().getHeight();
-        }
-    }
-    
+
     /**
      * Group defines the preferred width as simply being the width of its layout bounds, which
      * in turn is simply the sum of the positions & widths of all of its children. That is,
      * the preferred width is the one that it is at, because a Group cannot be resized.
      *
+     * Note: as the layout bounds in autosize Group depend on the Group to be already laid-out,
+     * this call will do the layout of the Group if necessary.
+     *
      * @param height This parameter is ignored by Group
      * @return The layout bounds width
      */
-    @Override public double prefWidth(double height) {
+    @Override
+    public double prefWidth(double height) {
+        if (isAutoSizeChildren()) {
+            layout();
+        }
         return getLayoutBounds().getWidth();
     }
 
@@ -188,13 +184,21 @@
      * in turn is simply the sum of the positions & heights of all of its children. That is,
      * the preferred height is the one that it is at, because a Group cannot be resized.
      *
+     * Note: as the layout bounds in autosize Group depend on the Group to be already laid-out,
+     * this call will do the layout of the Group if necessary.
+     *
      * @param width This parameter is ignored by Group
      * @return The layout bounds height
      */
-    @Override public double prefHeight(double width) {
+    @Override
+    public double prefHeight(double width) {
+        if (isAutoSizeChildren()) {
+            layout();
+        }
         return getLayoutBounds().getHeight();
     }
 
+
     @Override
     public double minHeight(double width) {
         return prefHeight(width);
--- a/modules/graphics/src/stub/java/javafx/scene/GroupTest.java	Mon Jul 15 12:19:04 2013 +0200
+++ b/modules/graphics/src/stub/java/javafx/scene/GroupTest.java	Mon Jul 15 14:15:01 2013 +0200
@@ -461,7 +461,6 @@
         region.setVisible(false);
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(50,75);
         group.getChildren().addAll(region,region2);
-        group.layout();
 
         assertEquals(50, group.prefWidth(-1), 0);
     }
@@ -474,7 +473,6 @@
         region.setVisible(false);
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(50,75);
         group.getChildren().addAll(region,region2);
-        group.layout();
 
         assertEquals(75, group.prefHeight(-1), 0);
     }
@@ -485,7 +483,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(100, group.prefWidth(-1), 0);
     }
@@ -496,7 +493,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(150, group.prefHeight(-1), 0);
     }
@@ -508,7 +504,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setScaleX(2.0);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(200, group.prefWidth(-1), 0);
     }
@@ -520,7 +515,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setScaleY(2.0);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(300, group.prefHeight(-1), 0);
     }
@@ -532,7 +526,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setClip(new Rectangle(50,75));
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(50, group.prefWidth(-1), 0);
     }
@@ -544,7 +537,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setClip(new Rectangle(50,75));
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(75, group.prefHeight(-1), 0);
     }
@@ -556,7 +548,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setRotate(90);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(150, group.prefWidth(-1), 0);
     }
@@ -568,7 +559,6 @@
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         region.setRotate(90);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(100, group.prefHeight(-1), 0);
     }
@@ -581,7 +571,6 @@
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(100,150);
         region2.setTranslateX(50);
         group.getChildren().addAll(region1,region2);
-        group.layout();
 
         assertEquals(150, group.prefWidth(-1), 0);
     }
@@ -594,7 +583,6 @@
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(100,150);
         region2.setTranslateY(50);
         group.getChildren().addAll(region1,region2);
-        group.layout();
 
         assertEquals(200, group.prefHeight(-1), 0);
     }
@@ -606,7 +594,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(100, group.prefWidth(-1), 0);
     }
@@ -618,7 +605,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(150, group.prefHeight(-1), 0);
     }
@@ -630,7 +616,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(100, group.prefWidth(-1), 0);
     }
@@ -642,7 +627,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(150, group.prefHeight(-1), 0);
     }
@@ -654,7 +638,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(100, group.prefWidth(-1), 0);
     }
@@ -666,7 +649,6 @@
 
         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().add(region);
-        group.layout();
 
         assertEquals(150, group.prefHeight(-1), 0);
     }
@@ -679,7 +661,6 @@
         javafx.scene.layout.MockRegion region1 = new javafx.scene.layout.MockRegion(100,150);
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().addAll(region1,region2);
-        group.layout();
 
         assertEquals(100, group.prefWidth(-1), 0);
     }
@@ -692,7 +673,6 @@
         javafx.scene.layout.MockRegion region1 = new javafx.scene.layout.MockRegion(100,150);
         javafx.scene.layout.MockRegion region2 = new javafx.scene.layout.MockRegion(100,150);
         group.getChildren().addAll(region1,region2);
-        group.layout();
 
         assertEquals(150, group.prefHeight(-1), 0);
     }