Java DTV API 1.3
18-Nov-2009

com.sun.dtv.lwuit
Class Label

java.lang.Object
  extended by com.sun.dtv.lwuit.Component
      extended by com.sun.dtv.lwuit.Label
All Implemented Interfaces:
Animation, StyleListener, Animated, MatteEnabled, ViewOnlyComponent
Direct Known Subclasses:
Button, DefaultListCellRenderer

public class Label
extends Component
implements ViewOnlyComponent

Allows displaying labels and images with different alignment options, this class is a base class for several components allowing them to declare alignment/icon look in a similar way.


Field Summary
 
Fields inherited from class com.sun.dtv.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Fields inherited from interface com.sun.dtv.ui.ViewOnlyComponent
HORIZONTAL_ALIGN_CENTER, HORIZONTAL_ALIGN_JUSTIFIED, HORIZONTAL_ALIGN_LEFT, HORIZONTAL_ALIGN_RIGHT, SCALE_ASPECT_PROOF, SCALE_NO, SCALE_NO_ASPECT_PROOF, STATE_DISABLED, STATE_ENABLED, VERTICAL_ALIGN_BOTTOM, VERTICAL_ALIGN_CENTER, VERTICAL_ALIGN_JUSTIFIED, VERTICAL_ALIGN_TOP
 
Fields inherited from interface com.sun.dtv.ui.Animated
ALTERNATING, LOOP, REPEATING
 
Constructor Summary
Label()
          Construct an empty label.
Label(Image icon)
          Constructs a new label with the specified icon.
Label(String text)
          Constructs a new label with the specified string of text, left justified.
 
