]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #2029 - orderedlayout width calculations
authorArtur Signell <artur.signell@itmill.com>
Thu, 18 Sep 2008 06:16:24 +0000 (06:16 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 18 Sep 2008 06:16:24 +0000 (06:16 +0000)
svn changeset:5427/svn branch:trunk

16 files changed:
src/com/itmill/toolkit/terminal/gwt/client/ContainerResizedListener.java
src/com/itmill/toolkit/terminal/gwt/client/Util.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IForm.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ISlider.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java
src/com/itmill/toolkit/terminal/gwt/client/ui/absolutegrid/IAbsoluteGrid.java

index f299c985dd7adc6a8106ddfabdd6dbef8e5484ee..d3634a1804c3dae990a0dde9a172682dfac22808 100644 (file)
@@ -15,6 +15,12 @@ public interface ContainerResizedListener {
      * function on its ancestors that implement NeedsLayout in case their
      * container has resized. runAnchestorsLayout(HasWidgets parent) function
      * from Util class may be a good helper for this.
+     * 
+     * The width and height parameters specifies the space available for the
+     * component (in pixels) if the parent container can or want to produce
+     * these numbers. If the parent container does not know (has not calculated)
+     * or cannot produce (undefined dimensions) one of these numbers -1 is
+     * passed.
      */
-    public void iLayout();
+    public void iLayout(int availableWidth, int availableHeight);
 }
index b3fb7260e3a1e6ca34a8dc21fcc507ca8c4ff07b..8981054d707c00cc1682fc1aaca2456003673196 100644 (file)
@@ -48,7 +48,16 @@ public class Util {
         while (childWidgets.hasNext()) {
             final Widget child = (Widget) childWidgets.next();
             if (child instanceof ContainerResizedListener) {
-                ((ContainerResizedListener) child).iLayout();
+                int w = -1, h = -1;
+
+                if (container instanceof WidgetSpaceAllocator) {
+                    w = ((WidgetSpaceAllocator) container)
+                            .getAllocatedWidth(child);
+                    h = ((WidgetSpaceAllocator) container)
+                            .getAllocatedHeight(child);
+                }
+
+                ((ContainerResizedListener) child).iLayout(w, h);
             } else if (child instanceof HasWidgets) {
                 final HasWidgets childContainer = (HasWidgets) child;
                 runDescendentsLayout(childContainer);
@@ -56,6 +65,12 @@ public class Util {
         }
     }
 
+    public interface WidgetSpaceAllocator {
+        int getAllocatedWidth(Widget child);
+
+        int getAllocatedHeight(Widget child);
+    }
+
     /**
      * Returns closest parent Widget in hierarchy that implements Container
      * interface
index 7923d3d9776a92d28b1481b00fb5c0947dc4adba..1790e0154099b07969be718ff1f117f0e6af5f7e 100644 (file)
@@ -114,7 +114,11 @@ public class IAccordion extends ITabsheetBase implements
         this.height = height;
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         StackItem item = getSelectedStack();
         if (item == null) {
             return;
index a01f387546c0fde230c5dfeeaa93c5e16169169d..e10f9965036e4d177d919419742e21bd1d5ffc79 100644 (file)
@@ -412,7 +412,11 @@ public class ICustomLayout extends ComplexPanel implements Paintable,
         widgetToCaptionWrapper.clear();
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (!iLayoutJS(DOM.getFirstChild(getElement()))) {
             Util.runDescendentsLayout(this);
         }
index 601aa250a9dc1a7fd5ba1c4303e6f51557754643..081660cd83756499deb636f5e42aac36d72c9d7f 100644 (file)
@@ -373,7 +373,11 @@ public class IExpandLayout extends ComplexPanel implements
         return getWidgetIndex(component) >= 0;
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (orientationMode == ORIENTATION_HORIZONTAL) {
             int pixels;
             if ("".equals(height)) {
index 639d5fbb88003d30ec914d4f6399574e0170a121..596574dfe09e0d42d77e25fd9fbe9dd33229428c 100644 (file)
@@ -98,7 +98,7 @@ public class IForm extends ComplexPanel implements Paintable,
             DOM.setInnerHTML(desc, "");\r
         }\r
 \r
-        iLayout();\r
+        iLayout(-1, -1);\r
 \r
         final UIDL layoutUidl = uidl.getChildUIDL(0);\r
         Container newLo = (Container) client.getPaintable(layoutUidl);\r
@@ -135,7 +135,7 @@ public class IForm extends ComplexPanel implements Paintable,
         }\r
     }\r
 \r
-    public void iLayout() {\r
+    public void iLayout(int availableWidth, int availableHeight) {\r
         Util.runDescendentsLayout(this);\r
     }\r
 \r
index 88a6ad1f466693072de540112e90b0b34b4dd86d..e418ec109afd87928ae0b68a6501ef1501032a2b 100644 (file)
@@ -288,7 +288,11 @@ public class IGridLayout extends SimplePanel implements Paintable, Container,
 
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (needsLayout) {
             super.setWidth(width);
             if (meterElement == null) {
index 02a3a84448fb34c01cad7112b57d139abefda4dc..213b6f0764de260cef121ae1d94d3805d89ac3b4 100644 (file)
@@ -20,6 +20,7 @@ import com.itmill.toolkit.terminal.gwt.client.ICaption;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.Util.WidgetSpaceAllocator;
 
 /**
  * Full implementation of OrderedLayout client peer.
@@ -239,7 +240,7 @@ import com.itmill.toolkit.terminal.gwt.client.Util;
  * @author IT Mill Ltd
  */
 public class IOrderedLayout extends Panel implements Container,
-        ContainerResizedListener {
+        ContainerResizedListener, WidgetSpaceAllocator {
 
     public static final String CLASSNAME = "i-orderedlayout";
 
@@ -305,7 +306,7 @@ public class IOrderedLayout extends Panel implements Container,
      * List of child widget wrappers. These wrappers are in exact same indexes
      * as the widgets in childWidgets list.
      */
-    private final Vector childWidgetWrappers = new Vector();
+    private final Vector<WidgetWrapper> childWidgetWrappers = new Vector<WidgetWrapper>();
 
     /** Whether the component has spacing enabled. */
     private boolean hasComponentSpacing;
@@ -396,7 +397,7 @@ public class IOrderedLayout extends Panel implements Container,
         // Reinsert all widget wrappers to this container
         final int currentOrientationMode = orientationMode;
         for (int i = 0; i < childWidgetWrappers.size(); i++) {
-            WidgetWrapper wr = (WidgetWrapper) childWidgetWrappers.get(i);
+            WidgetWrapper wr = childWidgetWrappers.get(i);
             orientationMode = oldOrientationMode;
             tableMode = oldTableMode;
             Element oldWrElement = wr.getElementWrappingWidgetAndCaption();
@@ -1273,6 +1274,23 @@ public class IOrderedLayout extends Panel implements Container,
                         && margins.hasBottom() ? marginBottom + "px" : "");
             }
         }
+
+        public int getAllocatedHeight() {
+            if (lastForcedPixelHeight == -1) {
+                return -1;
+            }
+
+            int available = lastForcedPixelHeight;
+            // Must remove caption height to report correct size to child
+            if (caption != null) {
+                available -= caption.getOffsetHeight();
+            }
+            return available;
+        }
+
+        public int getAllocatedWidth() {
+            return lastForcedPixelWidth;
+        }
     }
 
     /* documented at super */
@@ -1310,7 +1328,7 @@ public class IOrderedLayout extends Panel implements Container,
             }
 
             final int removeFromIndex = childWidgets.indexOf(child);
-            final WidgetWrapper wrapper = (WidgetWrapper) childWidgetWrappers
+            final WidgetWrapper wrapper = childWidgetWrappers
                     .get(removeFromIndex);
             Element wrapperElement = wrapper.getElement();
             final int nonWidgetChildElements = DOM
@@ -1385,8 +1403,7 @@ public class IOrderedLayout extends Panel implements Container,
          * from the DOM.
          */
         final int index = childWidgets.indexOf(child);
-        final WidgetWrapper wrapper = (WidgetWrapper) childWidgetWrappers
-                .get(index);
+        final WidgetWrapper wrapper = childWidgetWrappers.get(index);
         DOM.removeChild(wrappedChildContainer, wrapper.getElement());
         childWidgetWrappers.remove(index);
 
@@ -1423,8 +1440,7 @@ public class IOrderedLayout extends Panel implements Container,
     public void updateCaption(Paintable component, UIDL uidl) {
         final int index = childWidgets.indexOf(component);
         if (index >= 0) {
-            ((WidgetWrapper) childWidgetWrappers.get(index)).updateCaption(
-                    uidl, component);
+            childWidgetWrappers.get(index).updateCaption(uidl, component);
         }
     }
 
@@ -1434,9 +1450,29 @@ public class IOrderedLayout extends Panel implements Container,
     }
 
     /* documented at super */
