From: Artur Signell Date: Mon, 23 Jan 2012 12:22:45 +0000 (+0200) Subject: Created VAbstractPaintableWidget X-Git-Tag: 7.0.0.alpha2~536^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0f00b0f2751e1196b51b96bf3900423bdd95d064;p=vaadin-framework.git Created VAbstractPaintableWidget Moved VLabel* to own package --- 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 index 0000000000..dff5a286ba --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java @@ -0,0 +1,49 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.VPaintableWidget; + +public abstract class VAbstractPaintableWidget implements VPaintableWidget { + + private Widget widget; + + /** + * Default constructor + */ + public VAbstractPaintableWidget() { + } + + /** + * Creates and returns the widget for this VPaintableWidget. This method + * should only be called once when initializing the paintable. + * + * @return + */ + protected Widget createWidget() { + return GWT.create(getWidgetClass()); + } + + /** + * Returns the widget associated with this paintable. The widget returned by + * this method must not changed during the life time of the paintable. + * + * @return The widget associated with this paintable + */ + public Widget getWidgetForPaintable() { + if (widget == null) { + widget = createWidget(); + } + + return widget; + } + + /** + * Returns the class of the widget for this paintable. Used to instansiate + * the widget. + * + * @return The widget class. + */ + protected abstract Class getWidgetClass(); + +} 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 index f259d033c6..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/VLabel.java +++ /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
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 index 12f2c639da..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/VLabelPaintable.java +++ /dev/null @@ -1,122 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.terminal.gwt.client.ui; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.PreElement; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyDownEvent; -import com.google.gwt.event.dom.client.KeyDownHandler; -import com.google.gwt.event.dom.client.MouseMoveEvent; -import com.google.gwt.event.dom.client.MouseMoveHandler; -import com.google.gwt.event.dom.client.MouseOutEvent; -import com.google.gwt.event.dom.client.MouseOutHandler; -import com.google.gwt.event.dom.client.MouseOverEvent; -import com.google.gwt.event.dom.client.MouseOverHandler; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VPaintableWidget; - -public class VLabelPaintable implements VPaintableWidget { - - private VLabel widget = GWT.create(VLabel.class); - private ApplicationConnection client; - - class TooltipHandler implements ClickHandler, KeyDownHandler, - MouseOverHandler, MouseOutHandler, MouseMoveHandler { - - public void onClick(ClickEvent event) { - // TODO Auto-generated method stub - - } - - public void onMouseMove(MouseMoveEvent event) { - // TODO Auto-generated method stub - - } - - public void onMouseOut(MouseOutEvent event) { - // TODO Auto-generated method stub - - } - - public void onMouseOver(MouseOverEvent event) { - // TODO Auto-generated method stub - - } - - public void onKeyDown(KeyDownEvent event) { - // TODO Auto-generated method stub - - } - - } - - public VLabelPaintable() { - TooltipHandler handler = new TooltipHandler(); - - widget.addDomHandler(handler, ClickEvent.getType()); - widget.addDomHandler(handler, KeyDownEvent.getType()); - widget.addDomHandler(handler, MouseOverEvent.getType()); - widget.addDomHandler(handler, MouseOutEvent.getType()); - widget.addDomHandler(handler, MouseMoveEvent.getType()); - - } - - public VLabel getWidget() { - return widget; - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - if (client.updateComponent(getWidget(), uidl, true)) { - return; - } - - this.client = client; - - boolean sinkOnloads = false; - - final String mode = uidl.getStringAttribute("mode"); - if (mode == null || "text".equals(mode)) { - getWidget().setText(uidl.getChildString(0)); - } else if ("pre".equals(mode)) { - PreElement preElement = Document.get().createPreElement(); - preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0)); - // clear existing content - getWidget().setHTML(""); - // add preformatted text to dom - getWidget().getElement().appendChild(preElement); - } else if ("uidl".equals(mode)) { - getWidget().setHTML(uidl.getChildrenAsXML()); - } else if ("xhtml".equals(mode)) { - UIDL content = uidl.getChildUIDL(0).getChildUIDL(0); - if (content.getChildCount() > 0) { - getWidget().setHTML(content.getChildString(0)); - } else { - getWidget().setHTML(""); - } - sinkOnloads = true; - } else if ("xml".equals(mode)) { - getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0)); - } else if ("raw".equals(mode)) { - getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0)); - sinkOnloads = true; - } else { - getWidget().setText(""); - } - if (sinkOnloads) { - Util.sinkOnloadForImages(getWidget().getElement()); - } - } - - public Widget getWidgetForPaintable() { - return getWidget(); - } - -} 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 index 0000000000..09f435227d --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java @@ -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
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 index 0000000000..796bce265e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/label/VLabelPaintable.java @@ -0,0 +1,71 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.terminal.gwt.client.ui.label; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.PreElement; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VPaintableWidget; + +public class VLabelPaintable implements VPaintableWidget { + + private VLabel widget = GWT.create(VLabel.class); + private ApplicationConnection client; + + public VLabelPaintable() { + } + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + if (client.updateComponent(getWidgetForPaintable(), uidl, true)) { + return; + } + + this.client = client; + + boolean sinkOnloads = false; + + final String mode = uidl.getStringAttribute("mode"); + if (mode == null || "text".equals(mode)) { + getWidgetForPaintable().setText(uidl.getChildString(0)); + } else if ("pre".equals(mode)) { + PreElement preElement = Document.get().createPreElement(); + preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0)); + // clear existing content + getWidgetForPaintable().setHTML(""); + // add preformatted text to dom + getWidgetForPaintable().getElement().appendChild(preElement); + } else if ("uidl".equals(mode)) { + getWidgetForPaintable().setHTML(uidl.getChildrenAsXML()); + } else if ("xhtml".equals(mode)) { + UIDL content = uidl.getChildUIDL(0).getChildUIDL(0); + if (content.getChildCount() > 0) { + getWidgetForPaintable().setHTML(content.getChildString(0)); + } else { + getWidgetForPaintable().setHTML(""); + } + sinkOnloads = true; + } else if ("xml".equals(mode)) { + getWidgetForPaintable().setHTML( + uidl.getChildUIDL(0).getChildString(0)); + } else if ("raw".equals(mode)) { + getWidgetForPaintable().setHTML( + uidl.getChildUIDL(0).getChildString(0)); + sinkOnloads = true; + } else { + getWidgetForPaintable().setText(""); + } + if (sinkOnloads) { + Util.sinkOnloadForImages(getWidgetForPaintable().getElement()); + } + } + + public VLabel getWidgetForPaintable() { + return widget; + } + +} diff --git a/src/com/vaadin/ui/Label.java b/src/com/vaadin/ui/Label.java index 29eb6df766..576bbd967f 100644 --- a/src/com/vaadin/ui/Label.java +++ b/src/com/vaadin/ui/Label.java @@ -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; /**