]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8324 Split VGridLayout, VHorizontalLayout and VVerticalLayout into
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 11:53:23 +0000 (13:53 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 13:08:33 +0000 (15:08 +0200)
paintable
and
widget

src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java
src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java [new file with mode: 0644]

index b37032e98765d73e35b93aed5cd000dedf1ba1d0..e6e167f07780015da9e29dde8f76cbb8c6d772d0 100644 (file)
@@ -14,16 +14,12 @@ import java.util.Set;
 
 import com.google.gwt.dom.client.DivElement;
 import com.google.gwt.dom.client.Document;
-import com.google.gwt.event.dom.client.DomEvent.Type;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.AbsolutePanel;
 import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.Container;
-import com.vaadin.terminal.gwt.client.EventId;
 import com.vaadin.terminal.gwt.client.RenderSpace;
 import com.vaadin.terminal.gwt.client.StyleConstants;
 import com.vaadin.terminal.gwt.client.UIDL;
@@ -33,59 +29,43 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget;
 import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout;
 import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;
 
-public class VGridLayout extends SimplePanel implements VPaintableWidget,
-        Container {
+public class VGridLayout extends SimplePanel implements Container {
 
     public static final String CLASSNAME = "v-gridlayout";
 
     private DivElement margin = Document.get().createDivElement();
 
-    private final AbsolutePanel canvas = new AbsolutePanel();
+    final AbsolutePanel canvas = new AbsolutePanel();
 
-    private ApplicationConnection client;
+    ApplicationConnection client;
 
     protected HashMap<Widget, ChildComponentContainer> widgetToComponentContainer = new HashMap<Widget, ChildComponentContainer>();
 
-    private HashMap<Widget, Cell> widgetToCell = new HashMap<Widget, Cell>();
+    HashMap<Widget, Cell> widgetToCell = new HashMap<Widget, Cell>();
 
     private int spacingPixelsHorizontal;
     private int spacingPixelsVertical;
 
-    private int[] columnWidths;
-    private int[] rowHeights;
+    int[] columnWidths;
+    int[] rowHeights;
 
     private String height;
 
     private String width;
 
-    private int[] colExpandRatioArray;
+    int[] colExpandRatioArray;
 
-    private int[] rowExpandRatioArray;
+    int[] rowExpandRatioArray;
 
-    private int[] minColumnWidths;
+    int[] minColumnWidths;
 
     private int[] minRowHeights;
 
-    private boolean rendering;
+    boolean rendering;
 
-    private HashMap<Widget, ChildComponentContainer> nonRenderedWidgets;
+    HashMap<Widget, ChildComponentContainer> nonRenderedWidgets;
 
-    private boolean sizeChangedDuringRendering = false;
-
-    private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
-            this, EventId.LAYOUT_CLICK) {
-
-        @Override
-        protected VPaintableWidget getChildComponent(Element element) {
-            return getComponent(element);
-        }
-
-        @Override
-        protected <H extends EventHandler> HandlerRegistration registerHandler(
-                H handler, Type<H> type) {
-            return addDomHandler(handler, type);
-        }
-    };
+    boolean sizeChangedDuringRendering = false;
 
     public VGridLayout() {
         super();
@@ -135,126 +115,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         return spacingPixelsVertical;
     }
 
-    @SuppressWarnings("unchecked")
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        rendering = true;
-        this.client = client;
-
-        if (client.updateComponent(this, uidl, true)) {
-            rendering = false;
-            return;
-        }
-        clickEventHandler.handleEventHandlerRegistration(client);
-
-        canvas.setWidth("0px");
-
-        handleMargins(uidl);
-        detectSpacing(uidl);
-
-        int cols = uidl.getIntAttribute("w");
-        int rows = uidl.getIntAttribute("h");
-
-        columnWidths = new int[cols];
-        rowHeights = new int[rows];
-
-        if (cells == null) {
-            cells = new Cell[cols][rows];
-        } else if (cells.length != cols || cells[0].length != rows) {
-            Cell[][] newCells = new Cell[cols][rows];
-            for (int i = 0; i < cells.length; i++) {
-                for (int j = 0; j < cells[i].length; j++) {
-                    if (i < cols && j < rows) {
-                        newCells[i][j] = cells[i][j];
-                    }
-                }
-            }
-            cells = newCells;
-        }
-
-        nonRenderedWidgets = (HashMap<Widget, ChildComponentContainer>) widgetToComponentContainer
-                .clone();
-
-        final int[] alignments = uidl.getIntArrayAttribute("alignments");
-        int alignmentIndex = 0;
-
-        LinkedList<Cell> pendingCells = new LinkedList<Cell>();
-
-        LinkedList<Cell> relativeHeighted = new LinkedList<Cell>();
-
-        for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
-            final UIDL r = (UIDL) i.next();
-            if ("gr".equals(r.getTag())) {
-                for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) {
-                    final UIDL c = (UIDL) j.next();
-                    if ("gc".equals(c.getTag())) {
-                        Cell cell = getCell(c);
-                        if (cell.hasContent()) {
-                            boolean rendered = cell.renderIfNoRelativeWidth();
-                            cell.alignment = alignments[alignmentIndex++];
-                            if (!rendered) {
-                                pendingCells.add(cell);
-                            }
-
-                            if (cell.colspan > 1) {
-                                storeColSpannedCell(cell);
-                            } else if (rendered) {
-                                // strore non-colspanned widths to columnWidth
-                                // array
-                                if (columnWidths[cell.col] < cell.getWidth()) {
-                                    columnWidths[cell.col] = cell.getWidth();
-                                }
-                            }
-                            if (cell.hasRelativeHeight()) {
-                                relativeHeighted.add(cell);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        colExpandRatioArray = uidl.getIntArrayAttribute("colExpand");
-        rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand");
-        distributeColSpanWidths();
-
-        minColumnWidths = cloneArray(columnWidths);
-        expandColumns();
-
-        renderRemainingComponentsWithNoRelativeHeight(pendingCells);
-
-        detectRowHeights();
-
-        expandRows();
-
-        renderRemainingComponents(pendingCells);
-
-        for (Cell cell : relativeHeighted) {
-            // rendering done above so cell.cc should not be null
-            Widget widget2 = cell.cc.getWidget();
-            client.handleComponentRelativeSize(widget2);
-            cell.cc.updateWidgetSize();
-        }
-
-        layoutCells();
-
-        // clean non rendered components
-        for (Widget w : nonRenderedWidgets.keySet()) {
-            ChildComponentContainer childComponentContainer = widgetToComponentContainer
-                    .get(w);
-            widgetToCell.remove(w);
-            widgetToComponentContainer.remove(w);
-            childComponentContainer.removeFromParent();
-            VPaintableMap paintableMap = VPaintableMap.get(client);
-            paintableMap.unregisterPaintable(paintableMap.getPaintable(w));
-        }
-        nonRenderedWidgets = null;
-
-        rendering = false;
-        sizeChangedDuringRendering = false;
-
-    }
-
-    private static int[] cloneArray(int[] toBeCloned) {
+    static int[] cloneArray(int[] toBeCloned) {
         int[] clone = new int[toBeCloned.length];
         for (int i = 0; i < clone.length; i++) {
             clone[i] = toBeCloned[i] * 1;
@@ -262,7 +123,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         return clone;
     }
 
-    private void expandRows() {
+    void expandRows() {
         if (!"".equals(height)) {
             int usedSpace = minRowHeights[0];
             for (int i = 1; i < minRowHeights.length; i++) {
@@ -401,7 +262,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         }
     }
 
-    private void expandColumns() {
+    void expandColumns() {
         if (!"".equals(width)) {
             int usedSpace = minColumnWidths[0];
             for (int i = 1; i < minColumnWidths.length; i++) {
@@ -428,7 +289,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         }
     }
 
-    private void layoutCells() {
+    void layoutCells() {
         int x = 0;
         int y = 0;
         for (int i = 0; i < cells.length; i++) {
@@ -470,13 +331,13 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         return "".equals(width);
     }
 
-    private void renderRemainingComponents(LinkedList<Cell> pendingCells) {
+    void renderRemainingComponents(LinkedList<Cell> pendingCells) {
         for (Cell cell : pendingCells) {
             cell.render();
         }
     }
 
-    private void detectRowHeights() {
+    void detectRowHeights() {
 
         // collect min rowheight from non-rowspanned cells
         for (int i = 0; i < cells.length; i++) {
@@ -531,7 +392,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         l.cells.add(cell);
     }
 
-    private void renderRemainingComponentsWithNoRelativeHeight(
+    void renderRemainingComponentsWithNoRelativeHeight(
             LinkedList<Cell> pendingCells) {
 
         for (Iterator<Cell> iterator = pendingCells.iterator(); iterator
@@ -549,7 +410,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
      * Iterates colspanned cells, ensures cols have enough space to accommodate
      * them
      */
-    private void distributeColSpanWidths() {
+    void distributeColSpanWidths() {
         for (SpanList list : colSpans) {
             for (Cell cell : list.cells) {
                 // cells with relative content may return non 0 here if on
@@ -643,7 +504,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         }
     }
 
-    private void storeColSpannedCell(Cell cell) {
+    void storeColSpannedCell(Cell cell) {
         SpanList l = null;
         for (SpanList list : colSpans) {
             if (list.span < cell.colspan) {
@@ -666,7 +527,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         l.cells.add(cell);
     }
 
-    private void detectSpacing(UIDL uidl) {
+    void detectSpacing(UIDL uidl) {
         DivElement spacingmeter = Document.get().createDivElement();
         spacingmeter.setClassName(CLASSNAME + "-" + "spacing-"
                 + (uidl.getBooleanAttribute("spacing") ? "on" : "off"));
@@ -678,7 +539,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         canvas.getElement().removeChild(spacingmeter);
     }
 
-    private void handleMargins(UIDL uidl) {
+    void handleMargins(UIDL uidl) {
         final VMarginInfo margins = new VMarginInfo(
                 uidl.getIntAttribute("margins"));
 
@@ -719,23 +580,6 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         widgetToCell.put(newComponent, widgetToCell.get(oldComponent));
     }
 
-    public void updateCaption(VPaintableWidget paintable, UIDL uidl) {
-        Widget widget = paintable.getWidgetForPaintable();
-        ChildComponentContainer cc = widgetToComponentContainer.get(widget);
-        if (cc != null) {
-            cc.updateCaption(uidl, client);
-        }
-        if (!rendering) {
-            // ensure rel size details are updated
-            widgetToCell.get(widget).updateRelSizeStatus(uidl);
-            /*
-             * This was a component-only update and the possible size change
-             * must be propagated to the layout
-             */
-            client.captionSizeUpdated(widget);
-        }
-    }
-
     public boolean requestLayout(final Set<Widget> changedChildren) {
         boolean needsLayout = false;
         boolean reDistributeColSpanWidths = false;
@@ -895,12 +739,12 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         return cell.getAllocatedSpace();
     }
 
-    private Cell[][] cells;
+    Cell[][] cells;
 
     /**
      * Private helper class.
      */
-    private class Cell {
+    class Cell {
         private boolean relHeight = false;
         private boolean relWidth = false;
         private boolean widthCanAffectHeight = false;
@@ -1109,7 +953,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
         }
     }
 
-    private Cell getCell(UIDL c) {
+    Cell getCell(UIDL c) {
         int row = c.getIntAttribute("y");
         int col = c.getIntAttribute("x");
         Cell cell = cells[col][row];
@@ -1132,7 +976,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget,
      * @return The Paintable which the element is a part of. Null if the element
      *         belongs to the layout and not to a child.
      */
-    private VPaintableWidget getComponent(Element element) {
+    VPaintableWidget getComponent(Element element) {
         return Util.getPaintableForElement(client, this, element);
     }
 
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
new file mode 100644 (file)
index 0000000..1ef9581
--- /dev/null
@@ -0,0 +1,193 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.event.dom.client.DomEvent.Type;\r
+import com.google.gwt.event.shared.EventHandler;\r
+import com.google.gwt.event.shared.HandlerRegistration;\r
+import com.google.gwt.user.client.Element;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.EventId;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableMap;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell;\r
+import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;\r
+\r
+public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer {\r
+    private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(\r
+            this, EventId.LAYOUT_CLICK) {\r
+\r
+        @Override\r
+        protected VPaintableWidget getChildComponent(Element element) {\r
+            return getWidgetForPaintable().getComponent(element);\r
+        }\r
+\r
+        @Override\r
+        protected <H extends EventHandler> HandlerRegistration registerHandler(\r
+                H handler, Type<H> type) {\r
+            return getWidgetForPaintable().addDomHandler(handler, type);\r
+        }\r
+    };\r
+\r
+    @SuppressWarnings("unchecked")\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().rendering = true;\r
+        getWidgetForPaintable().client = client;\r
+\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            getWidgetForPaintable().rendering = false;\r
+            return;\r
+        }\r
+        clickEventHandler.handleEventHandlerRegistration(client);\r
+\r
+        getWidgetForPaintable().canvas.setWidth("0px");\r
+\r
+        getWidgetForPaintable().handleMargins(uidl);\r
+        getWidgetForPaintable().detectSpacing(uidl);\r
+\r
+        int cols = uidl.getIntAttribute("w");\r
+        int rows = uidl.getIntAttribute("h");\r
+\r
+        getWidgetForPaintable().columnWidths = new int[cols];\r
+        getWidgetForPaintable().rowHeights = new int[rows];\r
+\r
+        if (getWidgetForPaintable().cells == null) {\r
+            getWidgetForPaintable().cells = new Cell[cols][rows];\r
+        } else if (getWidgetForPaintable().cells.length != cols\r
+                || getWidgetForPaintable().cells[0].length != rows) {\r
+            Cell[][] newCells = new Cell[cols][rows];\r
+            for (int i = 0; i < getWidgetForPaintable().cells.length; i++) {\r
+                for (int j = 0; j < getWidgetForPaintable().cells[i].length; j++) {\r
+                    if (i < cols && j < rows) {\r
+                        newCells[i][j] = getWidgetForPaintable().cells[i][j];\r
+                    }\r
+                }\r
+            }\r
+            getWidgetForPaintable().cells = newCells;\r
+        }\r
+\r
+        getWidgetForPaintable().nonRenderedWidgets = (HashMap<Widget, ChildComponentContainer>) getWidgetForPaintable().widgetToComponentContainer\r
+                .clone();\r
+\r
+        final int[] alignments = uidl.getIntArrayAttribute("alignments");\r
+        int alignmentIndex = 0;\r
+\r
+        LinkedList<Cell> pendingCells = new LinkedList<Cell>();\r
+\r
+        LinkedList<Cell> relativeHeighted = new LinkedList<Cell>();\r
+\r
+        for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {\r
+            final UIDL r = (UIDL) i.next();\r
+            if ("gr".equals(r.getTag())) {\r
+                for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) {\r
+                    final UIDL c = (UIDL) j.next();\r
+                    if ("gc".equals(c.getTag())) {\r
+                        Cell cell = getWidgetForPaintable().getCell(c);\r
+                        if (cell.hasContent()) {\r
+                            boolean rendered = cell.renderIfNoRelativeWidth();\r
+                            cell.alignment = alignments[alignmentIndex++];\r
+                            if (!rendered) {\r
+                                pendingCells.add(cell);\r
+                            }\r
+\r
+                            if (cell.colspan > 1) {\r
+                                getWidgetForPaintable().storeColSpannedCell(\r
+                                        cell);\r
+                            } else if (rendered) {\r
+                                // strore non-colspanned widths to columnWidth\r
+                                // array\r
+                                if (getWidgetForPaintable().columnWidths[cell.col] < cell\r
+                                        .getWidth()) {\r
+                                    getWidgetForPaintable().columnWidths[cell.col] = cell\r
+                                            .getWidth();\r
+                                }\r
+                            }\r
+                            if (cell.hasRelativeHeight()) {\r
+                                relativeHeighted.add(cell);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+        getWidgetForPaintable().colExpandRatioArray = uidl\r
+                .getIntArrayAttribute("colExpand");\r
+        getWidgetForPaintable().rowExpandRatioArray = uidl\r
+                .getIntArrayAttribute("rowExpand");\r
+        getWidgetForPaintable().distributeColSpanWidths();\r
+\r
+        getWidgetForPaintable().minColumnWidths = VGridLayout\r
+                .cloneArray(getWidgetForPaintable().columnWidths);\r
+        getWidgetForPaintable().expandColumns();\r
+\r
+        getWidgetForPaintable().renderRemainingComponentsWithNoRelativeHeight(\r
+                pendingCells);\r
+\r
+        getWidgetForPaintable().detectRowHeights();\r
+\r
+        getWidgetForPaintable().expandRows();\r
+\r
+        getWidgetForPaintable().renderRemainingComponents(pendingCells);\r
+\r
+        for (Cell cell : relativeHeighted) {\r
+            // rendering done above so cell.cc should not be null\r
+            Widget widget2 = cell.cc.getWidget();\r
+            client.handleComponentRelativeSize(widget2);\r
+            cell.cc.updateWidgetSize();\r
+        }\r
+\r
+        getWidgetForPaintable().layoutCells();\r
+\r
+        // clean non rendered components\r
+        for (Widget w : getWidgetForPaintable().nonRenderedWidgets.keySet()) {\r
+            ChildComponentContainer childComponentContainer = getWidgetForPaintable().widgetToComponentContainer\r
+                    .get(w);\r
+            getWidgetForPaintable().widgetToCell.remove(w);\r
+            getWidgetForPaintable().widgetToComponentContainer.remove(w);\r
+            childComponentContainer.removeFromParent();\r
+            VPaintableMap paintableMap = VPaintableMap.get(client);\r
+            paintableMap.unregisterPaintable(paintableMap.getPaintable(w));\r
+        }\r
+        getWidgetForPaintable().nonRenderedWidgets = null;\r
+\r
+        getWidgetForPaintable().rendering = false;\r
+        getWidgetForPaintable().sizeChangedDuringRendering = false;\r
+\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget paintable, UIDL uidl) {\r
+        Widget widget = paintable.getWidgetForPaintable();\r
+        ChildComponentContainer cc = getWidgetForPaintable().widgetToComponentContainer\r
+                .get(widget);\r
+        if (cc != null) {\r
+            cc.updateCaption(uidl, getConnection());\r
+        }\r
+        if (!getWidgetForPaintable().rendering) {\r
+            // ensure rel size details are updated\r
+            getWidgetForPaintable().widgetToCell.get(widget)\r
+                    .updateRelSizeStatus(uidl);\r
+            /*\r
+             * This was a component-only update and the possible size change\r
+             * must be propagated to the layout\r
+             */\r
+            getConnection().captionSizeUpdated(widget);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public VGridLayout getWidgetForPaintable() {\r
+        return (VGridLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VGridLayout.class);\r
+    }\r
+\r
+}\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java
new file mode 100644 (file)
index 0000000..b72f522
--- /dev/null
@@ -0,0 +1,17 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+\r
+public class VHorizontalLayoutPaintable extends VOrderedLayoutPaintable {\r
+\r
+    @Override\r
+    public VHorizontalLayout getWidgetForPaintable() {\r
+        return (VHorizontalLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected VHorizontalLayout createWidget() {\r
+        return GWT.create(VHorizontalLayout.class);\r
+    }\r
+\r
+}\r
index f490e5176dc0d5b9f0eb8ae135ea6275f153efba..9f5576dfaf34d2861a8c21fe47c7d4504fa0cf96 100644 (file)
@@ -9,15 +9,8 @@ import java.util.Set;
 
 import com.google.gwt.core.client.JsArrayString;
 import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.DomEvent.Type;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.EventId;
-import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
 import com.vaadin.terminal.gwt.client.RenderInformation.Size;
 import com.vaadin.terminal.gwt.client.RenderSpace;
 import com.vaadin.terminal.gwt.client.UIDL;
@@ -32,21 +25,18 @@ public class VOrderedLayout extends CellBasedLayout {
 
     public static final String CLASSNAME = "v-orderedlayout";
 
-    private int orientation;
-
-    // Can be removed once OrderedLayout is removed
-    private boolean allowOrientationUpdate = false;
+    int orientation;
 
     /**
      * Size of the layout excluding any margins.
      */
-    private Size activeLayoutSize = new Size(0, 0);
+    Size activeLayoutSize = new Size(0, 0);
 
-    private boolean isRendering = false;
+    boolean isRendering = false;
 
     private String width = "";
 
-    private boolean sizeHasChangedDuringRendering = false;
+    boolean sizeHasChangedDuringRendering = false;
 
     private ValueMap expandRatios;
 
@@ -56,24 +46,8 @@ public class VOrderedLayout extends CellBasedLayout {
 
     private ValueMap alignments;
 
-    private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
-            this, EventId.LAYOUT_CLICK) {
-
-        @Override
-        protected VPaintableWidget getChildComponent(Element element) {
-            return getComponent(element);
-        }
-
-        @Override
-        protected <H extends EventHandler> HandlerRegistration registerHandler(
-                H handler, Type<H> type) {
-            return addDomHandler(handler, type);
-        }
-    };
-
     public VOrderedLayout() {
         this(CLASSNAME, ORIENTATION_VERTICAL);
-        allowOrientationUpdate = true;
     }
 
     protected VOrderedLayout(String className, int orientation) {
@@ -87,195 +61,7 @@ public class VOrderedLayout extends CellBasedLayout {
         STYLENAME_MARGIN_LEFT = className + "-margin-left";
     }
 
-    @Override
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        isRendering = true;
-        super.updateFromUIDL(uidl, client);
-
-        // Only non-cached, visible UIDL:s can introduce changes
-        if (uidl.getBooleanAttribute("cached")
-                || uidl.getBooleanAttribute("invisible")) {
-            isRendering = false;
-            return;
-        }
-
-        clickEventHandler.handleEventHandlerRegistration(client);
-
-        if (allowOrientationUpdate) {
-            handleOrientationUpdate(uidl);
-        }
-
-        // IStopWatch w = new IStopWatch("OrderedLayout.updateFromUIDL");
-
-        ArrayList<Widget> uidlWidgets = new ArrayList<Widget>(
-                uidl.getChildCount());
-        ArrayList<ChildComponentContainer> relativeSizeComponents = new ArrayList<ChildComponentContainer>();
-        ArrayList<UIDL> relativeSizeComponentUIDL = new ArrayList<UIDL>();
-
-        int pos = 0;
-        for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {
-            final UIDL childUIDL = (UIDL) it.next();
-            final VPaintableWidget childPaintable = client
-                    .getPaintable(childUIDL);
-            Widget widget = childPaintable.getWidgetForPaintable();
-
-            // Create container for component
-            ChildComponentContainer childComponentContainer = getComponentContainer(widget);
-
-            if (childComponentContainer == null) {
-                // This is a new component
-                childComponentContainer = createChildContainer(childPaintable);
-            } else {
-                /*
-                 * The widget may be null if the same paintable has been
-                 * rendered in a different component container while this has
-                 * been invisible. Ensure the childComponentContainer has the
-                 * widget attached. See e.g. #5372
-                 */
-                childComponentContainer.setPaintable(childPaintable);
-            }
-
-            addOrMoveChild(childComponentContainer, pos++);
-
-            /*
-             * Components which are to be expanded in the same orientation as
-             * the layout are rendered later when it is clear how much space
-             * they can use
-             */
-            if (!Util.isCached(childUIDL)) {
-                FloatSize relativeSize = Util.parseRelativeSize(childUIDL);
-                childComponentContainer.setRelativeSize(relativeSize);
-            }
-
-            if (childComponentContainer.isComponentRelativeSized(orientation)) {
-                relativeSizeComponents.add(childComponentContainer);
-                relativeSizeComponentUIDL.add(childUIDL);
-            } else {
-                if (isDynamicWidth()) {
-                    childComponentContainer.renderChild(childUIDL, client, -1);
-                } else {
-                    childComponentContainer.renderChild(childUIDL, client,
-                            activeLayoutSize.getWidth());
-                }
-                if (sizeHasChangedDuringRendering && Util.isCached(childUIDL)) {
-                    // notify cached relative sized component about size
-                    // chance
-                    client.handleComponentRelativeSize(childComponentContainer
-                            .getWidget());
-                }
-            }
-
-            uidlWidgets.add(widget);
-
-        }
-
-        // w.mark("Rendering of "
-        // + (uidlWidgets.size() - relativeSizeComponents.size())
-        // + " absolute size components done");
-
-        /*
-         * Remove any children after pos. These are the ones that previously
-         * were in the layout but have now been removed
-         */
-        removeChildrenAfter(pos);
-
-        // w.mark("Old children removed");
-
-        /* Fetch alignments and expand ratio from UIDL */
-        updateAlignmentsAndExpandRatios(uidl, uidlWidgets);
-        // w.mark("Alignments and expand ratios updated");
-
-        /* Fetch widget sizes from rendered components */
-        updateWidgetSizes();
-        // w.mark("Widget sizes updated");
-
-        recalculateLayout();
-        // w.mark("Layout size calculated (" + activeLayoutSize +
-        // ") offsetSize: "
-        // + getOffsetWidth() + "," + getOffsetHeight());
-
-        /* Render relative size components */
-        for (int i = 0; i < relativeSizeComponents.size(); i++) {
-            ChildComponentContainer childComponentContainer = relativeSizeComponents
-                    .get(i);
-            UIDL childUIDL = relativeSizeComponentUIDL.get(i);
-
-            if (isDynamicWidth()) {
-                childComponentContainer.renderChild(childUIDL, client, -1);
-            } else {
-                childComponentContainer.renderChild(childUIDL, client,
-                        activeLayoutSize.getWidth());
-            }
-
-            if (Util.isCached(childUIDL)) {
-                /*
-                 * We must update the size of the relative sized component if
-                 * the expand ratio or something else in the layout changes
-                 * which affects the size of a relative sized component
-                 */
-                client.handleComponentRelativeSize(childComponentContainer
-                        .getWidget());
-            }
-
-            // childComponentContainer.updateWidgetSize();
-        }
-
-        // w.mark("Rendering of " + (relativeSizeComponents.size())
-        // + " relative size components done");
-
-        /* Fetch widget sizes for relative size components */
-        for (ChildComponentContainer childComponentContainer : widgetToComponentContainer
-                .values()) {
-
-            /* Update widget size from DOM */
-            childComponentContainer.updateWidgetSize();
-        }
-
-        // w.mark("Widget sizes updated");
-
-        /*
-         * Components with relative size in main direction may affect the layout
-         * size in the other direction
-         */
-        if ((isHorizontal() && isDynamicHeight())
-                || (isVertical() && isDynamicWidth())) {
-            layoutSizeMightHaveChanged();
-        }
-        // w.mark("Layout dimensions updated");
-
-        /* Update component spacing */
-        updateContainerMargins();
-
-        /*
-         * Update component sizes for components with relative size in non-main
-         * direction
-         */
-        if (updateRelativeSizesInNonMainDirection()) {
-            // Sizes updated - might affect the other dimension so we need to
-            // recheck the widget sizes and recalculate layout dimensions
-            updateWidgetSizes();
-            layoutSizeMightHaveChanged();
-        }
-        calculateAlignments();
-        // w.mark("recalculateComponentSizesAndAlignments done");
-
-        setRootSize();
-
-        if (BrowserInfo.get().isIE()) {
-            /*
-             * This should fix the issue with padding not always taken into
-             * account for the containers leading to no spacing between
-             * elements.
-             */
-            root.getStyle().setProperty("zoom", "1");
-        }
-
-        // w.mark("runDescendentsLayout done");
-        isRendering = false;
-        sizeHasChangedDuringRendering = false;
-    }
-
-    private void layoutSizeMightHaveChanged() {
+    void layoutSizeMightHaveChanged() {
         Size oldSize = new Size(activeLayoutSize.getWidth(),
                 activeLayoutSize.getHeight());
         calculateLayoutDimensions();
@@ -288,7 +74,7 @@ public class VOrderedLayout extends CellBasedLayout {
         }
     }
 
-    private void updateWidgetSizes() {
+    void updateWidgetSizes() {
         for (ChildComponentContainer childComponentContainer : widgetToComponentContainer
                 .values()) {
 
@@ -299,7 +85,7 @@ public class VOrderedLayout extends CellBasedLayout {
         }
     }
 
-    private void recalculateLayout() {
+    void recalculateLayout() {
 
         /* Calculate space for relative size components */
         int spaceForExpansion = calculateLayoutDimensions();
@@ -340,30 +126,13 @@ public class VOrderedLayout extends CellBasedLayout {
 
     }
 
-    private void handleOrientationUpdate(UIDL uidl) {
-        int newOrientation = ORIENTATION_VERTICAL;
-        if ("horizontal".equals(uidl.getStringAttribute("orientation"))) {
-            newOrientation = ORIENTATION_HORIZONTAL;
-        }
-
-        if (orientation != newOrientation) {
-            orientation = newOrientation;
-
-            for (ChildComponentContainer childComponentContainer : widgetToComponentContainer
-                    .values()) {
-                childComponentContainer.setOrientation(orientation);
-            }
-        }
-
-    }
-
     /**
      * Updated components with relative height in horizontal layouts and
      * components with relative width in vertical layouts. This is only needed
      * if the height (horizontal layout) or width (vertical layout) has not been
      * specified.
      */
-    private boolean updateRelativeSizesInNonMainDirection() {
+    boolean updateRelativeSizesInNonMainDirection() {
         int updateDirection = 1 - orientation;
         if ((updateDirection == ORIENTATION_HORIZONTAL && !isDynamicWidth())
                 || (updateDirection == ORIENTATION_VERTICAL && !isDynamicHeight())) {
@@ -468,7 +237,7 @@ public class VOrderedLayout extends CellBasedLayout {
         return widgetWidth;
     }
 
-    private void calculateAlignments() {
+    void calculateAlignments() {
         int w = 0;
         int h = 0;
 
@@ -676,7 +445,7 @@ public class VOrderedLayout extends CellBasedLayout {
      * Updates the spacing between components. Needs to be done only when
      * components are added/removed.
      */
-    private void updateContainerMargins() {
+    void updateContainerMargins() {
         ChildComponentContainer firstChildComponent = getFirstChildComponentContainer();
         if (firstChildComponent != null) {
             firstChildComponent.setMarginLeft(0);
@@ -697,15 +466,15 @@ public class VOrderedLayout extends CellBasedLayout {
         }
     }
 
-    private boolean isHorizontal() {
+    boolean isHorizontal() {
         return orientation == ORIENTATION_HORIZONTAL;
     }
 
-    private boolean isVertical() {
+    boolean isVertical() {
         return orientation == ORIENTATION_VERTICAL;
     }
 
-    private ChildComponentContainer createChildContainer(VPaintableWidget child) {
+    ChildComponentContainer createChildContainer(VPaintableWidget child) {
 
         // Create a container DIV for the child
         ChildComponentContainer childComponent = new ChildComponentContainer(
@@ -783,7 +552,7 @@ public class VOrderedLayout extends CellBasedLayout {
         setRootSize();
     }
 
-    private void setRootSize() {
+    void setRootSize() {
         root.getStyle().setPropertyPx("width", activeLayoutSize.getWidth());
         root.getStyle().setPropertyPx("height", activeLayoutSize.getHeight());
     }
@@ -942,19 +711,6 @@ public class VOrderedLayout extends CellBasedLayout {
         }
     }
 
-    public void updateCaption(VPaintableWidget paintable, UIDL uidl) {
-        Widget widget = paintable.getWidgetForPaintable();
-        ChildComponentContainer componentContainer = getComponentContainer(widget);
-        componentContainer.updateCaption(uidl, client);
-        if (!isRendering) {
-            /*
-             * This was a component-only update and the possible size change
-             * must be propagated to the layout
-             */
-            client.captionSizeUpdated(widget);
-        }
-    }
-
     /**
      * Returns the deepest nested child component which contains "element". The
      * child component is also returned if "element" is part of its caption.
@@ -965,7 +721,7 @@ public class VOrderedLayout extends CellBasedLayout {
      * @return The Paintable which the element is a part of. Null if the element
      *         belongs to the layout and not to a child.
      */
-    private VPaintableWidget getComponent(Element element) {
+    VPaintableWidget getComponent(Element element) {
         return Util.getPaintableForElement(client, this, element);
     }
 
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java
new file mode 100644 (file)
index 0000000..4720e07
--- /dev/null
@@ -0,0 +1,254 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+\r
+import com.google.gwt.event.dom.client.DomEvent.Type;\r
+import com.google.gwt.event.shared.EventHandler;\r
+import com.google.gwt.event.shared.HandlerRegistration;\r
+import com.google.gwt.user.client.Element;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.BrowserInfo;\r
+import com.vaadin.terminal.gwt.client.EventId;\r
+import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.Util;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayoutPaintable;\r
+import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;\r
+\r
+public abstract class VOrderedLayoutPaintable extends CellBasedLayoutPaintable {\r
+\r
+    private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(\r
+            this, EventId.LAYOUT_CLICK) {\r
+\r
+        @Override\r
+        protected VPaintableWidget getChildComponent(Element element) {\r
+            return getWidgetForPaintable().getComponent(element);\r
+        }\r
+\r
+        @Override\r
+        protected <H extends EventHandler> HandlerRegistration registerHandler(\r
+                H handler, Type<H> type) {\r
+            return getWidgetForPaintable().addDomHandler(handler, type);\r
+        }\r
+    };\r
+\r
+    public void updateCaption(VPaintableWidget paintable, UIDL uidl) {\r
+        Widget widget = paintable.getWidgetForPaintable();\r
+        ChildComponentContainer componentContainer = getWidgetForPaintable()\r
+                .getComponentContainer(widget);\r
+        componentContainer.updateCaption(uidl, getConnection());\r
+        if (!getWidgetForPaintable().isRendering) {\r
+            /*\r
+             * This was a component-only update and the possible size change\r
+             * must be propagated to the layout\r
+             */\r
+            getConnection().captionSizeUpdated(widget);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().isRendering = true;\r
+        super.updateFromUIDL(uidl, client);\r
+\r
+        // Only non-cached, visible UIDL:s can introduce changes\r
+        if (uidl.getBooleanAttribute("cached")\r
+                || uidl.getBooleanAttribute("invisible")) {\r
+            getWidgetForPaintable().isRendering = false;\r
+            return;\r
+        }\r
+\r
+        clickEventHandler.handleEventHandlerRegistration(client);\r
+\r
+        // IStopWatch w = new IStopWatch("OrderedLayout.updateFromUIDL");\r
+\r
+        ArrayList<Widget> uidlWidgets = new ArrayList<Widget>(\r
+                uidl.getChildCount());\r
+        ArrayList<ChildComponentContainer> relativeSizeComponents = new ArrayList<ChildComponentContainer>();\r
+        ArrayList<UIDL> relativeSizeComponentUIDL = new ArrayList<UIDL>();\r
+\r
+        int pos = 0;\r
+        for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {\r
+            final UIDL childUIDL = (UIDL) it.next();\r
+            final VPaintableWidget childPaintable = client\r
+                    .getPaintable(childUIDL);\r
+            Widget widget = childPaintable.getWidgetForPaintable();\r
+\r
+            // Create container for component\r
+            ChildComponentContainer childComponentContainer = getWidgetForPaintable()\r
+                    .getComponentContainer(widget);\r
+\r
+            if (childComponentContainer == null) {\r
+                // This is a new component\r
+                childComponentContainer = getWidgetForPaintable()\r
+                        .createChildContainer(childPaintable);\r
+            } else {\r
+                /*\r
+                 * The widget may be null if the same paintable has been\r
+                 * rendered in a different component container while this has\r
+                 * been invisible. Ensure the childComponentContainer has the\r
+                 * widget attached. See e.g. #5372\r
+                 */\r
+                childComponentContainer.setPaintable(childPaintable);\r
+            }\r
+\r
+            getWidgetForPaintable().addOrMoveChild(childComponentContainer,\r
+                    pos++);\r
+\r
+            /*\r
+             * Components which are to be expanded in the same orientation as\r
+             * the layout are rendered later when it is clear how much space\r
+             * they can use\r
+             */\r
+            if (!Util.isCached(childUIDL)) {\r
+                FloatSize relativeSize = Util.parseRelativeSize(childUIDL);\r
+                childComponentContainer.setRelativeSize(relativeSize);\r
+            }\r
+\r
+            if (childComponentContainer\r
+                    .isComponentRelativeSized(getWidgetForPaintable().orientation)) {\r
+                relativeSizeComponents.add(childComponentContainer);\r
+                relativeSizeComponentUIDL.add(childUIDL);\r
+            } else {\r
+                if (getWidgetForPaintable().isDynamicWidth()) {\r
+                    childComponentContainer.renderChild(childUIDL, client, -1);\r
+                } else {\r
+                    childComponentContainer\r
+                            .renderChild(childUIDL, client,\r
+                                    getWidgetForPaintable().activeLayoutSize\r
+                                            .getWidth());\r
+                }\r
+                if (getWidgetForPaintable().sizeHasChangedDuringRendering\r
+                        && Util.isCached(childUIDL)) {\r
+                    // notify cached relative sized component about size\r
+                    // chance\r
+                    client.handleComponentRelativeSize(childComponentContainer\r
+                            .getWidget());\r
+                }\r
+            }\r
+\r
+            uidlWidgets.add(widget);\r
+\r
+        }\r
+\r
+        // w.mark("Rendering of "\r
+        // + (uidlWidgets.size() - relativeSizeComponents.size())\r
+        // + " absolute size components done");\r
+\r
+        /*\r
+         * Remove any children after pos. These are the ones that previously\r
+         * were in the layout but have now been removed\r
+         */\r
+        getWidgetForPaintable().removeChildrenAfter(pos);\r
+\r
+        // w.mark("Old children removed");\r
+\r
+        /* Fetch alignments and expand ratio from UIDL */\r
+        getWidgetForPaintable().updateAlignmentsAndExpandRatios(uidl,\r
+                uidlWidgets);\r
+        // w.mark("Alignments and expand ratios updated");\r
+\r
+        /* Fetch widget sizes from rendered components */\r
+        getWidgetForPaintable().updateWidgetSizes();\r
+        // w.mark("Widget sizes updated");\r
+\r
+        getWidgetForPaintable().recalculateLayout();\r
+        // w.mark("Layout size calculated (" + activeLayoutSize +\r
+        // ") offsetSize: "\r
+        // + getOffsetWidth() + "," + getOffsetHeight());\r
+\r
+        /* Render relative size components */\r
+        for (int i = 0; i < relativeSizeComponents.size(); i++) {\r
+            ChildComponentContainer childComponentContainer = relativeSizeComponents\r
+                    .get(i);\r
+            UIDL childUIDL = relativeSizeComponentUIDL.get(i);\r
+\r
+            if (getWidgetForPaintable().isDynamicWidth()) {\r
+                childComponentContainer.renderChild(childUIDL, client, -1);\r
+            } else {\r
+                childComponentContainer.renderChild(childUIDL, client,\r
+                        getWidgetForPaintable().activeLayoutSize.getWidth());\r
+            }\r
+\r
+            if (Util.isCached(childUIDL)) {\r
+                /*\r
+                 * We must update the size of the relative sized component if\r
+                 * the expand ratio or something else in the layout changes\r
+                 * which affects the size of a relative sized component\r
+                 */\r
+                client.handleComponentRelativeSize(childComponentContainer\r
+                        .getWidget());\r
+            }\r
+\r
+            // childComponentContainer.updateWidgetSize();\r
+        }\r
+\r
+        // w.mark("Rendering of " + (relativeSizeComponents.size())\r
+        // + " relative size components done");\r
+\r
+        /* Fetch widget sizes for relative size components */\r
+        for (ChildComponentContainer childComponentContainer : getWidgetForPaintable()\r
+                .getComponentContainers()) {\r
+\r
+            /* Update widget size from DOM */\r
+            childComponentContainer.updateWidgetSize();\r
+        }\r
+\r
+        // w.mark("Widget sizes updated");\r
+\r
+        /*\r
+         * Components with relative size in main direction may affect the layout\r
+         * size in the other direction\r
+         */\r
+        if ((getWidgetForPaintable().isHorizontal() && getWidgetForPaintable()\r
+                .isDynamicHeight())\r
+                || (getWidgetForPaintable().isVertical() && getWidgetForPaintable()\r
+                        .isDynamicWidth())) {\r
+            getWidgetForPaintable().layoutSizeMightHaveChanged();\r
+        }\r
+        // w.mark("Layout dimensions updated");\r
+\r
+        /* Update component spacing */\r
+        getWidgetForPaintable().updateContainerMargins();\r
+\r
+        /*\r
+         * Update component sizes for components with relative size in non-main\r
+         * direction\r
+         */\r
+        if (getWidgetForPaintable().updateRelativeSizesInNonMainDirection()) {\r
+            // Sizes updated - might affect the other dimension so we need to\r
+            // recheck the widget sizes and recalculate layout dimensions\r
+            getWidgetForPaintable().updateWidgetSizes();\r
+            getWidgetForPaintable().layoutSizeMightHaveChanged();\r
+        }\r
+        getWidgetForPaintable().calculateAlignments();\r
+        // w.mark("recalculateComponentSizesAndAlignments done");\r
+\r
+        getWidgetForPaintable().setRootSize();\r
+\r
+        if (BrowserInfo.get().isIE()) {\r
+            /*\r
+             * This should fix the issue with padding not always taken into\r
+             * account for the containers leading to no spacing between\r
+             * elements.\r
+             */\r
+            getWidgetForPaintable().root.getStyle().setProperty("zoom", "1");\r
+        }\r
+\r
+        // w.mark("runDescendentsLayout done");\r
+        getWidgetForPaintable().isRendering = false;\r
+        getWidgetForPaintable().sizeHasChangedDuringRendering = false;\r
+    }\r
+\r
+    @Override\r
+    protected abstract VOrderedLayout createWidget();\r
+\r
+    @Override\r
+    public VOrderedLayout getWidgetForPaintable() {\r
+        return (VOrderedLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+}\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java
new file mode 100644 (file)
index 0000000..5378218
--- /dev/null
@@ -0,0 +1,17 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+\r
+public class VVerticalLayoutPaintable extends VOrderedLayoutPaintable {\r
+\r
+    @Override\r
+    public VVerticalLayout getWidgetForPaintable() {\r
+        return (VVerticalLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected VVerticalLayout createWidget() {\r
+        return GWT.create(VVerticalLayout.class);\r
+    }\r
+\r
+}\r
index 85f48859a403703f7739c905d2da0251fb891e1f..9b38ba23aeda3133e53fbf56dab4f01e69d06778 100644 (file)
@@ -3,6 +3,7 @@
  */
 package com.vaadin.terminal.gwt.client.ui.layout;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -17,7 +18,6 @@ import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
 import com.vaadin.terminal.gwt.client.Container;
-import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.VPaintableMap;
 import com.vaadin.terminal.gwt.client.VPaintableWidget;
 import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
@@ -28,7 +28,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
 
     protected ApplicationConnection client = null;
 
-    protected DivElement root;
+    public DivElement root;
 
     public static final int ORIENTATION_VERTICAL = 0;
     public static final int ORIENTATION_HORIZONTAL = 1;
@@ -40,15 +40,15 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
     protected final Spacing spacingFromCSS = new Spacing(12, 12);
     protected final Spacing activeSpacing = new Spacing(0, 0);
 
-    private boolean dynamicWidth;
+    boolean dynamicWidth;
 
-    private boolean dynamicHeight;
+    boolean dynamicHeight;
 
     private final DivElement clearElement = Document.get().createDivElement();
 
     private String lastStyleName = "";
 
-    private boolean marginsNeedsRecalculation = false;
+    boolean marginsNeedsRecalculation = false;
 
     protected String STYLENAME_SPACING = "";
     protected String STYLENAME_MARGIN_TOP = "";
@@ -105,32 +105,6 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
         return widgetToComponentContainer.containsKey(component);
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        this.client = client;
-
-        // Only non-cached UIDL:s can introduce changes
-        if (uidl.getBooleanAttribute("cached")) {
-            return;
-        }
-
-        /**
-         * Margin and spacind detection depends on classNames and must be set
-         * before setting size. Here just update the details from UIDL and from
-         * overridden setStyleName run actual margin detections.
-         */
-        updateMarginAndSpacingInfo(uidl);
-
-        /*
-         * This call should be made first. Ensure correct implementation, handle
-         * size etc.
-         */
-        if (client.updateComponent(this, uidl, true)) {
-            return;
-        }
-
-        handleDynamicDimensions(uidl);
-    }
-
     @Override
     public void setStyleName(String styleName) {
         super.setStyleName(styleName);
@@ -159,27 +133,6 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
         }
     }
 
-    private void handleDynamicDimensions(UIDL uidl) {
-        String w = uidl.hasAttribute("width") ? uidl
-                .getStringAttribute("width") : "";
-
-        String h = uidl.hasAttribute("height") ? uidl
-                .getStringAttribute("height") : "";
-
-        if (w.equals("")) {
-            dynamicWidth = true;
-        } else {
-            dynamicWidth = false;
-        }
-
-        if (h.equals("")) {
-            dynamicHeight = true;
-        } else {
-            dynamicHeight = false;
-        }
-
-    }
-
     @Override
     public void setHeight(String height) {
         super.setHeight(height);
@@ -195,7 +148,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
         }
     }
 
-    protected void addOrMoveChild(ChildComponentContainer childComponent,
+    public void addOrMoveChild(ChildComponentContainer childComponent,
             int position) {
         if (childComponent.getParent() == this) {
             if (getWidgetIndex(childComponent) != position) {
@@ -235,33 +188,22 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
 
     }
 
-    protected ChildComponentContainer getComponentContainer(Widget child) {
+    public Collection<ChildComponentContainer> getComponentContainers() {
+        return widgetToComponentContainer.values();
+    }
+
+    public ChildComponentContainer getComponentContainer(Widget child) {
         return widgetToComponentContainer.get(child);
     }
 
-    protected boolean isDynamicWidth() {
+    public boolean isDynamicWidth() {
         return dynamicWidth;
     }
 
-    protected boolean isDynamicHeight() {
+    public boolean isDynamicHeight() {
         return dynamicHeight;
     }
 
-    private void updateMarginAndSpacingInfo(UIDL uidl) {
-        if (!uidl.hasAttribute("invisible")) {
-            int bitMask = uidl.getIntAttribute("margins");
-            if (activeMarginsInfo.getBitMask() != bitMask) {
-                activeMarginsInfo = new VMarginInfo(bitMask);
-                marginsNeedsRecalculation = true;
-            }
-            boolean spacing = uidl.getBooleanAttribute("spacing");
-            if (spacing != spacingEnabled) {
-                marginsNeedsRecalculation = true;
-                spacingEnabled = spacing;
-            }
-        }
-    }
-
     private static DivElement measurement;
     private static DivElement measurement2;
     private static DivElement measurement3;
@@ -342,7 +284,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container
         return (ChildComponentContainer) getChildren().get(0);
     }
 
-    protected void removeChildrenAfter(int pos) {
+    public void removeChildrenAfter(int pos) {
         // Remove all children after position "pos" but leave the clear element
         // in place
 
diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java
new file mode 100644 (file)
index 0000000..e994253
--- /dev/null
@@ -0,0 +1,81 @@
+package com.vaadin.terminal.gwt.client.ui.layout;\r
+\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;\r
+import com.vaadin.terminal.gwt.client.ui.VMarginInfo;\r
+\r
+public abstract class CellBasedLayoutPaintable extends\r
+        VAbstractPaintableWidgetContainer {\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().client = client;\r
+\r
+        // Only non-cached UIDL:s can introduce changes\r
+        if (uidl.getBooleanAttribute("cached")) {\r
+            return;\r
+        }\r
+\r
+        /**\r
+         * Margin and spacind detection depends on classNames and must be set\r
+         * before setting size. Here just update the details from UIDL and from\r
+         * overridden setStyleName run actual margin detections.\r
+         */\r
+        updateMarginAndSpacingInfo(uidl);\r
+\r
+        /*\r
+         * This call should be made first. Ensure correct implementation, handle\r
+         * size etc.\r
+         */\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            return;\r
+        }\r
+\r
+        handleDynamicDimensions(uidl);\r
+    }\r
+\r
+    private void handleDynamicDimensions(UIDL uidl) {\r
+        String w = uidl.hasAttribute("width") ? uidl\r
+                .getStringAttribute("width") : "";\r
+\r
+        String h = uidl.hasAttribute("height") ? uidl\r
+                .getStringAttribute("height") : "";\r
+\r
+        if (w.equals("")) {\r
+            getWidgetForPaintable().dynamicWidth = true;\r
+        } else {\r
+            getWidgetForPaintable().dynamicWidth = false;\r
+        }\r
+\r
+        if (h.equals("")) {\r
+            getWidgetForPaintable().dynamicHeight = true;\r
+        } else {\r
+            getWidgetForPaintable().dynamicHeight = false;\r
+        }\r
+\r
+    }\r
+\r
+    void updateMarginAndSpacingInfo(UIDL uidl) {\r
+        if (!uidl.hasAttribute("invisible")) {\r
+            int bitMask = uidl.getIntAttribute("margins");\r
+            if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) {\r
+                getWidgetForPaintable().activeMarginsInfo = new VMarginInfo(\r
+                        bitMask);\r
+                getWidgetForPaintable().marginsNeedsRecalculation = true;\r
+            }\r
+            boolean spacing = uidl.getBooleanAttribute("spacing");\r
+            if (spacing != getWidgetForPaintable().spacingEnabled) {\r
+                getWidgetForPaintable().marginsNeedsRecalculation = true;\r
+                getWidgetForPaintable().spacingEnabled = spacing;\r
+            }\r
+        }\r
+    }\r
+\r
+    @Override\r
+    protected abstract CellBasedLayout createWidget();\r
+\r
+    @Override\r
+    public CellBasedLayout getWidgetForPaintable() {\r
+        return (CellBasedLayout) super.getWidgetForPaintable();\r
+    }\r
+}\r