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";
int[] columnWidths;
int[] rowHeights;
- private String height;
+ private int height;
- private String width;
+ private int width;
+
+ private boolean undefinedWidth;
+
+ private boolean undefinedHeight;
int[] colExpandRatioArray;
}
void expandRows() {
- if (!"".equals(height)) {
+ if (!isUndefinedHeight()) {
int usedSpace = minRowHeights[0];
for (int i = 1; i < minRowHeights.length; i++) {
usedSpace += spacingPixelsVertical + minRowHeights[i];
}
}
- @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;
}
}
- @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;
for (Widget w : widgetToCell.keySet()) {
client.handleComponentRelativeSize(w);
}
- if (heightChanged && "".equals(height)) {
+ if (heightChanged && isUndefinedHeight()) {
Util.notifyParentOfSizeChange(this, false);
}
}
}
void expandColumns() {
- if (!"".equals(width)) {
+ if (!isUndefinedWidth()) {
int usedSpace = minColumnWidths[0];
for (int i = 1; i < minColumnWidths.length; i++) {
usedSpace += spacingPixelsHorizontal + minColumnWidths[i];
}
private boolean isUndefinedHeight() {
- return "".equals(height);
+ return undefinedHeight;
}
private boolean isUndefinedWidth() {
- return "".equals(width);
+ return undefinedWidth;
}
void renderRemainingComponents(LinkedList<Cell> pendingCells) {
- 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<Widget> 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<Integer> dirtyColumns = new ArrayList<Integer>();
}
}
- public RenderSpace getAllocatedSpace(Widget child) {
- Cell cell = widgetToCell.get(child);
- assert cell != null;
- return cell.getAllocatedSpace();
- }
-
Cell[][] cells;
/**
*/
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;
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;
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) {
};
@Override
- @SuppressWarnings("unchecked")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
getWidgetForPaintable().rendering = true;
getWidgetForPaintable().client = client;
return GWT.create(VGridLayout.class);
}
+ public void updateVerticalSizes() {
+ int innerHeight = getMeasuredSize().getInnerHeight();
+ getWidgetForPaintable().updateHeight(innerHeight, isUndefinedHeight());
+ layoutAllChildren();
+ }
+
+ private void layoutAllChildren() {
+ HashSet<Widget> childWidgets = new HashSet<Widget>();
+ Collection<VPaintableWidget> 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();
+ }
}