]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #2591 - A Label leaves empty space in a VerticalLayout in some...
authorArtur Signell <artur.signell@itmill.com>
Fri, 13 Feb 2009 21:20:26 +0000 (21:20 +0000)
committerArtur Signell <artur.signell@itmill.com>
Fri, 13 Feb 2009 21:20:26 +0000 (21:20 +0000)
svn changeset:6839/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java [new file with mode: 0644]

index fae87ccd88188d218b7145228d319ecaec07aea2..ffa30f724bbb5080959f5c127a6142495d4e99d5 100644 (file)
@@ -194,26 +194,24 @@ public class IOrderedLayout extends CellBasedLayout {
          */\r
         if ((isHorizontal() && isDynamicHeight())\r
                 || (isVertical() && isDynamicWidth())) {\r
-            Size oldSize = new Size(activeLayoutSize.getWidth(),\r
-                    activeLayoutSize.getHeight());\r
-            calculateLayoutDimensions();\r
-\r
-            /*\r
-             * If layout dimension is changed due to relative sized components\r
-             * we must also update container sizes\r
-             */\r
-            if (!oldSize.equals(activeLayoutSize)) {\r
-                calculateContainerSize();\r
-            }\r
-\r
+            layoutSizeMightHaveChanged();\r
         }\r
         // w.mark("Layout dimensions updated");\r
 \r
         /* Update component spacing */\r
         updateContainerMargins();\r
 \r
-        /* Recalculate component sizes and alignments */\r
-        recalculateComponentSizesAndAlignments();\r
+        /*\r
+         * Update component sizes for components with relative size in non-main\r
+         * direction\r
+         */\r
+        if (updateRelativeSizesInNonMainDirection()) {\r
+            // Sizes updated - might affect the other dimension so we need to\r
+            // recheck the widget sizes and recalculate layout dimensions\r
+            updateWidgetSizes();\r
+            layoutSizeMightHaveChanged();\r
+        }\r
+        calculateAlignments();\r
         // w.mark("recalculateComponentSizesAndAlignments done");\r
 \r
         setRootSize();\r
@@ -232,6 +230,19 @@ public class IOrderedLayout extends CellBasedLayout {
         sizeHasChangedDuringRendering = false;\r
     }\r
 \r
+    private void layoutSizeMightHaveChanged() {\r
+        Size oldSize = new Size(activeLayoutSize.getWidth(), activeLayoutSize\r
+                .getHeight());\r
+        calculateLayoutDimensions();\r
+\r
+        /*\r
+         * If layout dimension changes we must also update container sizes\r
+         */\r
+        if (!oldSize.equals(activeLayoutSize)) {\r
+            calculateContainerSize();\r
+        }\r
+    }\r
+\r
     private void updateWidgetSizes() {\r
         for (ChildComponentContainer childComponentContainer : widgetToComponentContainer\r
                 .values()) {\r
@@ -298,44 +309,31 @@ public class IOrderedLayout extends CellBasedLayout {
 \r
     }\r
 \r
-    private void recalculateComponentSizesAndAlignments() {\r
-        if (widgetToComponentContainer.isEmpty()) {\r
-            return;\r
-        }\r
-\r
-        /*\r
-         * Update the height of relative height components in a horizontal\r
-         * layout or the width for relative width components in a vertical\r
-         * layout\r
-         */\r
-        updateRelativeSizesInNonMainDirection();\r
-\r
-        /* Calculate alignments */\r
-        calculateAlignments();\r
-\r
-    }\r
-\r
     /**\r
      * Updated components with relative height in horizontal layouts and\r
      * components with relative width in vertical layouts. This is only needed\r
      * if the height (horizontal layout) or width (vertical layout) has not been\r
      * specified.\r
      */\r
-    private void updateRelativeSizesInNonMainDirection() {\r
+    private boolean updateRelativeSizesInNonMainDirection() {\r
         int updateDirection = 1 - orientation;\r
         if ((updateDirection == ORIENTATION_HORIZONTAL && !isDynamicWidth())\r
                 || (updateDirection == ORIENTATION_VERTICAL && !isDynamicHeight())) {\r
-            return;\r
+            return false;\r
         }\r
 \r
+        boolean updated = false;\r
         for (ChildComponentContainer componentContainer : widgetToComponentContainer\r
                 .values()) {\r
             if (componentContainer.isComponentRelativeSized(updateDirection)) {\r
                 client.handleComponentRelativeSize(componentContainer\r
                         .getWidget());\r
             }\r
+\r
+            updated = true;\r
         }\r
 \r
+        return updated;\r
     }\r
 \r
     private int calculateLayoutDimensions() {\r
@@ -724,7 +722,8 @@ public class IOrderedLayout extends CellBasedLayout {
             recalculateLayout();\r
         }\r
 \r
-        recalculateComponentSizesAndAlignments();\r
+        updateRelativeSizesInNonMainDirection();\r
+        calculateAlignments();\r
 \r
         setRootSize();\r
     }\r
diff --git a/src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java b/src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java
new file mode 100644 (file)
index 0000000..37e7897
--- /dev/null
@@ -0,0 +1,38 @@
+package com.itmill.toolkit.tests.layouts;\r
+\r
+import com.itmill.toolkit.tests.components.TestBase;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.Label;\r
+\r
+public class VerticalLayoutWithRelativeSizeComponents extends TestBase {\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "A undefined wide VerticalLayout containing a 100% wide label, a Button and another identical label. The labels should be as wide as the button (400px) and there should be no extra space between the bottom of the first label and the button.";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return 2591;\r
+    }\r
+\r
+    @Override\r
+    protected void setup() {\r
+        getLayout().setSizeUndefined();\r
+        getMainWindow().getLayout().setHeight(null);\r
+\r
+        Label l = new Label(\r
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc condimentum urna quis leo. In hac habitasse platea dictumst. Pellentesque tincidunt. Sed libero nisl, faucibus in, laoreet pellentesque, consectetur non, dolor. Sed tortor. Ut pretium sapien. Cras elementum enim non lacus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla velit est, aliquam a, pellentesque a, iaculis nec, sapien. Ut ultrices ligula vitae nulla. Morbi sem pede, iaculis ac, condimentum a, ornare eget, nisi. Aliquam hendrerit pulvinar massa. Vestibulum pretium purus eu augue. Sed posuere elit ut magna. Cras consequat faucibus nunc. Vestibulum quis diam.");\r
+        Label l2 = new Label(\r
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc condimentum urna quis leo. In hac habitasse platea dictumst. Pellentesque tincidunt. Sed libero nisl, faucibus in, laoreet pellentesque, consectetur non, dolor. Sed tortor. Ut pretium sapien. Cras elementum enim non lacus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla velit est, aliquam a, pellentesque a, iaculis nec, sapien. Ut ultrices ligula vitae nulla. Morbi sem pede, iaculis ac, condimentum a, ornare eget, nisi. Aliquam hendrerit pulvinar massa. Vestibulum pretium purus eu augue. Sed posuere elit ut magna. Cras consequat faucibus nunc. Vestibulum quis diam.");\r
+        l.setWidth("100%");\r
+        l2.setWidth("100%");\r
+\r
+        Button b = new Button("This defines the width");\r
+        b.setWidth("400px");\r
+        addComponent(l);\r
+        addComponent(b);\r
+        addComponent(l2);\r
+    }\r
+\r
+}\r