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

public class Label
extends AbstractComponent
implements Property, Property.Viewer, Property.ValueChangeListener, Property.ValueChangeNotifier, Comparable<Object>

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
The b,i,u and li tags can contain all the tags in the list recursively.

Since:

3.0

Version:

6.8.18

Author:

Vaadin Ltd.

See Also:

Serialized Form

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 com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addListener, addStyleName, attach, changeVariables, childRequestedRepaint, detach, fireComponentErrorEvent, fireComponentEvent, fireEvent, focus, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, hasListeners, isEnabled, isImmediate, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, setWidth, setWidthUnits
 
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

Content mode, where the label contains only plain text. The getValue() result is coded to XML when painting.

See Also:
Constant Field Values

CONTENT_PREFORMATTED

public static final int CONTENT_PREFORMATTED

Content mode, where the label contains preformatted text.

See Also:
Constant Field Values

CONTENT_UIDL

@Deprecated
public static final int CONTENT_UIDL

Deprecated. Use CONTENT_XML instead.

Formatted content mode, where the contents is XML restricted to the UIDL 1.0 formatting markups.

See Also:
Constant Field Values

CONTENT_XHTML

public static final int 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".

See Also:
Constant Field Values

CONTENT_XML

public static final int 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.

See Also:
Constant Field Values

CONTENT_RAW

public static final int 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.

See Also:
Constant Field Values

CONTENT_DEFAULT

public static final int CONTENT_DEFAULT

The default content mode is plain text.

See Also:
Constant Field Values

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,
             int contentMode)

Creates a new instance of Label with text-contents.

Parameters:
content -
contentMode -

Label

public Label(Property contentSource,
             int contentMode)

Creates a new instance of Label with text-contents read from given datasource.

Parameters:
contentSource -
contentMode -

Method Detail

setReadOnly

public void setReadOnly(boolean readOnly)

Set the component to read-only. Readonly is not used in label.

Specified by:
setReadOnly in interface Property
Specified by:
setReadOnly in interface Component
Overrides:
setReadOnly in class AbstractComponent

Parameters:
readOnly - True to enable read-only mode, False to disable it.

isReadOnly

public boolean isReadOnly()

Is the component read-only ? Readonly is not used in label - this returns allways false.

Specified by:
isReadOnly in interface Property
Specified by:
isReadOnly in interface Component
Overrides:
isReadOnly in class AbstractComponent

Returns:
true if the component is in read only mode.
See Also:
Component.setReadOnly(boolean)

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException

Paints the content of this component.

Overrides:
paintContent in class AbstractComponent

Parameters:
target - the Paint Event.
Throws:
PaintException - if the Paint Operation fails.

getValue

public Object getValue()

Gets the value of the label. Value of the label is the XML contents of the label.

Specified by:
getValue in interface Property

Returns:
the Value of the label.

setValue

public void setValue(Object newValue)

Set the value of the label. Value of the label is the XML contents of the label.

Specified by:
setValue in interface Property

Parameters:
newValue - the New value of the label.

toString

public String 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.

Specified by:
toString in interface Property
Overrides:
toString in class Object

Returns:
String representation of the value stored in the Property
See Also:
Object.toString()

getType

public Class getType()

Gets the type of the Property.

Specified by:
getType in interface Property

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.

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 int getContentMode()

Gets the content mode of the Label.

Possible content modes include:

  • 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.

setContentMode

public void setContentMode(int contentMode)

Sets the content mode of the Label.

Possible content modes include:

  • 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.

addListener

public void addListener(Property.ValueChangeListener listener)

Adds the value change listener.

Specified by:
addListener in interface Property.ValueChangeNotifier

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

removeListener

public void removeListener(Property.ValueChangeListener listener)

Removes the value change listener.

Specified by:
removeListener in interface Property.ValueChangeNotifier

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

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)

compareTo

public int compareTo(Object 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 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.

Specified by:
compareTo in interface Comparable<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)