-    public void iLayout() {
+    public void iLayout(int availableWidth, int availableHeight) {
         updateChildSizes();
         Util.runDescendentsLayout(this);
         childLayoutsHaveChanged = false;
     }
+
+    public int getAllocatedHeight(Widget child) {
+        final int index = childWidgets.indexOf(child);
+        if (index >= 0) {
+            WidgetWrapper wrapper = childWidgetWrappers.get(index);
+            return wrapper.getAllocatedHeight();
+        }
+
+        return -1;
+    }
+
+    public int getAllocatedWidth(Widget child) {
+        final int index = childWidgets.indexOf(child);
+        if (index >= 0) {
+            WidgetWrapper wrapper = childWidgetWrappers.get(index);
+            return wrapper.getAllocatedWidth();
+        }
+
+        return -1;
+    }
 }
index b15ae537ecd2dc2523896973ddd46ba4994f2404..315d2d0d1a101184cfc0bd428d12c560e27c9c9a 100644 (file)
@@ -234,7 +234,7 @@ public class IPanel extends SimplePanel implements Paintable,
         }
     }
 
-    public void iLayout() {
+    public void iLayout(int availableWidth, int availableHeight) {
         iLayout(true);
     }
 
index 4b9e6051afdbfb6bc711f21777c4c092d48656fd..ccf2c7a0ff836f12cb84d0491bf07710bce63900 100644 (file)
@@ -656,7 +656,11 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
         initializedAndAttached = true;
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (height != null) {
             if (height.equals("100%")) {
                 /*
index a6d5b6e2a210cc80f553df1a0fda757a8181a865..196187b2e563b6d6999a744d969130289dc0b447 100644 (file)
@@ -391,7 +391,7 @@ public class ISlider extends Widget implements Paintable, Field,
         setValue(new Double(v), animate, roundup);\r
     }\r
 \r
-    public void iLayout() {\r
+    public void iLayout(int availableWidth, int availableHeight) {\r
         if (vertical) {\r
             setHeight();\r
         }\r
index 67f45d6ac8dbafddac2bac45a91be2daa2599ead..7e2acebb531e85768f76d7b5e25bb1814a5a8699 100644 (file)
@@ -183,12 +183,16 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
         iLayout();
     }
 
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
     /*
      * Calculates absolutely positioned container places/sizes (non-Javadoc)
      * 
      * @see com.itmill.toolkit.terminal.gwt.client.NeedsLayout#layout()
      */
-    public void iLayout() {
+    public void iLayout(int availableWidth, int availableHeight) {
         if (!isAttached()) {
             return;
         }
index 1a0eb557fc739696ddb577027ac344d14069cb62..566c81f8965fcc2efd81866f4bb9998675c7c675 100644 (file)
@@ -376,7 +376,11 @@ public class ITabsheet extends ITabsheetBase implements
         }
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (height != null && height != "") {
             super.setHeight(height);
 
index 8e2d874384f622ca47cca6250238c85ba3396b33..836b9b03d9cf3a5a47c9583d4c5a822cb012d0d7 100644 (file)
@@ -166,20 +166,36 @@ public class ITextField extends TextBoxBase implements Paintable, Field,
         }
     }
 
-    public void iLayout() {
+    private void iLayout() {
+        iLayout(-1, -1);
+    }
+
+    public void iLayout(int availableWidth, int availableHeight) {
         if (proportionalWidth >= 0) {
-            int availPixels = (int) (DOM.getElementPropertyInt(DOM
-                    .getParent(getElement()), "clientWidth") * proportionalWidth);
+            int availPixels = availableWidth;
+            if (availPixels < 0) {
+                availPixels = (DOM.getElementPropertyInt(DOM
+                        .getParent(getElement()), "clientWidth"));
+            }
+            availPixels *= proportionalWidth;
+
             availPixels -= getExtraHorizontalPixels();
             if (availPixels >= 0) {
                 super.setWidth(availPixels + "px");
             }
         }
         if (proportionalHeight >= 0) {
-            int availPixels = (int) (DOM.getElementPropertyInt(DOM
-                    .getParent(getElement()), "clientHeight") * proportionalHeight);
+            int availPixels = availableHeight;
+            if (availPixels < 0) {
+                availPixels = (DOM.getElementPropertyInt(DOM
+                        .getParent(getElement()), "clientHeight"));
+            }
+            availPixels *= proportionalHeight;
             availPixels -= getExtraVerticalPixels();
-            super.setHeight(availPixels + "px");
+
+            if (availPixels >= 0) {
+                super.setHeight(availPixels + "px");
+            }
         }
     }
 
index 46ae202986eac7a3cb349658b0f2cebe4e7f4eea..a115c238aeea4e4403ba56f8574f88ef9a0daed0 100644 (file)
@@ -272,7 +272,11 @@ public class ITextualDate extends IDateField implements Paintable, Field,
         return fieldExtraWidth;\r
     }\r
 \r
-    public void iLayout() {\r
+    private void iLayout() {\r
+        iLayout(-1, -1);\r
+    }\r
+\r
+    public void iLayout(int availableWidth, int availableHeight) {\r
         if (needLayout) {\r
             text.setWidth((getOffsetWidth() - getFieldExtraWidth()) + "px");\r
         }\r
index 7375e96eb12068797b67d848ea9929d8c9465eb9..87bb203924afc083ed719420ea4911aaab8f83af 100644 (file)
@@ -264,7 +264,7 @@ public class IAbsoluteGrid extends Composite implements
         }
     }
 
-    public void iLayout() {
+    public void iLayout(int availableWidth, int availableHeight) {
         boolean sizeChanged = false;
         int newWidth = getOffsetWidth();
         if (offsetWidth != newWidth) {