diff options
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r-- | src/com/vaadin/ui/AbstractComponent.java | 25 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractMedia.java | 96 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractOrderedLayout.java | 109 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractTextField.java | 128 | ||||
-rw-r--r-- | src/com/vaadin/ui/Label.java | 175 | ||||
-rw-r--r-- | src/com/vaadin/ui/Root.java | 9 | ||||
-rw-r--r-- | src/com/vaadin/ui/TextArea.java | 48 | ||||
-rw-r--r-- | src/com/vaadin/ui/Video.java | 22 |
8 files changed, 174 insertions, 438 deletions
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 79a07ae00e..554d7806f9 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -18,7 +18,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -821,19 +820,27 @@ public abstract class AbstractComponent implements Component, MethodEventSource */ protected ComponentState createState() { try { + return getStateType().newInstance(); + } catch (Exception e) { + throw new RuntimeException( + "Error creating state of type " + getStateType().getName() + + " for " + getClass().getName(), e); + } + } + + /* (non-Javadoc) + * @see com.vaadin.terminal.gwt.server.ClientConnector#getStateType() + */ + public Class<? extends ComponentState> getStateType() { + try { Method m = getClass().getMethod("getState", (Class[]) null); Class<? extends ComponentState> type = (Class<? extends ComponentState>) m .getReturnType(); - return type.newInstance(); + return type; } catch (Exception e) { - getLogger().log( - Level.INFO, - "Error determining state object class for " - + getClass().getName()); + throw new RuntimeException("Error finding state type for " + + getClass().getName(), e); } - - // Fall back to ComponentState if detection fails for some reason. - return new ComponentState(); } /* Documentation copied from interface */ diff --git a/src/com/vaadin/ui/AbstractMedia.java b/src/com/vaadin/ui/AbstractMedia.java index 09cfd5ff12..760d9878ca 100644 --- a/src/com/vaadin/ui/AbstractMedia.java +++ b/src/com/vaadin/ui/AbstractMedia.java @@ -5,37 +5,25 @@ package com.vaadin.ui; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Map; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.Vaadin6Component; -import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector; +import com.vaadin.terminal.gwt.client.communication.URLReference; +import com.vaadin.terminal.gwt.client.ui.AbstractMediaState; import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector.MediaControl; +import com.vaadin.terminal.gwt.server.ResourceReference; /** * Abstract base class for the HTML5 media components. * * @author Vaadin Ltd */ -public class AbstractMedia extends AbstractComponent implements - Vaadin6Component { +public class AbstractMedia extends AbstractComponent { - private List<Resource> sources = new ArrayList<Resource>(); - - private boolean showControls; - - private String altText; - - private boolean htmlContentAllowed; - - private boolean autoplay; - - private boolean muted; + @Override + public AbstractMediaState getState() { + return (AbstractMediaState) super.getState(); + } /** * Sets a single media file as the source of the media component. @@ -43,10 +31,16 @@ public class AbstractMedia extends AbstractComponent implements * @param source */ public void setSource(Resource source) { - sources.clear(); + clearSources(); + addSource(source); } + private void clearSources() { + getState().getSources().clear(); + getState().getSourceTypes().clear(); + } + /** * Adds an alternative media file to the sources list. Which of the sources * is used is selected by the browser depending on which file formats it @@ -58,7 +52,8 @@ public class AbstractMedia extends AbstractComponent implements */ public void addSource(Resource source) { if (source != null) { - sources.add(source); + getState().getSources().add(new ResourceReference(source)); + getState().getSourceTypes().add(source.getMIMEType()); requestRepaint(); } } @@ -72,15 +67,21 @@ public class AbstractMedia extends AbstractComponent implements * @param sources */ public void setSources(Resource... sources) { - this.sources.addAll(Arrays.asList(sources)); - requestRepaint(); + clearSources(); + for (Resource source : sources) { + addSource(source); + } } /** * @return The sources pointed to in this media. */ public List<Resource> getSources() { - return Collections.unmodifiableList(sources); + ArrayList<Resource> sources = new ArrayList<Resource>(); + for (URLReference ref : getState().getSources()) { + sources.add(((ResourceReference) ref).getResource()); + } + return sources; } /** @@ -89,7 +90,7 @@ public class AbstractMedia extends AbstractComponent implements * @param showControls */ public void setShowControls(boolean showControls) { - this.showControls = showControls; + getState().setShowControls(showControls); requestRepaint(); } @@ -97,7 +98,7 @@ public class AbstractMedia extends AbstractComponent implements * @return true if the browser is to show native media controls. */ public boolean isShowControls() { - return showControls; + return getState().isShowControls(); } /** @@ -109,10 +110,10 @@ public class AbstractMedia extends AbstractComponent implements * "https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Using_Flash" * >Mozilla Developer Network</a> for details. * - * @param text + * @param altText */ - public void setAltText(String text) { - altText = text; + public void setAltText(String altText) { + getState().setAltText(altText); requestRepaint(); } @@ -121,7 +122,7 @@ public class AbstractMedia extends AbstractComponent implements * HTML5. */ public String getAltText() { - return altText; + return getState().getAltText(); } /** @@ -131,7 +132,7 @@ public class AbstractMedia extends AbstractComponent implements * @param htmlContentAllowed */ public void setHtmlContentAllowed(boolean htmlContentAllowed) { - this.htmlContentAllowed = htmlContentAllowed; + getState().setHtmlContentAllowed(htmlContentAllowed); requestRepaint(); } @@ -140,7 +141,7 @@ public class AbstractMedia extends AbstractComponent implements * be rendered as HTML. */ public boolean isHtmlContentAllowed() { - return htmlContentAllowed; + return getState().isHtmlContentAllowed(); } /** @@ -150,7 +151,7 @@ public class AbstractMedia extends AbstractComponent implements * @param autoplay */ public void setAutoplay(boolean autoplay) { - this.autoplay = autoplay; + getState().setAutoplay(autoplay); requestRepaint(); } @@ -158,7 +159,7 @@ public class AbstractMedia extends AbstractComponent implements * @return true if the media is set to automatically start playback. */ public boolean isAutoplay() { - return autoplay; + return getState().isAutoplay(); } /** @@ -167,7 +168,7 @@ public class AbstractMedia extends AbstractComponent implements * @param muted */ public void setMuted(boolean muted) { - this.muted = muted; + getState().setMuted(muted); requestRepaint(); } @@ -175,7 +176,7 @@ public class AbstractMedia extends AbstractComponent implements * @return true if the audio is muted. */ public boolean isMuted() { - return muted; + return getState().isMuted(); } /** @@ -192,25 +193,4 @@ public class AbstractMedia extends AbstractComponent implements getRpcProxy(MediaControl.class).play(); } - public void paintContent(PaintTarget target) throws PaintException { - target.addAttribute(MediaBaseConnector.ATTR_CONTROLS, isShowControls()); - if (getAltText() != null) { - target.addAttribute(MediaBaseConnector.ATTR_ALT_TEXT, getAltText()); - } - target.addAttribute(MediaBaseConnector.ATTR_HTML, - isHtmlContentAllowed()); - target.addAttribute(MediaBaseConnector.ATTR_AUTOPLAY, isAutoplay()); - for (Resource r : getSources()) { - target.startTag(MediaBaseConnector.TAG_SOURCE); - target.addAttribute(MediaBaseConnector.ATTR_RESOURCE, r); - target.addAttribute(MediaBaseConnector.ATTR_RESOURCE_TYPE, - r.getMIMEType()); - target.endTag(MediaBaseConnector.TAG_SOURCE); - } - target.addAttribute(MediaBaseConnector.ATTR_MUTED, isMuted()); - } - - public void changeVariables(Object source, Map<String, Object> variables) { - // TODO Remove once Vaadin6Component is no longer implemented - } } diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java index 3606fa6572..2cd6fc2a9a 100644 --- a/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -4,28 +4,23 @@ package com.vaadin.ui; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; -import java.util.Map; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; import com.vaadin.event.LayoutEvents.LayoutClickNotifier; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; -import com.vaadin.terminal.Vaadin6Component; import com.vaadin.terminal.gwt.client.Connector; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState; +import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState.ChildComponentData; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, - Vaadin6Component { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() { @@ -48,10 +43,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements /** * Mapping from components to alignments (horizontal + vertical). */ - private final Map<Component, Alignment> componentToAlignment = new HashMap<Component, Alignment>(); - - private final Map<Component, Float> componentToExpandRatio = new HashMap<Component, Float>(); - public AbstractOrderedLayout() { registerRpc(rpc); } @@ -75,11 +66,11 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements components.add(c); try { super.addComponent(c); - requestRepaint(); } catch (IllegalArgumentException e) { components.remove(c); throw e; } + componentAdded(c); } /** @@ -98,11 +89,12 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements components.addFirst(c); try { super.addComponent(c); - requestRepaint(); } catch (IllegalArgumentException e) { components.remove(c); throw e; } + componentAdded(c); + } /** @@ -127,11 +119,23 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements components.add(index, c); try { super.addComponent(c); - requestRepaint(); } catch (IllegalArgumentException e) { components.remove(c); throw e; } + + componentAdded(c); + } + + private void componentRemoved(Component c) { + getState().getChildData().remove(c); + requestRepaint(); + } + + private void componentAdded(Component c) { + getState().getChildData().put(c, new ChildComponentData()); + requestRepaint(); + } /** @@ -143,10 +147,8 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements @Override public void removeComponent(Component c) { components.remove(c); - componentToAlignment.remove(c); - componentToExpandRatio.remove(c); super.removeComponent(c); - requestRepaint(); + componentRemoved(c); } /** @@ -169,24 +171,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return components.size(); } - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the paint operation failed. - */ - public void paintContent(PaintTarget target) throws PaintException { - // Add child component alignment info to layout tag - target.addAttribute("alignments", componentToAlignment); - target.addAttribute("expandRatios", componentToExpandRatio); - } - - public void changeVariables(Object source, Map<String, Object> variables) { - // TODO Remove once Vaadin6Component is no longer implemented - } - /* Documented in superclass */ public void replaceComponent(Component oldComponent, Component newComponent) { @@ -213,17 +197,16 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements removeComponent(oldComponent); addComponent(newComponent, oldLocation); } else { + // Both old and new are in the layout if (oldLocation > newLocation) { components.remove(oldComponent); components.add(newLocation, oldComponent); components.remove(newComponent); - componentToAlignment.remove(newComponent); components.add(oldLocation, newComponent); } else { components.remove(newComponent); components.add(oldLocation, newComponent); components.remove(oldComponent); - componentToAlignment.remove(oldComponent); components.add(newLocation, oldComponent); } @@ -239,21 +222,17 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ public void setComponentAlignment(Component childComponent, int horizontalAlignment, int verticalAlignment) { - if (components.contains(childComponent)) { - // Alignments are bit masks - componentToAlignment.put(childComponent, new Alignment( - horizontalAlignment + verticalAlignment)); - requestRepaint(); - } else { - throw new IllegalArgumentException( - "Component must be added to layout before using setComponentAlignment()"); - } + Alignment a = new Alignment(horizontalAlignment + verticalAlignment); + setComponentAlignment(childComponent, a); } public void setComponentAlignment(Component childComponent, Alignment alignment) { - if (components.contains(childComponent)) { - componentToAlignment.put(childComponent, alignment); + ChildComponentData childData = getState().getChildData().get( + childComponent); + if (childData != null) { + // Alignments are bit masks + childData.setAlignmentBitmask(alignment.getBitMask()); requestRepaint(); } else { throw new IllegalArgumentException( @@ -269,12 +248,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * .vaadin.ui.Component) */ public Alignment getComponentAlignment(Component childComponent) { - Alignment alignment = componentToAlignment.get(childComponent); - if (alignment == null) { - return ALIGNMENT_DEFAULT; - } else { - return alignment; + ChildComponentData childData = getState().getChildData().get( + childComponent); + if (childData == null) { + throw new IllegalArgumentException( + "The given component is not a child of this layout"); } + + return new Alignment(childData.getAlignmentBitmask()); } /* @@ -326,13 +307,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * @param ratio */ public void setExpandRatio(Component component, float ratio) { - if (components.contains(component)) { - componentToExpandRatio.put(component, ratio); - requestRepaint(); - } else { + ChildComponentData childData = getState().getChildData().get(component); + if (childData == null) { throw new IllegalArgumentException( - "Component must be added to layout before using setExpandRatio()"); + "The given component is not a child of this layout"); } + + childData.setExpandRatio(ratio); + requestRepaint(); }; /** @@ -340,11 +322,16 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * * @param component * which expand ratios is requested - * @return expand ratio of given component, 0.0f by default + * @return expand ratio of given component, 0.0f by default. */ public float getExpandRatio(Component component) { - Float ratio = componentToExpandRatio.get(component); - return (ratio == null) ? 0 : ratio.floatValue(); + ChildComponentData childData = getState().getChildData().get(component); + if (childData == null) { + throw new IllegalArgumentException( + "The given component is not a child of this layout"); + } + + return childData.getExpandRatio(); } public void addListener(LayoutClickListener listener) { diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java index acb1d71ed8..d584374bda 100644 --- a/src/com/vaadin/ui/AbstractTextField.java +++ b/src/com/vaadin/ui/AbstractTextField.java @@ -4,7 +4,6 @@ package com.vaadin.ui; -import java.text.Format; import java.util.Map; import com.vaadin.event.FieldEvents.BlurEvent; @@ -19,18 +18,13 @@ import com.vaadin.event.FieldEvents.TextChangeNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Vaadin6Component; +import com.vaadin.terminal.gwt.client.ui.textfield.AbstractTextFieldState; import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; public abstract class AbstractTextField extends AbstractField<String> implements BlurNotifier, FocusNotifier, TextChangeNotifier, Vaadin6Component { /** - * Value formatter used to format the string contents. - */ - @Deprecated - private Format format; - - /** * Null representation. */ private String nullRepresentation = "null"; @@ -40,21 +34,6 @@ public abstract class AbstractTextField extends AbstractField<String> implements */ private boolean nullSettingAllowed = false; /** - * Maximum character count in text field. - */ - private int maxLength = -1; - - /** - * Number of visible columns in the TextField. - */ - private int columns = 0; - - /** - * The prompt to display in an empty field. Null when disabled. - */ - private String inputPrompt = null; - - /** * The text content when the last messages to the server was sent. Cleared * when value is changed. */ @@ -100,32 +79,23 @@ public abstract class AbstractTextField extends AbstractField<String> implements super(); } - public void paintContent(PaintTarget target) throws PaintException { - - if (getMaxLength() >= 0) { - target.addAttribute("maxLength", getMaxLength()); - } - - // Adds the number of column and rows - final int columns = getColumns(); - if (columns != 0) { - target.addAttribute("cols", String.valueOf(columns)); - } + @Override + public AbstractTextFieldState getState() { + return (AbstractTextFieldState) super.getState(); + } - if (getInputPrompt() != null) { - target.addAttribute("prompt", getInputPrompt()); - } + @Override + public void updateState() { + super.updateState(); - // Adds the content as variable - String value = getFormattedValue(); + String value = getValue(); if (value == null) { value = getNullRepresentation(); } - if (value == null) { - throw new IllegalStateException( - "Null values are not allowed if the null-representation is null"); - } - target.addVariable(this, "text", value); + getState().setText(value); + } + + public void paintContent(PaintTarget target) throws PaintException { if (selectionPosition != -1) { target.addAttribute("selpos", selectionPosition); @@ -153,37 +123,6 @@ public abstract class AbstractTextField extends AbstractField<String> implements } - /** - * Gets the formatted string value. Sets the field value by using the - * assigned Format. - * - * @return the Formatted value. - * @see #setFormat(Format) - * @see Format - * @deprecated - */ - @Deprecated - protected String getFormattedValue() { - Object v = getValue(); - if (v == null) { - return null; - } - return v.toString(); - } - - @Override - public String getValue() { - String v = super.getValue(); - if (format == null || v == null) { - return v; - } - try { - return format.format(v); - } catch (final IllegalArgumentException e) { - return v; - } - } - public void changeVariables(Object source, Map<String, Object> variables) { changingVariables = true; @@ -215,7 +154,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements if (getMaxLength() != -1 && newValue.length() > getMaxLength()) { newValue = newValue.substring(0, getMaxLength()); } - final String oldValue = getFormattedValue(); + final String oldValue = getValue(); if (newValue != null && (oldValue == null || isNullSettingAllowed()) && newValue.equals(getNullRepresentation())) { @@ -228,7 +167,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements // If the modified status changes, or if we have a // formatter, repaint is needed after all. - if (format != null || wasModified != isModified()) { + if (wasModified != isModified()) { requestRepaint(); } } @@ -345,31 +284,6 @@ public abstract class AbstractTextField extends AbstractField<String> implements requestRepaint(); } - /** - * Gets the value formatter of TextField. - * - * @return the Format used to format the value. - * @deprecated replaced by {@link com.vaadin.data.util.PropertyFormatter} - */ - @Deprecated - public Format getFormat() { - return format; - } - - /** - * Gets the value formatter of TextField. - * - * @param format - * the Format used to format the value. Null disables the - * formatting. - * @deprecated replaced by {@link com.vaadin.data.util.PropertyFormatter} - */ - @Deprecated - public void setFormat(Format format) { - this.format = format; - requestRepaint(); - } - @Override protected boolean isEmpty() { return super.isEmpty() || getValue().length() == 0; @@ -382,7 +296,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the maxLength */ public int getMaxLength() { - return maxLength; + return getState().getMaxLength(); } /** @@ -393,7 +307,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * the maxLength to set */ public void setMaxLength(int maxLength) { - this.maxLength = maxLength; + getState().setMaxLength(maxLength); requestRepaint(); } @@ -405,7 +319,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the number of columns in the editor. */ public int getColumns() { - return columns; + return getState().getColumns(); } /** @@ -420,7 +334,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements if (columns < 0) { columns = 0; } - this.columns = columns; + getState().setColumns(columns); requestRepaint(); } @@ -431,7 +345,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the current input prompt, or null if not enabled */ public String getInputPrompt() { - return inputPrompt; + return getState().getInputPrompt(); } /** @@ -441,7 +355,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @param inputPrompt */ public void setInputPrompt(String inputPrompt) { - this.inputPrompt = inputPrompt; + getState().setInputPrompt(inputPrompt); requestRepaint(); } diff --git a/src/com/vaadin/ui/Label.java b/src/com/vaadin/ui/Label.java index e52090aa5f..99a0f89e5c 100644 --- a/src/com/vaadin/ui/Label.java +++ b/src/com/vaadin/ui/Label.java @@ -5,13 +5,11 @@ package com.vaadin.ui; import java.lang.reflect.Method; -import java.util.Map; 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.Vaadin6Component; +import com.vaadin.terminal.gwt.client.ui.label.ContentMode; +import com.vaadin.terminal.gwt.client.ui.label.LabelState; /** * Label component for showing non-editable short texts. @@ -41,120 +39,7 @@ import com.vaadin.terminal.Vaadin6Component; // TODO generics for interface Property public class Label extends AbstractComponent implements Property, Property.Viewer, Property.ValueChangeListener, - Property.ValueChangeNotifier, Comparable<Object>, Vaadin6Component { - - /** - * Content modes defining how the client should interpret a Label's value. - * - * @sine 7.0 - */ - public enum ContentMode { - /** - * Content mode, where the label contains only plain text. The - * getValue() result is coded to XML when painting. - */ - TEXT(null) { - @Override - public void paintText(String text, PaintTarget target) - throws PaintException { - target.addText(text); - } - }, - - /** - * Content mode, where the label contains preformatted text. - */ - PREFORMATTED("pre") { - @Override - public void paintText(String text, PaintTarget target) - throws PaintException { - target.startTag("pre"); - target.addText(text); - target.endTag("pre"); - } - }, - - /** - * Content mode, where the label contains XHTML. Contents is then - * enclosed in DIV elements having namespace of - * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd". - */ - XHTML("xhtml") { - @Override - public void paintText(String text, PaintTarget target) - throws PaintException { - target.startTag("data"); - target.addXMLSection("div", text, - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); - target.endTag("data"); - } - }, - - /** - * Content mode, where the label contains well-formed or well-balanced - * XML. Each of the root elements must have their default namespace - * specified. - */ - XML("xml") { - @Override - public void paintText(String text, PaintTarget target) - throws PaintException { - target.addXMLSection("data", text, null); - } - }, - - /** - * Content mode, where the label contains RAW output. Output is not - * required to comply to with XML. In Web Adapter output is inserted - * inside the resulting HTML document as-is. This is useful for some - * specific purposes where possibly broken HTML content needs to be - * shown, but in most cases XHTML mode should be preferred. - */ - RAW("raw") { - @Override - public void paintText(String text, PaintTarget target) - throws PaintException { - target.startTag("data"); - target.addAttribute("escape", false); - target.addText(text); - target.endTag("data"); - } - }; - - private final String uidlName; - - /** - * The default content mode is text - */ - public static ContentMode DEFAULT = TEXT; - - private ContentMode(String uidlName) { - this.uidlName = uidlName; - } - - /** - * Gets the name representing this content mode in UIDL messages - * - * @return the UIDL name of this content mode - */ - public String getUidlName() { - return uidlName; - } - - /** - * Adds the text value to a {@link PaintTarget} according to this - * content mode - * - * @param text - * the text to add - * @param target - * the paint target to add the value to - * @throws PaintException - * if the paint operation failed - */ - public abstract void paintText(String text, PaintTarget target) - throws PaintException; - } + Property.ValueChangeNotifier, Comparable<Object> { /** * @deprecated From 7.0, use {@link ContentMode#TEXT} instead @@ -187,17 +72,15 @@ public class Label extends AbstractComponent implements Property, public static final ContentMode CONTENT_RAW = ContentMode.RAW; /** - * @deprecated From 7.0, use {@link ContentMode#DEFAULT} instead + * @deprecated From 7.0, use {@link ContentMode#TEXT} instead */ @Deprecated - public static final ContentMode CONTENT_DEFAULT = ContentMode.DEFAULT; + public static final ContentMode CONTENT_DEFAULT = ContentMode.TEXT; private static final String DATASOURCE_MUST_BE_SET = "Datasource must be set"; private Property dataSource; - private ContentMode contentMode = ContentMode.DEFAULT; - /** * Creates an empty Label. */ @@ -211,7 +94,7 @@ public class Label extends AbstractComponent implements Property, * @param content */ public Label(String content) { - this(content, ContentMode.DEFAULT); + this(content, ContentMode.TEXT); } /** @@ -221,7 +104,7 @@ public class Label extends AbstractComponent implements Property, * @param contentSource */ public Label(Property contentSource) { - this(contentSource, ContentMode.DEFAULT); + this(contentSource, ContentMode.TEXT); } /** @@ -243,27 +126,21 @@ public class Label extends AbstractComponent implements Property, */ public Label(Property contentSource, ContentMode contentMode) { setPropertyDataSource(contentSource); - if (contentMode != ContentMode.DEFAULT) { - setContentMode(contentMode); - } + setContentMode(contentMode); setWidth(100, UNITS_PERCENTAGE); } - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the Paint Operation fails. - */ - public void paintContent(PaintTarget target) throws PaintException { - String uidlName = contentMode.getUidlName(); - if (uidlName != null) { - target.addAttribute("mode", uidlName); - } - contentMode.paintText(getStringValue(), target); + @Override + public void updateState() { + super.updateState(); + // We don't know when the text is updated so update it here before + // sending the state to the client + getState().setText(getStringValue()); + } + @Override + public LabelState getState() { + return (LabelState) super.getState(); } /** @@ -381,7 +258,7 @@ public class Label extends AbstractComponent implements Property, * @see ContentMode */ public ContentMode getContentMode() { - return contentMode; + return getState().getContentMode(); } /** @@ -396,10 +273,9 @@ public class Label extends AbstractComponent implements Property, if (contentMode == null) { throw new IllegalArgumentException("Content mode can not be null"); } - if (contentMode != this.contentMode) { - this.contentMode = contentMode; - requestRepaint(); - } + + getState().setContentMode(contentMode); + requestRepaint(); } /* Value change events */ @@ -516,7 +392,8 @@ public class Label extends AbstractComponent implements Property, String thisValue; String otherValue; - if (contentMode == ContentMode.XML || contentMode == ContentMode.XHTML) { + if (getContentMode() == ContentMode.XML + || getContentMode() == ContentMode.XHTML) { thisValue = stripTags(getStringValue()); } else { thisValue = getStringValue(); @@ -566,8 +443,4 @@ public class Label extends AbstractComponent implements Property, return res.toString(); } - public void changeVariables(Object source, Map<String, Object> variables) { - // TODO Remove once Vaadin6Component is no longer implemented - } - } diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 405ae8da93..93b98693c2 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -30,7 +30,6 @@ import com.vaadin.terminal.Resource; import com.vaadin.terminal.Vaadin6Component; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedRequest.BrowserDetails; -import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.notification.VNotification; import com.vaadin.terminal.gwt.client.ui.root.RootServerRpc; @@ -475,10 +474,10 @@ public abstract class Root extends AbstractComponentContainer implements } @Override - protected ComponentState createState() { + public Class<? extends RootState> getStateType() { // This is a workaround for a problem with creating the correct state // object during build - return new RootState(); + return RootState.class; } /** @@ -644,6 +643,10 @@ public abstract class Root extends AbstractComponentContainer implements * @see com.vaadin.ui.ComponentContainer#getComponentIterator() */ public Iterator<Component> getComponentIterator() { + if (getContent() == null) { + return Collections.EMPTY_LIST.iterator(); + } + return Collections.singleton((Component) getContent()).iterator(); } diff --git a/src/com/vaadin/ui/TextArea.java b/src/com/vaadin/ui/TextArea.java index adb980818e..4c0b563b00 100644 --- a/src/com/vaadin/ui/TextArea.java +++ b/src/com/vaadin/ui/TextArea.java @@ -5,26 +5,13 @@ package com.vaadin.ui; import com.vaadin.data.Property; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; +import com.vaadin.terminal.gwt.client.ui.textarea.TextAreaState; /** * A text field that supports multi line editing. */ public class TextArea extends AbstractTextField { - private static final int DEFAULT_ROWS = 5; - - /** - * Number of visible rows in the text area. - */ - private int rows = DEFAULT_ROWS; - - /** - * Tells if word-wrapping should be used in the text area. - */ - private boolean wordwrap = true; - /** * Constructs an empty TextArea. */ @@ -81,6 +68,11 @@ public class TextArea extends AbstractTextField { } + @Override + public TextAreaState getState() { + return (TextAreaState) super.getState(); + } + /** * Sets the number of rows in the text area. * @@ -91,10 +83,8 @@ public class TextArea extends AbstractTextField { if (rows < 0) { rows = 0; } - if (this.rows != rows) { - this.rows = rows; - requestRepaint(); - } + getState().setRows(rows); + requestRepaint(); } /** @@ -103,7 +93,7 @@ public class TextArea extends AbstractTextField { * @return number of explicitly set rows. */ public int getRows() { - return rows; + return getState().getRows(); } /** @@ -114,10 +104,8 @@ public class TextArea extends AbstractTextField { * word-wrap mode. */ public void setWordwrap(boolean wordwrap) { - if (this.wordwrap != wordwrap) { - this.wordwrap = wordwrap; - requestRepaint(); - } + getState().setWordwrap(wordwrap); + requestRepaint(); } /** @@ -127,19 +115,7 @@ public class TextArea extends AbstractTextField { * <code>false</code> if not. */ public boolean isWordwrap() { - return wordwrap; + return getState().isWordwrap(); } - @Override - public void paintContent(PaintTarget target) throws PaintException { - super.paintContent(target); - - target.addAttribute("rows", getRows()); - - if (!isWordwrap()) { - // Wordwrap is only painted if turned off to minimize communications - target.addAttribute("wordwrap", false); - } - - } } diff --git a/src/com/vaadin/ui/Video.java b/src/com/vaadin/ui/Video.java index 28fbfb0547..0a2eccca0f 100644 --- a/src/com/vaadin/ui/Video.java +++ b/src/com/vaadin/ui/Video.java @@ -4,10 +4,9 @@ package com.vaadin.ui; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.video.VideoConnector; +import com.vaadin.terminal.gwt.client.ui.video.VideoState; +import com.vaadin.terminal.gwt.server.ResourceReference; /** * The Video component translates into an HTML5 <video> element and as @@ -32,7 +31,10 @@ import com.vaadin.terminal.gwt.client.ui.video.VideoConnector; */ public class Video extends AbstractMedia { - private Resource poster; + @Override + public VideoState getState() { + return (VideoState) super.getState(); + } public Video() { this("", null); @@ -65,21 +67,15 @@ public class Video extends AbstractMedia { * @param poster */ public void setPoster(Resource poster) { - this.poster = poster; + getState().setPoster(new ResourceReference(poster)); + requestRepaint(); } /** * @return The poster image. */ public Resource getPoster() { - return poster; + return ((ResourceReference) getState().getPoster()).getResource(); } - @Override - public void paintContent(PaintTarget target) throws PaintException { - super.paintContent(target); - if (getPoster() != null) { - target.addAttribute(VideoConnector.ATTR_POSTER, getPoster()); - } - } } |