From 5050f9a4f2dfe23e8b9d67413eddf28771ede805 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Fri, 10 Feb 2012 14:02:59 +0200 Subject: [PATCH] Update CssLayout to work with CalculatingLayotus (#8313) This is the slowest GridLayout ever, as it measures an calculates even more than the version from Vaadin 6 --- .../terminal/gwt/client/ui/VGridLayout.java | 62 ++++++------------- .../gwt/client/ui/VGridLayoutPaintable.java | 28 ++++++++- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index f269a5d1a2..6285121901 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -19,16 +19,14 @@ 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.RenderSpace; import com.vaadin.terminal.gwt.client.StyleConstants; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer; -public class VGridLayout extends SimplePanel implements Container { +public class VGridLayout extends SimplePanel { public static final String CLASSNAME = "v-gridlayout"; @@ -48,9 +46,13 @@ public class VGridLayout extends SimplePanel implements Container { int[] columnWidths; int[] rowHeights; - private String height; + private int height; - private String width; + private int width; + + private boolean undefinedWidth; + + private boolean undefinedHeight; int[] colExpandRatioArray; @@ -123,7 +125,7 @@ public class VGridLayout extends SimplePanel implements Container { } void expandRows() { - if (!"".equals(height)) { + if (!isUndefinedHeight()) { int usedSpace = minRowHeights[0]; for (int i = 1; i < minRowHeights.length; i++) { usedSpace += spacingPixelsVertical + minRowHeights[i]; @@ -148,10 +150,9 @@ public class VGridLayout extends SimplePanel implements Container { } } - @Override - public void setHeight(String height) { - super.setHeight(height); - if (!height.equals(this.height)) { + void updateHeight(int height, boolean undefinedHeight) { + if (height != this.height || this.undefinedHeight != undefinedHeight) { + this.undefinedHeight = undefinedHeight; this.height = height; if (rendering) { sizeChangedDuringRendering = true; @@ -165,10 +166,9 @@ public class VGridLayout extends SimplePanel implements Container { } } - @Override - public void setWidth(String width) { - super.setWidth(width); - if (!width.equals(this.width)) { + void updateWidth(int width, boolean undefinedWidth) { + if (width != this.width || undefinedWidth != this.undefinedWidth) { + this.undefinedWidth = undefinedWidth; this.width = width; if (rendering) { sizeChangedDuringRendering = true; @@ -254,7 +254,7 @@ public class VGridLayout extends SimplePanel implements Container { for (Widget w : widgetToCell.keySet()) { client.handleComponentRelativeSize(w); } - if (heightChanged && "".equals(height)) { + if (heightChanged && isUndefinedHeight()) { Util.notifyParentOfSizeChange(this, false); } } @@ -262,7 +262,7 @@ public class VGridLayout extends SimplePanel implements Container { } void expandColumns() { - if (!"".equals(width)) { + if (!isUndefinedWidth()) { int usedSpace = minColumnWidths[0]; for (int i = 1; i < minColumnWidths.length; i++) { usedSpace += spacingPixelsHorizontal + minColumnWidths[i]; @@ -323,11 +323,11 @@ public class VGridLayout extends SimplePanel implements Container { } private boolean isUndefinedHeight() { - return "".equals(height); + return undefinedHeight; } private boolean isUndefinedWidth() { - return "".equals(width); + return undefinedWidth; } void renderRemainingComponents(LinkedList pendingCells) { @@ -561,31 +561,13 @@ public class VGridLayout extends SimplePanel implements Container { - canvas.getOffsetHeight(); } - public boolean hasChildComponent(Widget component) { - return widgetToCell.containsKey(component); - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - ChildComponentContainer componentContainer = widgetToComponentContainer - .remove(oldComponent); - if (componentContainer == null) { - return; - } - - componentContainer.setPaintable(VPaintableMap.get(client).getPaintable( - newComponent)); - widgetToComponentContainer.put(newComponent, componentContainer); - - widgetToCell.put(newComponent, widgetToCell.get(oldComponent)); - } - public boolean requestLayout(final Set changedChildren) { boolean needsLayout = false; boolean reDistributeColSpanWidths = false; boolean reDistributeRowSpanHeights = false; int offsetHeight = canvas.getOffsetHeight(); int offsetWidth = canvas.getOffsetWidth(); - if ("".equals(width) || "".equals(height)) { + if (isUndefinedWidth() || isUndefinedHeight()) { needsLayout = true; } ArrayList dirtyColumns = new ArrayList(); @@ -732,12 +714,6 @@ public class VGridLayout extends SimplePanel implements Container { } } - public RenderSpace getAllocatedSpace(Widget child) { - Cell cell = widgetToCell.get(child); - assert cell != null; - return cell.getAllocatedSpace(); - } - Cell[][] cells; /** diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java index c7e9f79d9a..a753a40377 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java @@ -3,7 +3,9 @@ */ package com.vaadin.terminal.gwt.client.ui; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -14,6 +16,7 @@ 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.CalculatingLayout; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableMap; @@ -21,7 +24,8 @@ 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 { +public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer + implements CalculatingLayout { private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( this, EventId.LAYOUT_CLICK) { @@ -38,7 +42,6 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer { }; @Override - @SuppressWarnings("unchecked") public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { getWidgetForPaintable().rendering = true; getWidgetForPaintable().client = client; @@ -195,4 +198,25 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer { return GWT.create(VGridLayout.class); } + public void updateVerticalSizes() { + int innerHeight = getMeasuredSize().getInnerHeight(); + getWidgetForPaintable().updateHeight(innerHeight, isUndefinedHeight()); + layoutAllChildren(); + } + + private void layoutAllChildren() { + HashSet childWidgets = new HashSet(); + Collection children = getChildren(); + for (VPaintableWidget vPaintableWidget : children) { + childWidgets.add(vPaintableWidget.getWidgetForPaintable()); + } + getWidgetForPaintable().requestLayout(childWidgets); + } + + public void updateHorizontalSizes() { + int innerWidth = getMeasuredSize().getInnerWidth(); + getWidgetForPaintable().updateWidth(innerWidth, isUndefinedWidth()); + + layoutAllChildren(); + } } -- 2.39.5