package com.vaadin.terminal.gwt.client.ui;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
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.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
-public class VAbsoluteLayout extends ComplexPanel implements Container {
+public class VAbsoluteLayout extends ComplexPanel {
/** Tag name for widget creation */
public static final String TAGNAME = "absolutelayout";
protected final Element canvas = DOM.createDiv();
- // private int excessPixelsHorizontal;
- //
- // private int excessPixelsVertical;
-
private Object previousStyleName;
Map<String, AbsoluteWrapper> pidToComponentWrappper = new HashMap<String, AbsoluteWrapper>();
protected ApplicationConnection client;
- boolean rendering;
-
public VAbsoluteLayout() {
setElement(Document.get().createDivElement());
setStyleName(CLASSNAME);
getElement().appendChild(marginElement);
}
- public RenderSpace getAllocatedSpace(Widget child) {
- // TODO needs some special handling for components with only on edge
- // horizontally or vertically defined
- AbsoluteWrapper wrapper = (AbsoluteWrapper) child.getParent();
- int w;
- if (wrapper.left != null && wrapper.right != null) {
- w = wrapper.getOffsetWidth();
- } else if (wrapper.right != null) {
- // left == null
- // available width == right edge == offsetleft + width
- w = wrapper.getOffsetWidth() + wrapper.getElement().getOffsetLeft();
- } else {
- // left != null && right == null || left == null &&
- // right == null
- // available width == canvas width - offset left
- w = canvas.getOffsetWidth() - wrapper.getElement().getOffsetLeft();
- }
- int h;
- if (wrapper.top != null && wrapper.bottom != null) {
- h = wrapper.getOffsetHeight();
- } else if (wrapper.bottom != null) {
- // top not defined, available space 0... bottom of wrapper
- h = wrapper.getElement().getOffsetTop() + wrapper.getOffsetHeight();
- } else {
- // top defined or both undefined, available space == canvas - top
- h = canvas.getOffsetHeight() - wrapper.getElement().getOffsetTop();
- }
-
- return new RenderSpace(w, h);
- }
-
- public boolean hasChildComponent(Widget component) {
- for (Iterator<Entry<String, AbsoluteWrapper>> iterator = pidToComponentWrappper
- .entrySet().iterator(); iterator.hasNext();) {
- if (iterator.next().getValue().paintable == component) {
- return true;
- }
- }
- return false;
- }
-
- public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
- for (Widget wrapper : getChildren()) {
- AbsoluteWrapper w = (AbsoluteWrapper) wrapper;
- if (w.getWidget() == oldComponent) {
- w.setWidget(newComponent);
- return;
- }
- }
- }
-
- public boolean requestLayout(Set<Widget> children) {
- // component inside an absolute panel never affects parent nor the
- // layout
- return true;
- }
-
AbsoluteWrapper getWrapper(ApplicationConnection client, UIDL componentUIDL) {
AbsoluteWrapper wrapper = pidToComponentWrappper.get(componentUIDL
.getId());
super.add(child, canvas);
}
- @Override
- public void setStyleName(String style) {
- super.setStyleName(style);
- if (previousStyleName == null || !previousStyleName.equals(style)) {
- // excessPixelsHorizontal = -1;
- // excessPixelsVertical = -1;
- }
- }
-
@Override
public void setWidth(String width) {
super.setWidth(width);
// TODO do this so that canvas gets the sized properly (the area
// inside marginals)
canvas.getStyle().setProperty("width", width);
-
- if (!rendering) {
- relayoutRelativeChildren();
- }
- }
-
- private void relayoutRelativeChildren() {
- for (Widget widget : getChildren()) {
- if (widget instanceof AbsoluteWrapper) {
- AbsoluteWrapper w = (AbsoluteWrapper) widget;
- client.handleComponentRelativeSize(w.getWidget());
- w.updateCaptionPosition();
- }
- }
}
@Override
// TODO do this so that canvas gets the sized properly (the area
// inside marginals)
canvas.getStyle().setProperty("height", height);
-
- if (!rendering) {
- relayoutRelativeChildren();
- }
}
public class AbsoluteWrapper extends SimplePanel {
private String css;
- private String left;
- private String top;
- private String right;
- private String bottom;
+ String left;
+ String top;
+ String right;
+ String bottom;
private String zIndex;
private VPaintableWidget paintable;
updateCaptionPosition();
}
- private void updateCaptionPosition() {
+ void updateCaptionPosition() {
if (caption != null) {
Style style = caption.getElement().getStyle();
style.setProperty("position", "absolute");
import java.util.Iterator;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style;
+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.CalculatingLayout;
import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper;
-public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer {
+public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer
+ implements CalculatingLayout {
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
this, EventId.LAYOUT_CLICK) {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- getWidgetForPaintable().rendering = true;
getWidgetForPaintable().client = client;
// TODO margin handling
super.updateFromUIDL(uidl, client);
if (!isRealUpdate(uidl)) {
- getWidgetForPaintable().rendering = false;
return;
}
getWidgetForPaintable().pidToComponentWrappper.remove(pid);
absoluteWrapper.destroy();
}
- getWidgetForPaintable().rendering = false;
}
public void updateCaption(VPaintableWidget component, UIDL uidl) {
public VAbsoluteLayout getWidgetForPaintable() {
return (VAbsoluteLayout) super.getWidgetForPaintable();
}
+
+ public void updateVerticalSizes() {
+ VAbsoluteLayout layout = getWidgetForPaintable();
+ for (VPaintableWidget paintable : getChildren()) {
+ Widget widget = paintable.getWidgetForPaintable();
+ AbsoluteWrapper wrapper = (AbsoluteWrapper) widget.getParent();
+ Style wrapperStyle = wrapper.getElement().getStyle();
+
+ if (paintable.isRelativeHeight()) {
+ int h;
+ if (wrapper.top != null && wrapper.bottom != null) {
+ h = wrapper.getOffsetHeight();
+ } else if (wrapper.bottom != null) {
+ // top not defined, available space 0... bottom of
+ // wrapper
+ h = wrapper.getElement().getOffsetTop()
+ + wrapper.getOffsetHeight();
+ } else {
+ // top defined or both undefined, available space ==
+ // canvas - top
+ h = layout.canvas.getOffsetHeight()
+ - wrapper.getElement().getOffsetTop();
+ }
+ wrapperStyle.setHeight(h, Unit.PX);
+ } else {
+ wrapperStyle.clearHeight();
+ }
+
+ wrapper.updateCaptionPosition();
+ }
+ }
+
+ public void updateHorizontalSizes() {
+ VAbsoluteLayout layout = getWidgetForPaintable();
+ for (VPaintableWidget paintable : getChildren()) {
+ Widget widget = paintable.getWidgetForPaintable();
+ AbsoluteWrapper wrapper = (AbsoluteWrapper) widget.getParent();
+ Style wrapperStyle = wrapper.getElement().getStyle();
+
+ if (paintable.isRelativeWidth()) {
+ int w;
+ if (wrapper.left != null && wrapper.right != null) {
+ w = wrapper.getOffsetWidth();
+ } else if (wrapper.right != null) {
+ // left == null
+ // available width == right edge == offsetleft + width
+ w = wrapper.getOffsetWidth()
+ + wrapper.getElement().getOffsetLeft();
+ } else {
+ // left != null && right == null || left == null &&
+ // right == null
+ // available width == canvas width - offset left
+ w = layout.canvas.getOffsetWidth()
+ - wrapper.getElement().getOffsetLeft();
+ }
+ wrapperStyle.setWidth(w, Unit.PX);
+ } else {
+ wrapperStyle.clearWidth();
+ }
+
+ wrapper.updateCaptionPosition();
+ }
+ }
}