com.vaadin.ui
Class Label

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.Label
All Implemented Interfaces:
Property<java.lang.String>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, MethodEventSource, ClientConnector, Sizeable, com.vaadin.shared.Connector, Component, java.io.Serializable, java.lang.Comparable<Label>

public class Label
extends AbstractComponent
implements Property<java.lang.String>, Property.Viewer, Property.ValueChangeListener, Property.ValueChangeNotifier, java.lang.Comparable<Label>

Label component for showing non-editable short texts. The label content can be set to the modes specified by ContentMode

The contents of the label may contain simple formatting:

The b,i,u and li tags can contain all the tags in the list recursively.

Since:
3.0
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
static class Label.ValueChangeEvent
          Value change event
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeEvent, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Field Summary
static com.vaadin.shared.ui.label.ContentMode CONTENT_DEFAULT
          Deprecated. As of 7.0, use ContentMode.TEXT instead
static com.vaadin.shared.ui.label.ContentMode CONTENT_PREFORMATTED
          Deprecated. As of 7.0, use ContentMode.PREFORMATTED instead
static com.vaadin.shared.ui.label.ContentMode CONTENT_RAW
          Deprecated. As of 7.0, use ContentMode.RAW instead
static com.vaadin.shared.ui.label.ContentMode CONTENT_TEXT
          Deprecated. As of 7.0, use ContentMode.TEXT instead
static com.vaadin.shared.ui.label.ContentMode CONTENT_XHTML
          Deprecated. As of 7.0, use ContentMode.HTML instead
static com.vaadin.shared.ui.label.ContentMode CONTENT_XML
          Deprecated. As of 7.0, use ContentMode.XML instead
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
Label()
          Creates an empty Label.
Label(Property contentSource)
          Creates a new instance of Label with text-contents read from given datasource.
Label(Property contentSource, com.vaadin.shared.ui.label.ContentMode contentMode)
          Creates a new instance of Label with text-contents read from given datasource.
Label(java.lang.String content)
          Creates a new instance of Label with text-contents.
Label(java.lang.String content, com.vaadin.shared.ui.label.ContentMode contentMode)
          Creates a new instance of Label with text-contents.
 
Method Summary
 void addListener(Property.ValueChangeListener listener)
          Deprecated. As of 7.0, replaced by addValueChangeListener(com.vaadin.data.Property.ValueChangeListener)
 void addValueChangeListener(Property.ValueChangeListener listener)
          Adds the value change listener.
 void attach()
          Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
 int compareTo(Label other)
          Compares the Label to other objects.
protected  void fireValueChange()
          Emits the options change event.
 com.vaadin.shared.ui.label.ContentMode getContentMode()
          Gets the content mode of the Label.
 Converter<java.lang.String,java.lang.Object> getConverter()
          Gets the converter used to convert the property data source value to the label value.
 Property getPropertyDataSource()
          Gets the viewing data-source property.
protected  com.vaadin.shared.ui.label.LabelState getState()
          Returns the shared state bean with information to be sent from the server to the client.
protected  com.vaadin.shared.ui.label.LabelState getState(boolean markAsDirty)
          Returns the shared state for this connector.
 java.lang.Class<java.lang.String> getType()
          Gets the type of the Property.
 java.lang.String getValue()
          Gets the value of the label.
 void removeListener(Property.ValueChangeListener listener)
          Deprecated. As of 7.0, replaced by removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener)
 void removeValueChangeListener(Property.ValueChangeListener listener)
          Removes the value change listener.
 void setContentMode(com.vaadin.shared.ui.label.ContentMode contentMode)
          Sets the content mode of the Label.
 void setConverter(Converter<java.lang.String,?> converter)
          Sets the converter used to convert the label value to the property data source type.
 void setLocale(java.util.Locale locale)
          Sets the locale of this component.
 void setPropertyDataSource(Property newDataSource)
          Sets the property as data-source for viewing.
 void setValue(java.lang.String newStringValue)
          Set the value of the label.
 java.lang.String toString()
          Deprecated. As of 7.0, use getValue() to get the value of the label or getPropertyDataSource().getValue() to get the value of the data source.
 void valueChange(Property.ValueChangeEvent event)
          Listens the value change events from data source.
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setParent, setPrimaryStyleName, setReadOnly, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Property
isReadOnly, setReadOnly
 
