From ee3849e150e8d6c221bf06b09634f9b4bee1c351 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 31 Jan 2012 13:53:23 +0200 Subject: [PATCH] #8324 Split VGridLayout, VHorizontalLayout and VVerticalLayout into paintable and widget --- .../terminal/gwt/client/ui/VGridLayout.java | 210 ++------------ .../gwt/client/ui/VGridLayoutPaintable.java | 193 ++++++++++++ .../client/ui/VHorizontalLayoutPaintable.java | 17 ++ .../gwt/client/ui/VOrderedLayout.java | 274 +----------------- .../client/ui/VOrderedLayoutPaintable.java | 254 ++++++++++++++++ .../client/ui/VVerticalLayoutPaintable.java | 17 ++ .../gwt/client/ui/layout/CellBasedLayout.java | 86 +----- .../ui/layout/CellBasedLayoutPaintable.java | 81 ++++++ 8 files changed, 618 insertions(+), 514 deletions(-) create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index b37032e987..e6e167f077 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -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 widgetToComponentContainer = new HashMap(); - private HashMap widgetToCell = new HashMap(); + HashMap widgetToCell = new HashMap(); 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 nonRenderedWidgets; + HashMap 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 HandlerRegistration registerHandler( - H handler, Type 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) widgetToComponentContainer - .clone(); - - final int[] alignments = uidl.getIntArrayAttribute("alignments"); - int alignmentIndex = 0; - - LinkedList pendingCells = new LinkedList(); - - LinkedList relativeHeighted = new LinkedList(); - - 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 pendingCells) { + void renderRemainingComponents(LinkedList 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 pendingCells) { for (Iterator 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 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 index 0000000000..1ef958183b --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java @@ -0,0 +1,193 @@ +package com.vaadin.terminal.gwt.client.ui; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; + +import com.google.gwt.core.client.GWT; +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.EventId; +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.VGridLayout.Cell; +import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer; + +public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer { + private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( + this, EventId.LAYOUT_CLICK) { + + @Override + protected VPaintableWidget getChildComponent(Element element) { + return getWidgetForPaintable().getComponent(element); + } + + @Override + protected HandlerRegistration registerHandler( + H handler, Type type) { + return getWidgetForPaintable().addDomHandler(handler, type); + } + }; + + @SuppressWarnings("unchecked") + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + getWidgetForPaintable().rendering = true; + getWidgetForPaintable().client = client; + + if (client.updateComponent(this, uidl, true)) { + getWidgetForPaintable().rendering = false; + return; + } + clickEventHandler.handleEventHandlerRegistration(client); + + getWidgetForPaintable().canvas.setWidth("0px"); + + getWidgetForPaintable().handleMargins(uidl); + getWidgetForPaintable().detectSpacing(uidl); + + int cols = uidl.getIntAttribute("w"); + int rows = uidl.getIntAttribute("h"); + + getWidgetForPaintable().columnWidths = new int[cols]; + getWidgetForPaintable().rowHeights = new int[rows]; + + if (getWidgetForPaintable().cells == null) { + getWidgetForPaintable().cells = new Cell[cols][rows]; + } else if (getWidgetForPaintable().cells.length != cols + || getWidgetForPaintable().cells[0].length != rows) { + Cell[][] newCells = new Cell[cols][rows]; + for (int i = 0; i < getWidgetForPaintable().cells.length; i++) { + for (int j = 0; j < getWidgetForPaintable().cells[i].length; j++) { + if (i < cols && j < rows) { + newCells[i][j] = getWidgetForPaintable().cells[i][j]; + } + } + } + getWidgetForPaintable().cells = newCells; + } + + getWidgetForPaintable().nonRenderedWidgets = (HashMap) getWidgetForPaintable().widgetToComponentContainer + .clone(); + + final int[] alignments = uidl.getIntArrayAttribute("alignments"); + int alignmentIndex = 0; + + LinkedList pendingCells = new LinkedList(); + + LinkedList relativeHeighted = new LinkedList(); + + 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 = getWidgetForPaintable().getCell(c); + if (cell.hasContent()) { + boolean rendered = cell.renderIfNoRelativeWidth(); + cell.alignment = alignments[alignmentIndex++]; + if (!rendered) { + pendingCells.add(cell); + } + + if (cell.colspan > 1) { + getWidgetForPaintable().storeColSpannedCell( + cell); + } else if (rendered) { + // strore non-colspanned widths to columnWidth + // array + if (getWidgetForPaintable().columnWidths[cell.col] < cell + .getWidth()) { + getWidgetForPaintable().columnWidths[cell.col] = cell + .getWidth(); + } + } + if (cell.hasRelativeHeight()) { + relativeHeighted.add(cell); + } + } + } + } + } + } + + getWidgetForPaintable().colExpandRatioArray = uidl + .getIntArrayAttribute("colExpand"); + getWidgetForPaintable().rowExpandRatioArray = uidl + .getIntArrayAttribute("rowExpand"); + getWidgetForPaintable().distributeColSpanWidths(); + + getWidgetForPaintable().minColumnWidths = VGridLayout + .cloneArray(getWidgetForPaintable().columnWidths); + getWidgetForPaintable().expandColumns(); + + getWidgetForPaintable().renderRemainingComponentsWithNoRelativeHeight( + pendingCells); + + getWidgetForPaintable().detectRowHeights(); + + getWidgetForPaintable().expandRows(); + + getWidgetForPaintable().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(); + } + + getWidgetForPaintable().layoutCells(); + + // clean non rendered components + for (Widget w : getWidgetForPaintable().nonRenderedWidgets.keySet()) { + ChildComponentContainer childComponentContainer = getWidgetForPaintable().widgetToComponentContainer + .get(w); + getWidgetForPaintable().widgetToCell.remove(w); + getWidgetForPaintable().widgetToComponentContainer.remove(w); + childComponentContainer.removeFromParent(); + VPaintableMap paintableMap = VPaintableMap.get(client); + paintableMap.unregisterPaintable(paintableMap.getPaintable(w)); + } + getWidgetForPaintable().nonRenderedWidgets = null; + + getWidgetForPaintable().rendering = false; + getWidgetForPaintable().sizeChangedDuringRendering = false; + + } + + public void updateCaption(VPaintableWidget paintable, UIDL uidl) { + Widget widget = paintable.getWidgetForPaintable(); + ChildComponentContainer cc = getWidgetForPaintable().widgetToComponentContainer + .get(widget); + if (cc != null) { + cc.updateCaption(uidl, getConnection()); + } + if (!getWidgetForPaintable().rendering) { + // ensure rel size details are updated + getWidgetForPaintable().widgetToCell.get(widget) + .updateRelSizeStatus(uidl); + /* + * This was a component-only update and the possible size change + * must be propagated to the layout + */ + getConnection().captionSizeUpdated(widget); + } + } + + @Override + public VGridLayout getWidgetForPaintable() { + return (VGridLayout) super.getWidgetForPaintable(); + } + + @Override + protected Widget createWidget() { + return GWT.create(VGridLayout.class); + } + +} 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 index 0000000000..b72f5222cc --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java @@ -0,0 +1,17 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; + +public class VHorizontalLayoutPaintable extends VOrderedLayoutPaintable { + + @Override + public VHorizontalLayout getWidgetForPaintable() { + return (VHorizontalLayout) super.getWidgetForPaintable(); + } + + @Override + protected VHorizontalLayout createWidget() { + return GWT.create(VHorizontalLayout.class); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java index f490e5176d..9f5576dfaf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java @@ -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 HandlerRegistration registerHandler( - H handler, Type 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 uidlWidgets = new ArrayList( - uidl.getChildCount()); - ArrayList relativeSizeComponents = new ArrayList(); - ArrayList relativeSizeComponentUIDL = new ArrayList(); - - int pos = 0; - for (final Iterator 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 index 0000000000..4720e07099 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java @@ -0,0 +1,254 @@ +package com.vaadin.terminal.gwt.client.ui; + +import java.util.ArrayList; +import java.util.Iterator; + +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.UIDL; +import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VPaintableWidget; +import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayoutPaintable; +import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer; + +public abstract class VOrderedLayoutPaintable extends CellBasedLayoutPaintable { + + private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( + this, EventId.LAYOUT_CLICK) { + + @Override + protected VPaintableWidget getChildComponent(Element element) { + return getWidgetForPaintable().getComponent(element); + } + + @Override + protected HandlerRegistration registerHandler( + H handler, Type type) { + return getWidgetForPaintable().addDomHandler(handler, type); + } + }; + + public void updateCaption(VPaintableWidget paintable, UIDL uidl) { + Widget widget = paintable.getWidgetForPaintable(); + ChildComponentContainer componentContainer = getWidgetForPaintable() + .getComponentContainer(widget); + componentContainer.updateCaption(uidl, getConnection()); + if (!getWidgetForPaintable().isRendering) { + /* + * This was a component-only update and the possible size change + * must be propagated to the layout + */ + getConnection().captionSizeUpdated(widget); + } + } + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + getWidgetForPaintable().isRendering = true; + super.updateFromUIDL(uidl, client); + + // Only non-cached, visible UIDL:s can introduce changes + if (uidl.getBooleanAttribute("cached") + || uidl.getBooleanAttribute("invisible")) { + getWidgetForPaintable().isRendering = false; + return; + } + + clickEventHandler.handleEventHandlerRegistration(client); + + // IStopWatch w = new IStopWatch("OrderedLayout.updateFromUIDL"); + + ArrayList uidlWidgets = new ArrayList( + uidl.getChildCount()); + ArrayList relativeSizeComponents = new ArrayList(); + ArrayList relativeSizeComponentUIDL = new ArrayList(); + + int pos = 0; + for (final Iterator 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 = getWidgetForPaintable() + .getComponentContainer(widget); + + if (childComponentContainer == null) { + // This is a new component + childComponentContainer = getWidgetForPaintable() + .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); + } + + getWidgetForPaintable().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(getWidgetForPaintable().orientation)) { + relativeSizeComponents.add(childComponentContainer); + relativeSizeComponentUIDL.add(childUIDL); + } else { + if (getWidgetForPaintable().isDynamicWidth()) { + childComponentContainer.renderChild(childUIDL, client, -1); + } else { + childComponentContainer + .renderChild(childUIDL, client, + getWidgetForPaintable().activeLayoutSize + .getWidth()); + } + if (getWidgetForPaintable().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 + */ + getWidgetForPaintable().removeChildrenAfter(pos); + + // w.mark("Old children removed"); + + /* Fetch alignments and expand ratio from UIDL */ + getWidgetForPaintable().updateAlignmentsAndExpandRatios(uidl, + uidlWidgets); + // w.mark("Alignments and expand ratios updated"); + + /* Fetch widget sizes from rendered components */ + getWidgetForPaintable().updateWidgetSizes(); + // w.mark("Widget sizes updated"); + + getWidgetForPaintable().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 (getWidgetForPaintable().isDynamicWidth()) { + childComponentContainer.renderChild(childUIDL, client, -1); + } else { + childComponentContainer.renderChild(childUIDL, client, + getWidgetForPaintable().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 : getWidgetForPaintable() + .getComponentContainers()) { + + /* 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 ((getWidgetForPaintable().isHorizontal() && getWidgetForPaintable() + .isDynamicHeight()) + || (getWidgetForPaintable().isVertical() && getWidgetForPaintable() + .isDynamicWidth())) { + getWidgetForPaintable().layoutSizeMightHaveChanged(); + } + // w.mark("Layout dimensions updated"); + + /* Update component spacing */ + getWidgetForPaintable().updateContainerMargins(); + + /* + * Update component sizes for components with relative size in non-main + * direction + */ + if (getWidgetForPaintable().updateRelativeSizesInNonMainDirection()) { + // Sizes updated - might affect the other dimension so we need to + // recheck the widget sizes and recalculate layout dimensions + getWidgetForPaintable().updateWidgetSizes(); + getWidgetForPaintable().layoutSizeMightHaveChanged(); + } + getWidgetForPaintable().calculateAlignments(); + // w.mark("recalculateComponentSizesAndAlignments done"); + + getWidgetForPaintable().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. + */ + getWidgetForPaintable().root.getStyle().setProperty("zoom", "1"); + } + + // w.mark("runDescendentsLayout done"); + getWidgetForPaintable().isRendering = false; + getWidgetForPaintable().sizeHasChangedDuringRendering = false; + } + + @Override + protected abstract VOrderedLayout createWidget(); + + @Override + public VOrderedLayout getWidgetForPaintable() { + return (VOrderedLayout) super.getWidgetForPaintable(); + } + +} 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 index 0000000000..5378218ece --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java @@ -0,0 +1,17 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; + +public class VVerticalLayoutPaintable extends VOrderedLayoutPaintable { + + @Override + public VVerticalLayout getWidgetForPaintable() { + return (VVerticalLayout) super.getWidgetForPaintable(); + } + + @Override + protected VVerticalLayout createWidget() { + return GWT.create(VVerticalLayout.class); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java index 85f48859a4..9b38ba23ae 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java @@ -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 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 index 0000000000..e99425311b --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java @@ -0,0 +1,81 @@ +package com.vaadin.terminal.gwt.client.ui.layout; + +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer; +import com.vaadin.terminal.gwt.client.ui.VMarginInfo; + +public abstract class CellBasedLayoutPaintable extends + VAbstractPaintableWidgetContainer { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + getWidgetForPaintable().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); + } + + private void handleDynamicDimensions(UIDL uidl) { + String w = uidl.hasAttribute("width") ? uidl + .getStringAttribute("width") : ""; + + String h = uidl.hasAttribute("height") ? uidl + .getStringAttribute("height") : ""; + + if (w.equals("")) { + getWidgetForPaintable().dynamicWidth = true; + } else { + getWidgetForPaintable().dynamicWidth = false; + } + + if (h.equals("")) { + getWidgetForPaintable().dynamicHeight = true; + } else { + getWidgetForPaintable().dynamicHeight = false; + } + + } + + void updateMarginAndSpacingInfo(UIDL uidl) { + if (!uidl.hasAttribute("invisible")) { + int bitMask = uidl.getIntAttribute("margins"); + if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) { + getWidgetForPaintable().activeMarginsInfo = new VMarginInfo( + bitMask); + getWidgetForPaintable().marginsNeedsRecalculation = true; + } + boolean spacing = uidl.getBooleanAttribute("spacing"); + if (spacing != getWidgetForPaintable().spacingEnabled) { + getWidgetForPaintable().marginsNeedsRecalculation = true; + getWidgetForPaintable().spacingEnabled = spacing; + } + } + } + + @Override + protected abstract CellBasedLayout createWidget(); + + @Override + public CellBasedLayout getWidgetForPaintable() { + return (CellBasedLayout) super.getWidgetForPaintable(); + } +} -- 2.39.5