Class Label
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.Label
-
- All Implemented Interfaces:
Property<String>,Property.ValueChangeListener,Property.ValueChangeNotifier,Property.Viewer,ContextClickEvent.ContextClickNotifier,MethodEventSource,ClientConnector,Sizeable,Connector,Component,Serializable,Comparable<Label>
public class Label extends AbstractComponent implements Property<String>, Property.Viewer, Property.ValueChangeListener, Property.ValueChangeNotifier, Comparable<Label>
Label component for showing non-editable short texts. The label content can be set to the modes specified byContentModeThe contents of the label may contain simple formatting:
- <b> Bold
- <i> Italic
- <u> Underlined
- <br/> Linebreak
- <ul><li>item 1</li><li>item 2</li></ul> List of items
- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLabel.ValueChangeEventValue change event-
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.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
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.server.Sizeable
Sizeable.Unit
-
-
Field Summary
Fields Modifier and Type Field Description static ContentModeCONTENT_DEFAULTDeprecated.As of 7.0, useContentMode.TEXTinsteadstatic ContentModeCONTENT_PREFORMATTEDDeprecated.As of 7.0, useContentMode.PREFORMATTEDinsteadstatic ContentModeCONTENT_RAWDeprecated.As of 7.0, useContentMode.RAWinsteadstatic ContentModeCONTENT_TEXTDeprecated.As of 7.0, useContentMode.TEXTinsteadstatic ContentModeCONTENT_XHTMLDeprecated.As of 7.0, useContentMode.HTMLinsteadstatic ContentModeCONTENT_XMLDeprecated.As of 7.0, useContentMode.XMLinstead-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
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
Constructors Constructor Description Label()Creates an empty Label.Label(Property contentSource)Creates a new instance of Label with text-contents read from given datasource.Label(Property contentSource, ContentMode contentMode)Creates a new instance of Label with text-contents read from given datasource.Label(String content)Creates a new instance of Label with text-contents.Label(String content, ContentMode contentMode)Creates a new instance of Label with text-contents.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddListener(Property.ValueChangeListener listener)Deprecated.As of 7.0, replaced byaddValueChangeListener(Property.ValueChangeListener)voidaddValueChangeListener(Property.ValueChangeListener listener)Adds the value change listener.voidattach()Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).intcompareTo(Label other)Compares the Label to other objects.protected voidfireValueChange()Emits the options change event.ContentModegetContentMode()Gets the content mode of the Label.Converter<String,Object>getConverter()Gets the converter used to convert the property data source value to the label value.protected Collection<String>getCustomAttributes()Returns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(org.jsoup.nodes.Element,com.vaadin.ui.declarative.DesignContext)andAbstractComponent.writeDesign(org.jsoup.nodes.Element,com.vaadin.ui.declarative.DesignContext)methods.PropertygetPropertyDataSource()Gets the viewing data-source property.protected LabelStategetState()Returns the shared state bean with information to be sent from the server to the client.protected LabelStategetState(boolean markAsDirty)Returns the shared state for this connector.Class<String>getType()Gets the type of the Property.StringgetValue()Gets the value of the label.voidreadDesign(org.jsoup.nodes.Element design, DesignContext designContext)Reads the component state from the given design.voidremoveListener(Property.ValueChangeListener listener)Deprecated.As of 7.0, replaced byremoveValueChangeListener(Property.ValueChangeListener)voidremoveValueChangeListener(Property.ValueChangeListener listener)Removes the value change listener.voidsetContentMode(ContentMode contentMode)Sets the content mode of the Label.voidsetConverter(Converter<String,?> converter)Sets the converter used to convert the label value to the property data source type.voidsetLocale(Locale locale)Sets the locale of this component.voidsetPropertyDataSource(Property newDataSource)Sets the property as data-source for viewing.voidsetValue(String newStringValue)Set the value of the label.StringtoString()Deprecated.As of 7.0, usegetValue()to get the value of the label orgetPropertyDataSource().getValue() to get the value of the data source.voidvalueChange(Property.ValueChangeEvent event)Listens the value change events from data source.voidwriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)Writes the component state to the given design.-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, 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.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
-
Methods inherited from interface com.vaadin.data.Property
isReadOnly, setReadOnly
-
-
-
-
Field Detail
-
CONTENT_TEXT
@Deprecated public static final ContentMode CONTENT_TEXT
Deprecated.As of 7.0, useContentMode.TEXTinstead
-
CONTENT_PREFORMATTED
@Deprecated public static final ContentMode CONTENT_PREFORMATTED
Deprecated.As of 7.0, useContentMode.PREFORMATTEDinstead
-
CONTENT_XHTML
@Deprecated public static final ContentMode CONTENT_XHTML
Deprecated.As of 7.0, useContentMode.HTMLinstead
-
CONTENT_XML
@Deprecated public static final ContentMode CONTENT_XML
Deprecated.As of 7.0, useContentMode.XMLinstead
-
CONTENT_RAW
@Deprecated public static final ContentMode CONTENT_RAW
Deprecated.As of 7.0, useContentMode.RAWinstead
-
CONTENT_DEFAULT
@Deprecated public static final ContentMode CONTENT_DEFAULT
Deprecated.As of 7.0, useContentMode.TEXTinstead
-
-
Constructor Detail
-
Label
public Label()
Creates an empty Label.
-
Label
public Label(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(String content, ContentMode contentMode)
Creates a new instance of Label with text-contents.- Parameters:
content-contentMode-
-
Label
public Label(Property contentSource, ContentMode contentMode)
Creates a new instance of Label with text-contents read from given datasource.- Parameters:
contentSource-contentMode-
-
-
Method Detail
-
getState
protected LabelState getState()
Description copied from class:AbstractComponentReturns 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:
getStatein classAbstractComponent- Returns:
- updated component shared state
-
getState
protected LabelState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractComponent- 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 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
ContentModeit is plain text or markup.
-
setValue
public void setValue(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.
-
getType
public Class<String> getType()
Gets the type of the Property.- Specified by:
getTypein interfaceProperty<String>- Returns:
- type of the Property
- See Also:
Property.getType()
-
getPropertyDataSource
public Property getPropertyDataSource()
Gets the viewing data-source property.- Specified by:
getPropertyDataSourcein interfaceProperty.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:
setPropertyDataSourcein interfaceProperty.Viewer- Parameters:
newDataSource- the new data source Property- See Also:
Property.Viewer.setPropertyDataSource(Property)
-
getContentMode
public ContentMode getContentMode()
Gets the content mode of the Label.- Returns:
- the Content mode of the label.
- See Also:
ContentMode
-
setContentMode
public void setContentMode(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:
addValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- the Listener to be added.- See Also:
Property.ValueChangeNotifier.addListener(Property.ValueChangeListener)
-
addListener
@Deprecated public void addListener(Property.ValueChangeListener listener)
Deprecated.As of 7.0, replaced byaddValueChangeListener(Property.ValueChangeListener)- Specified by:
addListenerin interfaceProperty.ValueChangeNotifier
-
removeValueChangeListener
public void removeValueChangeListener(Property.ValueChangeListener listener)
Removes the value change listener.- Specified by:
removeValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- the Listener to be removed.- See Also:
Property.ValueChangeNotifier.removeListener(Property.ValueChangeListener)
-
removeListener
@Deprecated public void removeListener(Property.ValueChangeListener listener)
Deprecated.As of 7.0, replaced byremoveValueChangeListener(Property.ValueChangeListener)- Specified by:
removeListenerin interfaceProperty.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:
valueChangein interfaceProperty.ValueChangeListener- Parameters:
event- value change event object- See Also:
Property.ValueChangeListener.valueChange(Property.ValueChangeEvent)
-
attach
public void attach()
Description copied from interface:ClientConnectorNotifies 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 theClientConnector.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:
attachin interfaceClientConnector- Specified by:
attachin interfaceComponent- Overrides:
attachin classAbstractComponent
-
setLocale
public void setLocale(Locale locale)
Description copied from class:AbstractComponentSets 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:
setLocalein classAbstractComponent- 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:
compareToin interfaceComparable<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<String,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<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 String toString()
Deprecated.As of 7.0, usegetValue()to get the value of the label orgetPropertyDataSource().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
-
readDesign
public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)Description copied from interface:ComponentReads the component state from the given design.The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
- Specified by:
readDesignin interfaceComponent- Overrides:
readDesignin classAbstractComponent- Parameters:
design- The element to obtain the state fromdesignContext- The DesignContext instance used for parsing the design
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:AbstractComponentReturns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(org.jsoup.nodes.Element,com.vaadin.ui.declarative.DesignContext)andAbstractComponent.writeDesign(org.jsoup.nodes.Element,com.vaadin.ui.declarative.DesignContext)methods. Typically these are handled in a custom way in the overridden versions of the above methods- Overrides:
getCustomAttributesin classAbstractComponent- Returns:
- the collection of attributes that are not handled by the basic implementation
-
writeDesign
public void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)Description copied from interface:ComponentWrites the component state to the given design.The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
- Specified by:
writeDesignin interfaceComponent- Overrides:
writeDesignin classAbstractComponent- Parameters:
design- The element to write the component state to. Any previous attributes or child nodes are not cleared.designContext- The DesignContext instance used for writing the design
-
-