com.sun.lwuit
Class Label

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

public class Label
extends Component

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


Field Summary
 
Fields inherited from class com.sun.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Constructor Summary
Label()
          Construct an empty label
Label(Image icon)
          Constructs a new label with the specified icon
Label(java.lang.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.
protected  Dimension calcPreferredSize()
          Calculates the preferred size based on component content.
 int getAlignment()
          Deprecated. use Style.getAlignment instead
 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 getIcon()
          Returns the labels icon
 int getShiftText()
          Simple getter to return how many pixels to shift the text inside the Label
 java.lang.String getText()
          Returns the label text
 int getTextPosition()
          Returns The position of the text relative to the icon
 int getVerticalAlignment()
          Returns the vertical alignment of the Label, this will only work when the icon is in the side of the text and not above or bellow it.
static boolean isDefaultTickerEnabled()
          Allows disabling/enabling tickers globally
 boolean isEndsWith3Points()
          Simple getter
 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.
protected  java.lang.String paramString()
          Returns a string representing the state of this component.
 void setAlignment(int align)
          Deprecated. use Style.setAlignment instead
static void setDefaultTickerEnabled(boolean aDefaultTickerEnabled)
          Allows disabling/enabling tickers globally
 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 setIcon(Image icon)
          Sets the Label icon, if the icon is unmodified a repaint would not be triggered
 void setShiftText(int shiftText)
          This method shifts the text from it's position in pixels.
 void setText(java.lang.String text)
          Sets the Label text
 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)
          Sets the vertical alignment of the Label to one of: CENTER, TOP, BOTTOM
 boolean shouldTickerStart()
          Returns true if a ticker should be started since there is no room to show the text in the label.
 void startTicker()
          This method will start the text ticker
 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.lwuit.Component
addFocusListener, calcScrollSize, contains, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBaseline, getBorder, getBottomGap, getBounds, getClientProperty, getComponentForm, getDirtyRegion, getDisabledStyle, getDragImage, getGridPosX, getGridPosY, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypes, getPropertyValue, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTensileLength, getUIID, getUnselectedStyle, getWidth, getVisibleBounds, getX, getY, growShrink, handlesInput, hasFocus, initComponent, initCustomStyle, installDefaultPainter, isAlwaysTensile, isDragActivated, isDragAndDropOperation, isDraggable, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isInitialized, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, keyPressed, keyReleased, keyRepeated, laidOut, longKeyPress, longPointerPress, paintBackground, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintLock, paintLockRelease, paintScrollbars, paintScrollbarX, paintScrollbarY, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setCellRenderer, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setInitialized, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setWidth, setVisible, setX, setY, styleChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Label

public Label(java.lang.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(java.lang.String text)
Sets the Label text

Parameters:
text - the string that the label presents.

getText

public java.lang.String getText()
Returns the label text

Returns:
the label text

setIcon

public void setIcon(Image icon)
Sets the Label icon, if the icon is unmodified a repaint would not be triggered

Parameters:
icon - the image that the label presents.

getIcon

public Image getIcon()
Returns the labels icon

Returns:
the labels icon

setAlignment

public void setAlignment(int align)
Deprecated. use Style.setAlignment instead

Sets the Alignment of the Label to one of: CENTER, LEFT, RIGHT

Parameters:
align - alignment value
See Also:
Component.CENTER, Component.LEFT, Component.RIGHT

setVerticalAlignment

public void setVerticalAlignment(int valign)
Sets the vertical alignment of the Label to one of: CENTER, TOP, BOTTOM

Parameters:
valign - alignment value
See Also:
Component.CENTER, Component.TOP, Component.BOTTOM

getVerticalAlignment

public int getVerticalAlignment()
Returns the vertical alignment of the Label, this will only work when the icon is in the side of the text and not above or bellow it.

Returns:
the vertical alignment of the Label one of: CENTER, TOP, BOTTOM
See Also:
Component.CENTER, Component.TOP, Component.BOTTOM

getAlignment

public int getAlignment()
Deprecated. use Style.getAlignment instead

Returns the alignment of the Label

Returns:
the alignment of the Label one of: CENTER, LEFT, RIGHT
See Also:
Component.CENTER, Component.LEFT, Component.RIGHT

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:
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:
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

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

paramString

protected java.lang.String paramString()
Description copied from class: Component
Returns a string representing the state of this component. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class Component
Returns:
a string representation of this component's state

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
Overrides:
paint in class Component
Parameters:
g - the component graphics

calcPreferredSize

protected Dimension calcPreferredSize()
Description copied from class: Component
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Overrides:
calcPreferredSize in class Component
Returns:
the calculated preferred size based on component content

getShiftText

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

Returns:
number of pixels to shift

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

shouldTickerStart

public boolean shouldTickerStart()
Returns true if a ticker should be started since there is no room to show the text in the label.

Returns:
true if a ticker should start running

startTicker

public void startTicker()
This method will start the text ticker


startTicker

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

Parameters:
delay - the delay in millisecods 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 -

isTickerEnabled

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

Returns:
tickerEnabled

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. Frames are defined by the Display class.

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

isDefaultTickerEnabled

public static boolean isDefaultTickerEnabled()
Allows disabling/enabling tickers globally

Returns:
the defaultTickerEnabled

setDefaultTickerEnabled

public static void setDefaultTickerEnabled(boolean aDefaultTickerEnabled)
Allows disabling/enabling tickers globally

Parameters:
aDefaultTickerEnabled - the defaultTickerEnabled to set