]> source.dussan.org Git - vaadin-framework.git/commitdiff
experimental expand feature for ordered layout
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 17 Oct 2008 12:17:58 +0000 (12:17 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 17 Oct 2008 12:17:58 +0000 (12:17 +0000)
svn changeset:5654/svn branch:trunk

src/com/itmill/toolkit/ui/OrderedLayout.java

index b088d9f29855b076336237788eb155a0e69cec4f..93929d91d936b0ef770699ac337edc08680f135c 100644 (file)
@@ -180,16 +180,22 @@ public class OrderedLayout extends AbstractLayout implements
         }
 
         final String[] alignmentsArray = new String[components.size()];
-        final Float[] expandRatioArray = new Float[components.size()];
+        final Integer[] expandRatioArray = new Integer[components.size()];
         float sum = getExpandRatioSum();
-        boolean equallyDevided = false;
-        if (sum == 0) {
-            equallyDevided = true;
+        boolean equallyDivided = false;
+        int realSum = 0;
+        if (sum == 0 && components.size() > 0) {
+            // no component has been expanded, all components have same expand
+            // rate
+            equallyDivided = true;
             float equalSize = 1 / components.size();
+            int myRatio = Math.round(equalSize * 1000);
             for (int i = 0; i < expandRatioArray.length; i++) {
-                expandRatioArray[i] = equalSize;
+                expandRatioArray[i] = myRatio;
             }
+            realSum = myRatio * components.size();
         }
+
         // Adds all items in all the locations
         int index = 0;
         for (final Iterator i = components.iterator(); i.hasNext();) {
@@ -199,14 +205,18 @@ public class OrderedLayout extends AbstractLayout implements
                 c.paint(target);
                 alignmentsArray[index] = String
                         .valueOf(getComponentAlignment(c));
-                if (!equallyDevided) {
-                    float myRatio = getExpandRatio(c);
-                    expandRatioArray[index] = myRatio / sum;
+                if (!equallyDivided) {
+                    int myRatio = Math.round((getExpandRatio(c) / sum) * 1000);
+                    expandRatioArray[index] = myRatio;
+                    realSum += myRatio;
                 }
                 index++;
             }
         }
 
+        // correct possible rounding error
+        expandRatioArray[0] -= realSum - 1000;
+
         // Add child component alignment info to layout tag
         target.addAttribute("alignments", alignmentsArray);
         target.addAttribute("expandRatios", expandRatioArray);