Method Summary
 boolean animate()
          Allows the animation to reduce "repaint" calls when it returns false.
 int getAlignment()
          Returns the alignment of the Label.
 Image[] getAnimateContent(int state)
          Returns the animated content for this component, depending on the current state.
 int getBaselineResizeBehavior()
          Returns a constant indicating how the baseline varies with the size of the component.
 int getGap()
          Returns the gap in pixels between the icon/text to the Label boundaries.
 Image getGraphicContent(int state)
          Returns the graphical content for this component, depending on the current state.
 int getHorizontalAlignment()
          Retrieve the horizontal alignment for any state-based content in this component.
 Image getIcon()
          Returns the labels icon.
 int getInteractionState()
          Return the current interaction state of the component.
 Matte getMatte()
          Return the Matte currently associated with the component implementing this interface.
 int getScalingMode()
          Retrieve the scaling mode for this component.
 int getShiftText()
          Simple getter to return how many pixels to shift the text inside the Label.
 String getText()
          Returns the label text.
 String getTextContent(int state)
          Returns the text content for this component, depending on the current state.
 TextLayoutManager getTextLayoutManager()
          Gets the text layout manager that is currently in use for text layout in this component.
 int getTextPosition()
          Returns The position of the text relative to the icon.
 int getVerticalAlignment()
          Retrieve the vertical alignment for any state-based content in this component.
 boolean isDoubleBuffered()
          Returns true if double buffering is available and activated.
 boolean isEndsWith3Points()
          Simple getter.
 boolean isOpaque()
          Returns true if the whole area of the Component (as returned by the com.sun.dtv.lwuit.Component#getBounds method, is opaque.
 boolean isTickerEnabled()
          This method return true if the ticker is enabled on this Label.
 boolean isTickerRunning()
          Returns true if the ticker is running.
 void paint(Graphics g)
          This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
 void processEvent(AWTEvent event)
          Handle the specified AWTEvent.
 void setAlignment(int align)
          Convenience method, similar to #setHorizontalAlignment
 void setAnimateContent(Image[] images, int state)
          Assigns an array of graphical content to be used for animation to this component which is state-dependent.
 void setEndsWith3Points(boolean endsWith3Points)
          If the Label text is too long fit the text to the widget and add "..."
 void setGap(int gap)
          Set the gap in pixels between the icon/text to the Label boundaries.
 void setGraphicContent(Image image, int state)
          Assigns graphical content to this component which is state-dependent.
 void setHorizontalAlignment(int alignment)
          Set the horizontal alignment for any state-based content in this component.
 void setIcon(Image icon)
          Sets the Label icon.
 void setInteractionState(int state)
          Set the current state of the component with respect to interaction.
 void setMatte(Matte matte)
          Adds an Matte to the component implementing this interface in order to enable matte compositing.
 void setScalingMode(int scaling)
          Set the scaling mode for this component.
 void setShiftText(int shiftText)
          This method shifts the text from it's position in pixels.
 void setText(String text)
          Sets the Label text.
 void setTextContent(String text, int state)
          Assigns text content to this component which is state-dependent.
 void setTextLayoutManager(TextLayoutManager manager)
          Sets the text layout manager that should be used for text layout in this component.
 void setTextPosition(int textPosition)
          Sets the position of the text relative to the icon if exists.
 void setTickerEnabled(boolean tickerEnabled)
          Sets the Label to allow ticking of the text.
 void setVerticalAlignment(int valign)
          Set the vertical alignment for any state-based content in this component.
 void startTicker(long delay, boolean rightToLeft)
          This method will start the text ticker.
 void stopTicker()
          Stops the text ticker.
 
Methods inherited from class com.sun.dtv.lwuit.Component
addFocusListener, calcPreferredSize, contains, deinitialize, getAbsoluteX, getAbsoluteY, getAnimationMode, getBaseline, getBottomGap, getBounds, getClientProperty, getComponentForm, getDelay, getHeight, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPosition, getPreferredSize, getRepetitionMode, getScrollAnimationSpeed, getScrollX, getScrollY, getSideGap, getStyle, getUIID, getWidth, getX, getY, handlesInput, hasFocus, initialize, isEnabled, isFocusable, isFocusPainted, isInitialized, isRunning, isScrollableX, isScrollableY, isScrollVisible, isSmoothScrolling, isVisible, jumpTo, keyPressed, keyReleased, keyRepeated, longKeyPress, paintBackgrounds, paintComponent, paintComponent, pointerDragged, pointerPressed, pointerReleased, putClientProperty, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, setAnimationMode, setCellRenderer, setDelay, setEnabled, setFocus, setFocusable, setFocusPainted, setHandlesInput, setHeight, setInitialized, setIsScrollVisible, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredSize, setRepetitionMode, setScrollAnimationSpeed, setScrollX, setScrollY, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setStyle, setUIID, setVisible, setWidth, setX, setY, start, stop, styleChanged, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Label

public Label(String text)
Constructs a new label with the specified string of text, left justified.

Parameters:
text - the string that the label presents.

Label

public Label()
Construct an empty label.


Label

public Label(Image icon)
Constructs a new label with the specified icon.

Parameters:
icon - the image that the label presents.
Method Detail

getBaselineResizeBehavior

public int getBaselineResizeBehavior()
Description copied from class: Component
Returns a constant indicating how the baseline varies with the size of the component.

Overrides:
getBaselineResizeBehavior in class Component
Returns:
one of BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET or BRB_OTHER

setText

public void setText(String text)
Sets the Label text. Convenience method, similar to #setTextContent

Parameters:
text - the string that the label presents.
See Also:
getText()

getText

public String getText()
Returns the label text. Convenience method, similar to #getTextContent

Returns:
the label text
See Also:
setText(java.lang.String)

setIcon

public void setIcon(Image icon)
Sets the Label icon. Convenience method, similar to #setGraphicsContent

Parameters:
icon - the image that the label presents.
See Also:
getIcon()

getIcon

public Image getIcon()
Returns the labels icon. Convenience method, similar to #getGraphicsContent

Returns:
the labels icon
See Also:
setIcon(com.sun.dtv.lwuit.Image)

setAlignment

public void setAlignment(int align)
Convenience method, similar to #setHorizontalAlignment


setVerticalAlignment

public void setVerticalAlignment(int valign)
Description copied from interface: ViewOnlyComponent
Set the vertical alignment for any state-based content in this component.

Specified by:
setVerticalAlignment in interface ViewOnlyComponent
Parameters:
valign - the vertical alignment mode, one of ViewOnlyComponent.VERTICAL_ALIGN_TOP, ViewOnlyComponent.VERTICAL_ALIGN_CENTER, ViewOnlyComponent.VERTICAL_ALIGN_BOTTOM or ViewOnlyComponent.VERTICAL_ALIGN_JUSTIFIED.
See Also:
ViewOnlyComponent.getVerticalAlignment()

getVerticalAlignment

public int getVerticalAlignment()
Description copied from interface: ViewOnlyComponent
Retrieve the vertical alignment for any state-based content in this component.

Specified by:
getVerticalAlignment in interface ViewOnlyComponent
Returns:
the current horizontal alignment mode, one of ViewOnlyComponent.VERTICAL_ALIGN_TOP, ViewOnlyComponent.VERTICAL_ALIGN_CENTER, ViewOnlyComponent.VERTICAL_ALIGN_BOTTOM or ViewOnlyComponent.VERTICAL_ALIGN_JUSTIFIED.
See Also:
ViewOnlyComponent.setVerticalAlignment(int)

getAlignment

public int getAlignment()
Returns the alignment of the Label. Convenience method, similar to #getHorizontalAlignment

Returns:
the current alignment mode, one of ViewOnlyComponent.HORIZONTAL_ALIGN_LEFT, ViewOnlyComponent.HORIZONTAL_ALIGN_CENTER, ViewOnlyComponent.HORIZONTAL_ALIGN_RIGHT or ViewOnlyComponent.HORIZONTAL_ALIGN_JUSTIFIED.
See Also:
setAlignment(int)

setTextPosition

public void setTextPosition(int textPosition)
Sets the position of the text relative to the icon if exists.

Parameters:
textPosition - alignment value (LEFT, RIGHT, BOTTOM or TOP)
See Also:
getTextPosition(), Component.LEFT, Component.RIGHT, Component.BOTTOM, Component.TOP

getTextPosition

public int getTextPosition()
Returns The position of the text relative to the icon.

Returns:
The position of the text relative to the icon, one of: LEFT, RIGHT, BOTTOM, TOP
See Also:
setTextPosition(int), Component.LEFT, Component.RIGHT, Component.BOTTOM, Component.TOP

setGap

public void setGap(int gap)
Set the gap in pixels between the icon/text to the Label boundaries.

Parameters:
gap - the gap in pixels
See Also:
getGap()

getGap

public int getGap()
Returns the gap in pixels between the icon/text to the Label boundaries.

Returns:
the gap in pixels between the icon/text to the Label boundaries
See Also:
setGap(int)

paint

public void paint(Graphics g)
Description copied from class: Component
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

Specified by:
paint in interface Animation
Specified by:
paint in interface ViewOnlyComponent
Overrides:
paint in class Component
Parameters:
g - the component graphics

getShiftText

public int getShiftText()
Simple getter to return how many pixels to shift the text inside the Label.

Returns:
number of pixels to shift
See Also:
setShiftText(int)

setShiftText

public void setShiftText(int shiftText)
This method shifts the text from it's position in pixels. The value can be positive/negative to move the text to the right/left.

Parameters:
shiftText - The number of pixels to move the text
See Also:
getShiftText()

startTicker

public void startTicker(long delay,
                        boolean rightToLeft)
This method will start the text ticker.

Parameters:
delay - the delay in milliseconds between animation intervals
rightToLeft - if true move the text to the left

stopTicker

public void stopTicker()
Stops the text ticker.


isTickerRunning

public boolean isTickerRunning()
Returns true if the ticker is running.

Returns:
true if the ticker is running

setTickerEnabled

public void setTickerEnabled(boolean tickerEnabled)
Sets the Label to allow ticking of the text. By default is true.

Parameters:
tickerEnabled - indicate whether ticker is enabled

isTickerEnabled

public boolean isTickerEnabled()
This method return true if the ticker is enabled on this Label.

Returns:
true if ticker is enabled, false otherwise

setEndsWith3Points

public void setEndsWith3Points(boolean endsWith3Points)
If the Label text is too long fit the text to the widget and add "..." points at the end. By default this is set to true.

Parameters:
endsWith3Points - true if text should add "..." at the end

isEndsWith3Points

public boolean isEndsWith3Points()
Simple getter.

Returns:
true if this Label adds "..." when the text is too long

animate

public boolean animate()
Description copied from interface: Animation
Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame.

Specified by:
animate in interface Animation
Overrides:
animate in class Component
Returns:
true if a repaint is desired or false if no repaint is necessary

setTextContent

public void setTextContent(String text,
                           int state)
                    throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Assigns text content to this component which is state-dependent.

Specified by:
setTextContent in interface ViewOnlyComponent
Parameters:
text - the text content, or null (removes text content which had been assigned before)
state - the state of the component for which this content should be displayed, one of STATE_ENABLED or STATE_DISABLED
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.getTextContent(int)

setGraphicContent

public void setGraphicContent(Image image,
                              int state)
                       throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Assigns graphical content to this component which is state-dependent.

Specified by:
setGraphicContent in interface ViewOnlyComponent
Parameters:
image - the graphical content, or null (removes graphical content which had been assigned before)
state - the state of the component for which this content should be displayed, one of STATE_ENABLED or STATE_DISABLED
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.getGraphicContent(int)

setAnimateContent

public void setAnimateContent(Image[] images,
                              int state)
                       throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Assigns an array of graphical content to be used for animation to this component which is state-dependent.

Specified by:
setAnimateContent in interface ViewOnlyComponent
Parameters:
images - the graphical content array, or null (removes any graphical content which had been assigned before)
state - the state of the component for which this content should be displayed, one of STATE_ENABLED or STATE_DISABLED
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.getAnimateContent(int)

getTextContent

public String getTextContent(int state)
                      throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Returns the text content for this component, depending on the current state.

Specified by:
getTextContent in interface ViewOnlyComponent
Parameters:
state - the state of the component for which this content is to be retrieved, one of STATE_ENABLED or STATE_DISABLED
Returns:
The text content associated with the specified state, or null if there is none.
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.setTextContent(java.lang.String, int)

getGraphicContent

public Image getGraphicContent(int state)
                        throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Returns the graphical content for this component, depending on the current state.

Specified by:
getGraphicContent in interface ViewOnlyComponent
Parameters:
state - the state of the component for which this content is to be retrieved, one of STATE_ENABLED or STATE_DISABLED
Returns:
The graphical content associated with the specified state, or null if there is none.
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.setGraphicContent(com.sun.dtv.lwuit.Image, int)

getAnimateContent

public Image[] getAnimateContent(int state)
                          throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Returns the animated content for this component, depending on the current state.

Specified by:
getAnimateContent in interface ViewOnlyComponent
Parameters:
state - the state of the component for which this content is to be retrieved, one of STATE_ENABLED or STATE_DISABLED
Returns:
The graphical content associated with the specified state, or null if there is none.
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.setAnimateContent(com.sun.dtv.lwuit.Image[], int)

setInteractionState

public void setInteractionState(int state)
                         throws IllegalArgumentException
Description copied from interface: ViewOnlyComponent
Set the current state of the component with respect to interaction.

Specified by:
setInteractionState in interface ViewOnlyComponent
Parameters:
state - the interaction state for this content, one of STATE_ENABLED or STATE_DISABLED
Throws:
IllegalArgumentException - if the state parameter does not represent a state
See Also:
ViewOnlyComponent.getInteractionState()

getInteractionState

public int getInteractionState()
Description copied from interface: ViewOnlyComponent
Return the current interaction state of the component.

Specified by:
getInteractionState in interface ViewOnlyComponent
Returns:
the current interaction state of the component.
See Also:
ViewOnlyComponent.setInteractionState(int)

setTextLayoutManager

public void setTextLayoutManager(TextLayoutManager manager)
Description copied from interface: ViewOnlyComponent
Sets the text layout manager that should be used for text layout in this component.

Specified by:
setTextLayoutManager in interface ViewOnlyComponent
Parameters:
manager - the TextLayoutManager
See Also:
ViewOnlyComponent.getTextLayoutManager()

getTextLayoutManager

public TextLayoutManager getTextLayoutManager()
Description copied from interface: ViewOnlyComponent
Gets the text layout manager that is currently in use for text layout in this component.

Specified by:
getTextLayoutManager in interface ViewOnlyComponent
Returns:
the TextLayoutManager
See Also:
ViewOnlyComponent.setTextLayoutManager(com.sun.dtv.ui.TextLayoutManager)

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)
Description copied from interface: ViewOnlyComponent
Set the horizontal alignment for any state-based content in this component.

