From 99c4b5c2ed38d50583d2b0e66b73d3dc2a815a10 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 17 Oct 2008 12:17:58 +0000 Subject: [PATCH] experimental expand feature for ordered layout svn changeset:5654/svn branch:trunk --- src/com/itmill/toolkit/ui/OrderedLayout.java | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) 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); -- 2.39.5