]> source.dussan.org Git - vaadin-framework.git/commitdiff
Created VAbstractPaintableWidget
authorArtur Signell <artur@vaadin.com>
Mon, 23 Jan 2012 12:22:45 +0000 (14:22 +0200)
committerArtur Signell <artur@vaadin.com>
Mon, 23 Jan 2012 12:22:45 +0000 (14:22 +0200)
Moved VLabel* to own package

src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VLabel.java [deleted file]
src/com/vaadin/terminal/gwt/client/ui/VLabelPaintable.java [deleted file]
src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/label/VLabelPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/Label.java

diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
new file mode 100644 (file)
index 0000000..dff5a28
--- /dev/null
@@ -0,0 +1,49 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public abstract class VAbstractPaintableWidget implements VPaintableWidget {\r
+\r
+    private Widget widget;\r
+\r
+    /**\r
+     * Default constructor\r
+     */\r
+    public VAbstractPaintableWidget() {\r
+    }\r
+\r
+    /**\r
+     * Creates and returns the widget for this VPaintableWidget. This method\r
+     * should only be called once when initializing the paintable.\r
+     * \r
+     * @return\r
+     */\r
+    protected Widget createWidget() {\r
+        return GWT.create(getWidgetClass());\r
+    }\r
+\r
+    /**\r
+     * Returns the widget associated with this paintable. The widget returned by\r
+     * this method must not changed during the life time of the paintable.\r
+     * \r
+     * @return The widget associated with this paintable\r
+     */\r
+    public Widget getWidgetForPaintable() {\r
+        if (widget == null) {\r
+            widget = createWidget();\r
+        }\r
+\r
+        return widget;\r
+    }\r
+\r
+    /**\r
+     * Returns the class of the widget for this paintable. Used to instansiate\r
+     * the widget.\r
+     * \r
+     * @return The widget class.\r
+     */\r
+    protected abstract Class<? extends Widget> getWidgetClass();\r
+\r
+}\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLabel.java b/src/com/vaadin/terminal/gwt/client/ui/VLabel.java
deleted file mode 100644 (file)
index f259d03..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/* 
-@VaadinApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.ui.HTML;
-import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.Util;
-import com.vaadin.terminal.gwt.client.VTooltip;
-
-public class VLabel extends HTML {
-
-    public static final String CLASSNAME = "v-label";
-    private static final String CLASSNAME_UNDEFINED_WIDTH = "v-label-undef-w";
-
-    private int verticalPaddingBorder = 0;
-    private int horizontalPaddingBorder = 0;
-
-    public VLabel() {
-        super();
-        setStyleName(CLASSNAME);
-        sinkEvents(VTooltip.TOOLTIP_EVENTS);
-    }
-
-    public VLabel(String text) {
-        super(text);
-        setStyleName(CLASSNAME);
-        sinkEvents(VTooltip.TOOLTIP_EVENTS);
-    }
-
-    @Override
-    public void onBrowserEvent(Event event) {
-        super.onBrowserEvent(event);
-        if (event.getTypeInt() == Event.ONLOAD) {
-            // FIXME: Should not be here but in paintable
-            Util.notifyParentOfSizeChange(this, true);
-            event.cancelBubble(true);
-            return;
-        }
-        // FIXME: Move to paintable
-        // if (client != null) {
-        // client.handleTooltipEvent(event, this);
-        // }
-    }
-
-    @Override
-    public void setHeight(String height) {
-        verticalPaddingBorder = Util.setHeightExcludingPaddingAndBorder(this,
-                height, verticalPaddingBorder);
-    }
-
-    @Override
-    public void setWidth(String width) {
-        horizontalPaddingBorder = Util.setWidthExcludingPaddingAndBorder(this,
-                width, horizontalPaddingBorder);
-        if (width == null || width.equals("")) {
-            setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, true);
-        } else {
-            setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, false);
-        }
-    }
-
-    @Override
-    public void setText(String text) {
-        if (BrowserInfo.get().isIE8()) {
-            // #3983 - IE8 incorrectly replaces \n with <br> so we do the
-            // escaping manually and set as HTML
-            super.setHTML(Util.escapeHTML(text));
-        } else {
-            super.setText(text);
-        }
-    }
-}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLabelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VLabelPaintable.java
deleted file mode 100644 (file)
index 12f2c63..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*\r
-@VaadinApache2LicenseForJavaFiles@\r
- */\r
-package com.vaadin.terminal.gwt.client.ui;\r
-\r
-import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.dom.client.Document;\r
-import com.google.gwt.dom.client.PreElement;\r
-import com.google.gwt.event.dom.client.ClickEvent;\r
-import com.google.gwt.event.dom.client.ClickHandler;\r
-import com.google.gwt.event.dom.client.KeyDownEvent;\r
-import com.google.gwt.event.dom.client.KeyDownHandler;\r
-import com.google.gwt.event.dom.client.MouseMoveEvent;\r
-import com.google.gwt.event.dom.client.MouseMoveHandler;\r
-import com.google.gwt.event.dom.client.MouseOutEvent;\r
-import com.google.gwt.event.dom.client.MouseOutHandler;\r
-import com.google.gwt.event.dom.client.MouseOverEvent;\r
-import com.google.gwt.event.dom.client.MouseOverHandler;\r
-import com.google.gwt.user.client.ui.Widget;\r
-import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
-import com.vaadin.terminal.gwt.client.UIDL;\r
-import com.vaadin.terminal.gwt.client.Util;\r
-import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
-\r
-public class VLabelPaintable implements VPaintableWidget {\r
-\r
-    private VLabel widget = GWT.create(VLabel.class);\r
-    private ApplicationConnection client;\r
-\r
-    class TooltipHandler implements ClickHandler, KeyDownHandler,\r
-            MouseOverHandler, MouseOutHandler, MouseMoveHandler {\r
-\r
-        public void onClick(ClickEvent event) {\r
-            // TODO Auto-generated method stub\r
-\r
-        }\r
-\r
-        public void onMouseMove(MouseMoveEvent event) {\r
-            // TODO Auto-generated method stub\r
-\r
-        }\r
-\r
-        public void onMouseOut(MouseOutEvent event) {\r
-            // TODO Auto-generated method stub\r
-\r
-        }\r
-\r
-        public void onMouseOver(MouseOverEvent event) {\r
-            // TODO Auto-generated method stub\r
-\r
-        }\r
-\r
-        public void onKeyDown(KeyDownEvent event) {\r
-            // TODO Auto-generated method stub\r
-\r
-        }\r
-\r
-    }\r
-\r
-    public VLabelPaintable() {\r
-        TooltipHandler handler = new TooltipHandler();\r
-\r
-        widget.addDomHandler(handler, ClickEvent.getType());\r
-        widget.addDomHandler(handler, KeyDownEvent.getType());\r
-        widget.addDomHandler(handler, MouseOverEvent.getType());\r
-        widget.addDomHandler(handler, MouseOutEvent.getType());\r
-        widget.addDomHandler(handler, MouseMoveEvent.getType());\r
-\r
-    }\r
-\r
-    public VLabel getWidget() {\r
-        return widget;\r
-    }\r
-\r
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
-\r
-        if (client.updateComponent(getWidget(), uidl, true)) {\r
-            return;\r
-        }\r
-\r
-        this.client = client;\r
-\r
-        boolean sinkOnloads = false;\r
-\r
-        final String mode = uidl.getStringAttribute("mode");\r
-        if (mode == null || "text".equals(mode)) {\r
-            getWidget().setText(uidl.getChildString(0));\r
-        } else if ("pre".equals(mode)) {\r
-            PreElement preElement = Document.get().createPreElement();\r
-            preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0));\r
-            // clear existing content\r
-            getWidget().setHTML("");\r
-            // add preformatted text to dom\r
-            getWidget().getElement().appendChild(preElement);\r
-        } else if ("uidl".equals(mode)) {\r
-            getWidget().setHTML(uidl.getChildrenAsXML());\r
-        } else if ("xhtml".equals(mode)) {\r
-            UIDL content = uidl.getChildUIDL(0).getChildUIDL(0);\r
-            if (content.getChildCount() > 0) {\r
-                getWidget().setHTML(content.getChildString(0));\r
-            } else {\r
-                getWidget().setHTML("");\r
-            }\r
-            sinkOnloads = true;\r
-        } else if ("xml".equals(mode)) {\r
-            getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0));\r
-        } else if ("raw".equals(mode)) {\r
-            getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0));\r
-            sinkOnloads = true;\r
-        } else {\r
-            getWidget().setText("");\r
-        }\r
-        if (sinkOnloads) {\r
-            Util.sinkOnloadForImages(getWidget().getElement());\r
-        }\r
-    }\r
-\r
-    public Widget getWidgetForPaintable() {\r
-        return getWidget();\r
-    }\r
-\r
-}\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java b/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java
new file mode 100644 (file)
index 0000000..09f4352
--- /dev/null
@@ -0,0 +1,75 @@
+/* 
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.ui.label;
+
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VTooltip;
+
+public class VLabel extends HTML {
+
+    public static final String CLASSNAME = "v-label";
+    private static final String CLASSNAME_UNDEFINED_WIDTH = "v-label-undef-w";
+
+    private int verticalPaddingBorder = 0;
+    private int horizontalPaddingBorder = 0;
+
+    public VLabel() {
+        super();
+        setStyleName(CLASSNAME);
+        sinkEvents(VTooltip.TOOLTIP_EVENTS);
+    }
+
+    public VLabel(String text) {
+        super(text);
+        setStyleName(CLASSNAME);
+        sinkEvents(VTooltip.TOOLTIP_EVENTS);
+    }
+
+    @Override
+    public void onBrowserEvent(Event event) {
+        super.onBrowserEvent(event);
+        if (event.getTypeInt() == Event.ONLOAD) {
+            // FIXME: Should not be here but in paintable
+            Util.notifyParentOfSizeChange(this, true);
+            event.cancelBubble(true);
+            return;
+        }
+        // FIXME: Move to paintable
+        // if (client != null) {
+        // client.handleTooltipEvent(event, this);
+        // }
+    }
+
+    @Override
+    public void setHeight(String height) {
+        verticalPaddingBorder = Util.setHeightExcludingPaddingAndBorder(this,
+                height, verticalPaddingBorder);
+    }
+
+    @Override
+    public void setWidth(String width) {
+        horizontalPaddingBorder = Util.setWidthExcludingPaddingAndBorder(this,
+                width, horizontalPaddingBorder);
+        if (width == null || width.equals("")) {
+            setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, true);
+        } else {
+            setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, false);
+        }
+    }
+
+    @Override
+    public void setText(String text) {
+        if (BrowserInfo.get().isIE8()) {
+            // #3983 - IE8 incorrectly replaces \n with <br> so we do the
+            // escaping manually and set as HTML
+            super.setHTML(Util.escapeHTML(text));
+        } else {
+            super.setText(text);
+        }
+    }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/VLabelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/label/VLabelPaintable.java
new file mode 100644 (file)
index 0000000..796bce2
--- /dev/null
@@ -0,0 +1,71 @@
+/*\r
+@VaadinApache2LicenseForJavaFiles@\r
+ */\r
+package com.vaadin.terminal.gwt.client.ui.label;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.dom.client.Document;\r
+import com.google.gwt.dom.client.PreElement;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.Util;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public class VLabelPaintable implements VPaintableWidget {\r
+\r
+    private VLabel widget = GWT.create(VLabel.class);\r
+    private ApplicationConnection client;\r
+\r
+    public VLabelPaintable() {\r
+    }\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+\r
+        if (client.updateComponent(getWidgetForPaintable(), uidl, true)) {\r
+            return;\r
+        }\r
+\r
+        this.client = client;\r
+\r
+        boolean sinkOnloads = false;\r
+\r
+        final String mode = uidl.getStringAttribute("mode");\r
+        if (mode == null || "text".equals(mode)) {\r
+            getWidgetForPaintable().setText(uidl.getChildString(0));\r
+        } else if ("pre".equals(mode)) {\r
+            PreElement preElement = Document.get().createPreElement();\r
+            preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0));\r
+            // clear existing content\r
+            getWidgetForPaintable().setHTML("");\r
+            // add preformatted text to dom\r
+            getWidgetForPaintable().getElement().appendChild(preElement);\r
+        } else if ("uidl".equals(mode)) {\r
+            getWidgetForPaintable().setHTML(uidl.getChildrenAsXML());\r
+        } else if ("xhtml".equals(mode)) {\r
+            UIDL content = uidl.getChildUIDL(0).getChildUIDL(0);\r
+            if (content.getChildCount() > 0) {\r
+                getWidgetForPaintable().setHTML(content.getChildString(0));\r
+            } else {\r
+                getWidgetForPaintable().setHTML("");\r
+            }\r
+            sinkOnloads = true;\r
+        } else if ("xml".equals(mode)) {\r
+            getWidgetForPaintable().setHTML(\r
+                    uidl.getChildUIDL(0).getChildString(0));\r
+        } else if ("raw".equals(mode)) {\r
+            getWidgetForPaintable().setHTML(\r
+                    uidl.getChildUIDL(0).getChildString(0));\r
+            sinkOnloads = true;\r
+        } else {\r
+            getWidgetForPaintable().setText("");\r
+        }\r
+        if (sinkOnloads) {\r
+            Util.sinkOnloadForImages(getWidgetForPaintable().getElement());\r
+        }\r
+    }\r
+\r
+    public VLabel getWidgetForPaintable() {\r
+        return widget;\r
+    }\r
+\r
+}\r
index 29eb6df766d8f0b5042b1dad0cae67e43ff19391..576bbd967f9f7b03f6c5e2201d3af05cad4bdc84 100644 (file)
@@ -10,7 +10,7 @@ import com.vaadin.data.Property;
 import com.vaadin.data.util.ObjectProperty;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VLabelPaintable;
+import com.vaadin.terminal.gwt.client.ui.label.VLabelPaintable;
 import com.vaadin.ui.ClientWidget.LoadStyle;
 
 /**