com.vaadin.ui.
Class Label
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.Label
All Implemented Interfaces:
Property, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Serializable, Comparable<Object>, EventListener
- extends AbstractComponent
- implements Property, Property.Viewer, Property.ValueChangeListener, Property.ValueChangeNotifier, Comparable<Object>
public class Label
Label component for showing non-editable short texts. The label content can be set to the modes specified by the final members CONTENT_*
The 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
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
class |
Label.ValueChangeEvent
Value change event |
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent |
---|
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler |
Nested classes/interfaces inherited from interface com.vaadin.data.Property |
---|
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeEvent, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer |
Nested classes/interfaces inherited from interface com.vaadin.ui.Component |
---|
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener |
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable |
---|
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener |
Field Summary | |
---|---|
static int |
CONTENT_DEFAULT
The default content mode is plain text. |
static int |
CONTENT_PREFORMATTED
Content mode, where the label contains preformatted text. |
static int |
CONTENT_RAW
Content mode, where the label contains RAW output. |
static int |
CONTENT_TEXT
Content mode, where the label contains only plain text. |
static int |
CONTENT_UIDL
Deprecated. Use CONTENT_XML instead. |
static int |
CONTENT_XHTML
Content mode, where the label contains XHTML. |
static int |
CONTENT_XML
Content mode, where the label contains well-formed or well-balanced XML. |
Fields inherited from interface com.vaadin.terminal.Sizeable |
---|
SIZE_UNDEFINED, UNIT_SYMBOLS, 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,
int 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,
int contentMode)
Creates a new instance of Label with text-contents. |
Method Summary | |
---|---|
void |
addListener(Property.ValueChangeListener listener)
Adds the value change listener. |
int |
compareTo(Object other)
Compares the Label to other objects. |
protected void |
fireValueChange()
Emits the options change event. |
int |
getContentMode()
Gets the content mode of the Label. |
Property |
getPropertyDataSource()
Gets the viewing data-source property. |
Class |
getType()
Gets the type of the Property. |
Object |
getValue()
Gets the value of the label. |
boolean |
isReadOnly()
Is the component read-only ? Readonly is not used in label - this returns allways false. |
void |
paintContent(PaintTarget target)
Paints the content of this component. |
void |
removeListener(Property.ValueChangeListener listener)
Removes the value change listener. |
void |
setContentMode(int contentMode)
Sets the content mode of the Label. |
void |
setPropertyDataSource(Property newDataSource)
Sets the property as data-source for viewing. |
void |
setReadOnly(boolean readOnly)
Set the component to read-only. |
void |
setValue(Object newValue)
Set the value of the label. |
String |
toString()
Returns the value of the Property in human readable textual format. |
void |
valueChange(Property.ValueChangeEvent event)
Listens the value change events from data source. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
CONTENT_TEXT
public static final int CONTENT_TEXT
- See Also:
- Constant Field Values
Content mode, where the label contains only plain text. The getValue() result is coded to XML when painting.
CONTENT_PREFORMATTED
public static final int CONTENT_PREFORMATTED
- See Also:
- Constant Field Values
Content mode, where the label contains preformatted text.
CONTENT_UIDL
@Deprecated
public static final int CONTENT_UIDL
- See Also:
- Constant Field Values
Deprecated. Use CONTENT_XML instead.
Formatted content mode, where the contents is XML restricted to the UIDL 1.0 formatting markups.
CONTENT_XHTML
public static final int CONTENT_XHTML
- See Also:
- Constant Field Values
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".
CONTENT_XML
public static final int CONTENT_XML
- See Also:
- Constant Field Values
Content mode, where the label contains well-formed or well-balanced XML. Each of the root elements must have their default namespace specified.
CONTENT_RAW
public static final int CONTENT_RAW
- See Also:
- Constant Field Values
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.
CONTENT_DEFAULT
public static final int CONTENT_DEFAULT
- See Also:
- Constant Field Values
The default content mode is plain text.
Constructor Detail |
---|
Label
public Label()
Creates an empty Label.
Label
public Label(String content)
- Parameters:
content
-
Creates a new instance of Label with text-contents.
Label
public Label(Property contentSource)
- Parameters:
contentSource
-
Creates a new instance of Label with text-contents read from given datasource.
Label
public Label(String content,
int contentMode)
- Parameters:
content
-contentMode
-
Creates a new instance of Label with text-contents.
Label
public Label(Property contentSource,
int contentMode)
- Parameters:
contentSource
-contentMode
-
Creates a new instance of Label with text-contents read from given datasource.
Method Detail |
---|
setReadOnly
public void setReadOnly(boolean readOnly)
- Specified by:
setReadOnly
in interfaceProperty
- Specified by:
setReadOnly
in interfaceComponent
- Overrides:
setReadOnly
in classAbstractComponent
- Parameters:
readOnly
- True to enable read-only mode, False to disable it.
Set the component to read-only. Readonly is not used in label.
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceProperty
- Specified by:
isReadOnly
in interfaceComponent
- Overrides:
isReadOnly
in classAbstractComponent
- Returns:
true
if the component is in read only mode.- See Also:
Component.setReadOnly(boolean)
Is the component read-only ? Readonly is not used in label - this returns allways false.
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractComponent
- Parameters:
target
- the Paint Event.- Throws:
PaintException
- if the Paint Operation fails.
Paints the content of this component.
getValue
public Object getValue()
- Returns:
- the Value of the label.
Gets the value of the label. Value of the label is the XML contents of the label.
setValue
public void setValue(Object newValue)
- Parameters:
newValue
- the New value of the label.
Set the value of the label. Value of the label is the XML contents of the label.
toString
public String toString()
- Returns:
String
representation of the value stored in the Property- See Also:
Object.toString()
Description copied from interface: Property
Returns the value of the Property in human readable textual format. The
return value should be assignable to the setValue
method if
the Property is not in read-only mode.
getType
public Class getType()
- Returns:
- type of the Property
- See Also:
Property.getType()
Gets the type of the Property.
getPropertyDataSource
public Property getPropertyDataSource()
- Specified by:
getPropertyDataSource
in interfaceProperty.Viewer
- Returns:
- the data source property.
- See Also:
Property.Viewer.getPropertyDataSource()
Gets the viewing data-source property.
setPropertyDataSource
public void setPropertyDataSource(Property newDataSource)
- Specified by:
setPropertyDataSource
in interfaceProperty.Viewer
- Parameters:
newDataSource
- the new data source Property- See Also:
Property.Viewer.setPropertyDataSource(com.vaadin.data.Property)
Sets the property as data-source for viewing.
getContentMode
public int getContentMode()
- CONTENT_TEXT Content mode, where the label contains only plain text. The getValue() result is coded to XML when painting.
- CONTENT_PREFORMATTED Content mode, where the label contains preformatted text.
- CONTENT_UIDL Formatted content mode, where the contents is XML restricted to the UIDL 1.0 formatting markups.
- CONTENT_XHTML 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".
- CONTENT_XML Content mode, where the label contains well-formed or well-balanced XML. Each of the root elements must have their default namespace specified.
- CONTENT_RAW 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.
- Returns:
- the Content mode of the label.
Gets the content mode of the Label.
Possible content modes include:
setContentMode
public void setContentMode(int contentMode)
- CONTENT_TEXT Content mode, where the label contains only plain text. The getValue() result is coded to XML when painting.
- CONTENT_PREFORMATTED Content mode, where the label contains preformatted text.
- CONTENT_UIDL Formatted content mode, where the contents is XML restricted to the UIDL 1.0 formatting markups.
- CONTENT_XHTML 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".
- CONTENT_XML Content mode, where the label contains well-formed or well-balanced XML. Each of the root elements must have their default namespace specified.
- CONTENT_RAW 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.
- Parameters:
contentMode
- the New content mode of the label.
Sets the content mode of the Label.
Possible content modes include:
addListener
public void addListener(Property.ValueChangeListener listener)
- Specified by:
addListener
in interfaceProperty.ValueChangeNotifier
- Parameters:
listener
- the Listener to be added.- See Also:
Property.ValueChangeNotifier.addListener(com.vaadin.data.Property.ValueChangeListener)
Adds the value change listener.
removeListener
public void removeListener(Property.ValueChangeListener listener)
- Specified by:
removeListener
in interfaceProperty.ValueChangeNotifier
- Parameters:
listener
- the Listener to be removed.- See Also:
Property.ValueChangeNotifier.removeListener(com.vaadin.data.Property.ValueChangeListener)
Removes the value change listener.
fireValueChange
protected void fireValueChange()
Emits the options change event.
valueChange
public void valueChange(Property.ValueChangeEvent event)
- Specified by:
valueChange
in interfaceProperty.ValueChangeListener
- Parameters:
event
- value change event object- See Also:
Property.ValueChangeListener.valueChange(Property.ValueChangeEvent)
Listens the value change events from data source.
compareTo
public int compareTo(Object other)
- Specified by:
compareTo
in interfaceComparable<Object>
- 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)
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 XHTML modes, only CDATA is compared and tags ignored. If the other object is not a Label, its toString() return value is used in comparison.