import java.util.Set;
import com.google.gwt.dom.client.Style;
-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.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;
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.EventId;
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.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ValueMap;
-public class VCssLayout extends SimplePanel implements VPaintableWidget,
- Container {
+public class VCssLayout extends SimplePanel {
public static final String TAGNAME = "csslayout";
public static final String CLASSNAME = "v-" + TAGNAME;
- private FlowPane panel = new FlowPane();
+ FlowPane panel = new FlowPane();
- private Element margin = DOM.createDiv();
-
- private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
- this, EventId.LAYOUT_CLICK) {
-
- @Override
- protected VPaintableWidget getChildComponent(Element element) {
- return panel.getComponent(element);
- }
-
- @Override
- protected <H extends EventHandler> HandlerRegistration registerHandler(
- H handler, Type<H> type) {
- return addDomHandler(handler, type);
- }
- };
+ Element margin = DOM.createDiv();
private boolean hasHeight;
private boolean hasWidth;
- private boolean rendering;
+ boolean rendering;
public VCssLayout() {
super();
}
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- rendering = true;
-
- if (client.updateComponent(this, uidl, true)) {
- rendering = false;
- return;
- }
- clickEventHandler.handleEventHandlerRegistration(client);
-
- final VMarginInfo margins = new VMarginInfo(
- uidl.getIntAttribute("margins"));
- setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP,
- margins.hasTop());
- setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT,
- margins.hasRight());
- setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_BOTTOM,
- margins.hasBottom());
- setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_LEFT,
- margins.hasLeft());
-
- setStyleName(margin, CLASSNAME + "-" + "spacing",
- uidl.hasAttribute("spacing"));
- panel.updateFromUIDL(uidl, client);
- rendering = false;
- }
-
public boolean hasChildComponent(Widget component) {
return panel.hasChildComponent(component);
}
panel.replaceChildComponent(oldComponent, newComponent);
}
- public void updateCaption(VPaintableWidget component, UIDL uidl) {
- panel.updateCaption(component, uidl);
- }
-
public class FlowPane extends FlowPanel {
private final HashMap<Widget, VCaption> widgetToCaption = new HashMap<Widget, VCaption>();
}
}
- private VPaintableWidget getComponent(Element element) {
+ VPaintableWidget getComponent(Element element) {
return Util
.getPaintableForElement(client, VCssLayout.this, element);
}
public Widget getWidgetForPaintable() {
return this;
}
+
+ /**
+ * Sets CSS classes for margin and spacing based on the given parameters.
+ *
+ * @param margins
+ * A {@link VMarginInfo} object that provides info on
+ * top/left/bottom/right margins
+ * @param spacing
+ * true to enable spacing, false otherwise
+ */
+ protected void setMarginAndSpacingStyles(VMarginInfo margins,
+ boolean spacing) {
+ setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ + StyleConstants.MARGIN_TOP, margins.hasTop());
+ setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ + StyleConstants.MARGIN_RIGHT, margins.hasRight());
+ setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ + StyleConstants.MARGIN_BOTTOM, margins.hasBottom());
+ setStyleName(margin, VCssLayout.CLASSNAME + "-"
+ + StyleConstants.MARGIN_LEFT, margins.hasLeft());
+
+ setStyleName(margin, VCssLayout.CLASSNAME + "-" + "spacing", spacing);
+
+ }
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\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.VPaintableWidget;\r
+\r
+public class VCssLayoutPaintable extends VAbstractPaintableWidgetContainer {\r
+\r
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(\r
+ this, EventId.LAYOUT_CLICK) {\r
+\r
+ @Override\r
+ protected VPaintableWidget getChildComponent(Element element) {\r
+ return getWidgetForPaintable().panel.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 updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ getWidgetForPaintable().rendering = true;\r
+\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ getWidgetForPaintable().rendering = false;\r
+ return;\r
+ }\r
+ clickEventHandler.handleEventHandlerRegistration(client);\r
+\r
+ getWidgetForPaintable().setMarginAndSpacingStyles(\r
+ new VMarginInfo(uidl.getIntAttribute("margins")),\r
+ uidl.hasAttribute("spacing"));\r
+ getWidgetForPaintable().panel.updateFromUIDL(uidl, client);\r
+ getWidgetForPaintable().rendering = false;\r
+ }\r
+\r
+ @Override\r
+ public VCssLayout getWidgetForPaintable() {\r
+ return (VCssLayout) super.getWidgetForPaintable();\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VCssLayout.class);\r
+ }\r
+\r
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+ getWidgetForPaintable().panel.updateCaption(component, uidl);\r
+ }\r
+\r
+}\r