Specified by:
setHorizontalAlignment in interface ViewOnlyComponent
Parameters:
alignment - the horizontal alignment mode, one of ViewOnlyComponent.HORIZONTAL_ALIGN_LEFT, ViewOnlyComponent.HORIZONTAL_ALIGN_CENTER, ViewOnlyComponent.HORIZONTAL_ALIGN_RIGHT or ViewOnlyComponent.HORIZONTAL_ALIGN_JUSTIFIED.
See Also:
ViewOnlyComponent.getHorizontalAlignment()

getHorizontalAlignment

public int getHorizontalAlignment()
Description copied from interface: ViewOnlyComponent
Retrieve the horizontal alignment for any state-based content in this component.

Specified by:
getHorizontalAlignment in interface ViewOnlyComponent
Returns:
the current horizontal alignment mode, one of ViewOnlyComponent.HORIZONTAL_ALIGN_LEFT, ViewOnlyComponent.HORIZONTAL_ALIGN_CENTER, ViewOnlyComponent.HORIZONTAL_ALIGN_RIGHT or ViewOnlyComponent.HORIZONTAL_ALIGN_JUSTIFIED.
See Also:
ViewOnlyComponent.setHorizontalAlignment(int)

setScalingMode

public void setScalingMode(int scaling)
Description copied from interface: ViewOnlyComponent
Set the scaling mode for this component.

