From: Matti Tahvonen Date: Fri, 17 Oct 2008 12:17:58 +0000 (+0000) Subject: experimental expand feature for ordered layout X-Git-Tag: 6.7.0.beta1~3977 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=99c4b5c2ed38d50583d2b0e66b73d3dc2a815a10;p=vaadin-framework.git experimental expand feature for ordered layout svn changeset:5654/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/ui/OrderedLayout.java b/src/com/itmill/toolkit/ui/OrderedLayout.java index b088d9f298..93929d91d9 100644 --- a/src/com/itmill/toolkit/ui/OrderedLayout.java +++ b/src/com/itmill/toolkit/ui/OrderedLayout.java @@ -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);