Methods inherited from interface com.vaadin.ui.Component
getUI
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

Field Detail

CONTENT_TEXT

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_TEXT
Deprecated. As of 7.0, use ContentMode.TEXT instead

CONTENT_PREFORMATTED

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_PREFORMATTED
Deprecated. As of 7.0, use ContentMode.PREFORMATTED instead

CONTENT_XHTML

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_XHTML
Deprecated. As of 7.0, use ContentMode.HTML instead

CONTENT_XML

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_XML
Deprecated. As of 7.0, use ContentMode.XML instead

CONTENT_RAW

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_RAW
Deprecated. As of 7.0, use ContentMode.RAW instead

CONTENT_DEFAULT

@Deprecated
public static final com.vaadin.shared.ui.label.ContentMode CONTENT_DEFAULT
Deprecated. As of 7.0, use ContentMode.TEXT instead
Constructor Detail

Label

public Label()
Creates an empty Label.


Label

public Label(java.lang.String content)
Creates a new instance of Label with text-contents.

Parameters:
content -

Label

public Label(Property contentSource)
Creates a new instance of Label with text-contents read from given datasource.

Parameters:
contentSource -

Label

public Label(java.lang.String content,
             com.vaadin.shared.ui.label.ContentMode contentMode)
Creates a new instance of Label with text-contents.

Parameters:
content -
contentMode -

Label

public Label(Property contentSource,
             com.vaadin.shared.ui.label.ContentMode contentMode)
Creates a new instance of Label with text-contents read from given datasource.

Parameters:
contentSource -
contentMode -
Method Detail

getState

protected com.vaadin.shared.ui.label.LabelState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractComponent
Returns:
updated component shared state

getState

protected com.vaadin.shared.ui.label.LabelState getState(boolean markAsDirty)
Description copied from class: AbstractClientConnector
Returns the shared state for this connector.

Overrides:
getState in class AbstractComponent
Parameters:
markAsDirty - true if the connector should automatically be marked dirty, false otherwise
Returns:
The shared state for this connector. Never null.
See Also:
AbstractClientConnector.getState()

getValue

public java.lang.String getValue()
Gets the value of the label.

The value of the label is the text that is shown to the end user. Depending on the ContentMode it is plain text or markup.

Specified by:
getValue in interface Property<java.lang.String>
Returns:
the value of the label.

setValue

public void setValue(java.lang.String newStringValue)
Set the value of the label. Value of the label is the XML contents of the label. Since Vaadin 7.2, changing the value of Label instance with that method will fire ValueChangeEvent.

Specified by:
setValue in interface Property<java.lang.String>
Parameters:
newStringValue - the New value of the label.

getType

public java.lang.Class<java.lang.String> getType()
Gets the type of the Property.

Specified by:
getType in interface Property<java.lang.String>
Returns:
type of the Property
See Also:
Property.getType()

getPropertyDataSource

public Property getPropertyDataSource()
Gets the viewing data-source property.

Specified by:
getPropertyDataSource in interface Property.Viewer
Returns:
the data source property.
See Also:
Property.Viewer.getPropertyDataSource()

setPropertyDataSource

public void setPropertyDataSource(Property newDataSource)
Sets the property as data-source for viewing. Since Vaadin 7.2 a ValueChangeEvent is fired if the new value is different from previous.

Specified by:
setPropertyDataSource in interface Property.Viewer
Parameters:
newDataSource - the new data source Property
See Also:
Property.Viewer.setPropertyDataSource(com.vaadin.data.Property)

getContentMode

public com.vaadin.shared.ui.label.ContentMode getContentMode()
Gets the content mode of the Label.

Returns:
the Content mode of the label.
See Also:
ContentMode

setContentMode

public void setContentMode(com.vaadin.shared.ui.label.ContentMode contentMode)
Sets the content mode of the Label.

Parameters:
contentMode - the New content mode of the label.
See Also:
ContentMode