Specified by:
setScalingMode in interface ViewOnlyComponent
Parameters:
scaling - the scaling mode, one of ViewOnlyComponent.SCALE_NO, ViewOnlyComponent.SCALE_NO_ASPECT_PROOF or ViewOnlyComponent.SCALE_ASPECT_PROOF.
See Also:
ViewOnlyComponent.getScalingMode()

getScalingMode

public int getScalingMode()
Description copied from interface: ViewOnlyComponent
Retrieve the scaling mode for this component.

Specified by:
getScalingMode in interface ViewOnlyComponent
Returns:
the current scaling mode, one of ViewOnlyComponent.SCALE_NO, ViewOnlyComponent.SCALE_NO_ASPECT_PROOF or ViewOnlyComponent.SCALE_ASPECT_PROOF.
See Also:
ViewOnlyComponent.setScalingMode(int)

isDoubleBuffered

public boolean isDoubleBuffered()
Description copied from interface: ViewOnlyComponent
Returns true if double buffering is available and activated.

Specified by:
isDoubleBuffered in interface ViewOnlyComponent
Returns:
true if double buffering is available and activated, and false otherwise

isOpaque

public boolean isOpaque()
Description copied from interface: ViewOnlyComponent
Returns true if the whole area of the Component (as returned by the com.sun.dtv.lwuit.Component#getBounds method, is opaque.

Specified by:
isOpaque in interface ViewOnlyComponent
Returns:
true if all the pixels within the area defined by the com.sun.dtv.lwuit.Component#getBounds method are opaque, i.e. all pixels are painted in an opaque color, false otherwise.

processEvent

public void processEvent(AWTEvent event)
Description copied from interface: ViewOnlyComponent
Handle the specified AWTEvent.

Specified by:
processEvent in interface ViewOnlyComponent
Parameters:
event - a java.awt.AWTEvent to handle.

setMatte

public void setMatte(Matte matte)
              throws MatteException
Description copied from interface: MatteEnabled
Adds an Matte to the component implementing this interface in order to enable matte compositing. If there is already a Matte assigned to the component, and this Matte is animated, it has to be stopped before any call to this method.

Specified by:
setMatte in interface MatteEnabled
Parameters:
matte - the Matte to be assigned to the component. At any point of time there can only be one matte associated to the component, that's way any matte that has been associated before will be overriden by a call to this method. The Matte parameter can also be null, in this case there is no matte associated with the component after the call, even if there had been one before.
Throws:
MatteException - if the Matte has an unsupported type, the platform does not support mattes at all, or an animated matte is associated with the component and is still running
See Also:
MatteEnabled.getMatte()

getMatte

public Matte getMatte()
Description copied from interface: MatteEnabled
Return the Matte currently associated with the component implementing this interface.

Specified by:
getMatte in interface MatteEnabled
Returns:
the Matte currently associated with the component or null if there is none
See Also:
MatteEnabled.setMatte(com.sun.dtv.ui.Matte)

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.