addValueChangeListener

public void addValueChangeListener(Property.ValueChangeListener listener)
Adds the value change listener.

Specified by:
addValueChangeListener in interface Property.ValueChangeNotifier
Parameters:
listener - the Listener to be added.
See Also:
Property.ValueChangeNotifier.addListener(com.vaadin.data.Property.ValueChangeListener)

addListener

@Deprecated
public void addListener(Property.ValueChangeListener listener)
Deprecated. As of 7.0, replaced by addValueChangeListener(com.vaadin.data.Property.ValueChangeListener)

Specified by:
addListener in interface Property.ValueChangeNotifier

removeValueChangeListener

public void removeValueChangeListener(Property.ValueChangeListener listener)
Removes the value change listener.

Specified by:
removeValueChangeListener in interface Property.ValueChangeNotifier
Parameters:
listener - the Listener to be removed.
See Also:
Property.ValueChangeNotifier.removeListener(com.vaadin.data.Property.ValueChangeListener)

removeListener

@Deprecated
public void removeListener(Property.ValueChangeListener listener)
Deprecated. As of 7.0, replaced by removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener)

Specified by:
removeListener in interface Property.ValueChangeNotifier

fireValueChange

protected void fireValueChange()
Emits the options change event.


valueChange

public void valueChange(Property.ValueChangeEvent event)
Listens the value change events from data source.

Specified by:
valueChange in interface Property.ValueChangeListener
Parameters:
event - value change event object
See Also:
Property.ValueChangeListener.valueChange(Property.ValueChangeEvent)

attach

public void attach()
Description copied from interface: ClientConnector
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).

The caller of this method is #setParent(ClientConnector) if the parent is itself already attached to the session. If not, the parent will call the ClientConnector.attach() for all its children when it is attached to the session. This method is always called before the connector's data is sent to the client-side for the first time.

The attachment logic is implemented in AbstractClientConnector.

Specified by:
attach in interface ClientConnector
Specified by:
attach in interface Component
Overrides:
attach in class AbstractComponent

setLocale

public void setLocale(java.util.Locale locale)
Description copied from class: AbstractComponent
Sets the locale of this component.
 // Component for which the locale is meaningful
 InlineDateField date = new InlineDateField("Datum");
 
 // German language specified with ISO 639-1 language
 // code and ISO 3166-1 alpha-2 country code.
 date.setLocale(new Locale("de", "DE"));
 
 date.setResolution(DateField.RESOLUTION_DAY);
 layout.addComponent(date);
 

Overrides:
setLocale in class AbstractComponent
Parameters:
locale - the locale to become this component's locale.

compareTo

public int compareTo(Label other)
Compares the Label to other objects.

Labels can be compared to other labels for sorting label contents. This is especially handy for sorting table columns.

In RAW, PREFORMATTED and TEXT modes, the label contents are compared as is. In XML, UIDL and HTML modes, only CDATA is compared and tags ignored. If the other object is not a Label, its toString() return value is used in comparison.

Specified by:
compareTo in interface java.lang.Comparable<Label>
Parameters:
other - the Other object to compare to.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
See Also:
Comparable.compareTo(java.lang.Object)

getConverter

public Converter<java.lang.String,java.lang.Object> getConverter()
Gets the converter used to convert the property data source value to the label value.

Returns:
The converter or null if none is set.

setConverter

public void setConverter(Converter<java.lang.String,?> converter)
Sets the converter used to convert the label value to the property data source type. The converter must have a presentation type of String.

Parameters:
converter - The new converter to use.

toString

@Deprecated
public java.lang.String toString()
Deprecated. As of 7.0, use getValue() to get the value of the label or getPropertyDataSource().getValue() to get the value of the data source.

Returns a string representation of this object. The returned string representation depends on if the legacy Property toString mode is enabled or disabled.

If legacy Property toString mode is enabled, returns the value displayed by this label.

If legacy Property toString mode is disabled, the string representation has no special meaning

Overrides:
toString in class java.lang.Object
Returns:
The value displayed by this label or a string representation of this Label object.
See Also:
AbstractProperty#isLegacyToStringEnabled()


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.