org.formaria.awt
Class Label

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by org.formaria.awt.Label
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, TextHolder
Direct Known Subclasses:
GraphicButton, Tab, Unknown

public class Label
extends java.awt.Canvas
implements TextHolder

Draws text. The text may be wrapped over multiple lines. Double buffering is switched off by default.

Copyright (c) Formaria Ltd., 2008
License: see license.txt

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int bufferHeight
          The buffer image height
protected  java.awt.Image bufferImage
          the internal buffer
protected  int bufferWidth
          The width of the buffer image
protected  boolean doubleBuffered
          true for a double buffered display
protected  TextRenderer renderer
          The renderer that will draw the content
protected  java.lang.String text
          The content of the label
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Label()
           
 
Method Summary
 void addNotify()
          Repaint the component once it has been created
 int getAlignment()
          Get the text horizontal alignment.
 int getHorizontalAlignment()
          Get the text horizontal alignment.
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this component.
 java.lang.String getText()
          Gets the text.
 int getVerticalAlignment()
          Get the text vertical alignment.
 void paint(java.awt.Graphics g)
          Render the text
 void setAlignment(int align)
          Set the horizontal alignment of the text.
 void setAlignment(java.lang.String value)
          Set one or more attributes of the component.
 void setDoubleBuffered(boolean buffer)
          Toggle use of double buffering when painting this component
 void setHorizontalAlignment(int align)
          Set the horizontal alignment of the text.
 void setText(java.lang.String str)
          Reset the text
 void setTransparent(boolean b)
          Sets the transparency of the text.
 void setVerticalAlignment(int align)
          Sets the vertical alignment of the text.
 void setVerticalAlignment(java.lang.String value)
          Set one or more attributes of the component.
 void update(java.awt.Graphics g)
          Update the component
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

protected java.lang.String text
The content of the label


renderer

protected TextRenderer renderer
The renderer that will draw the content


doubleBuffered

protected boolean doubleBuffered
true for a double buffered display


bufferImage

protected java.awt.Image bufferImage
the internal buffer


bufferWidth

protected int bufferWidth
The width of the buffer image


bufferHeight

protected int bufferHeight
The buffer image height

Constructor Detail

Label

public Label()
Method Detail

setText

public void setText(java.lang.String str)
Reset the text

Specified by:
setText in interface TextHolder
Parameters:
str - the new text

update

public void update(java.awt.Graphics g)
Update the component

Overrides:
update in class java.awt.Canvas
Parameters:
g - the graphics context

addNotify

public void addNotify()
Repaint the component once it has been created

Overrides:
addNotify in class java.awt.Canvas

paint

public void paint(java.awt.Graphics g)
Render the text

Overrides:
paint in class java.awt.Canvas
Parameters:
g - the graphics context

getText

public java.lang.String getText()
Gets the text.

Specified by:
getText in interface TextHolder
Returns:
the label text

getAlignment

public int getAlignment()
Get the text horizontal alignment. The function is same to getHorizontalAlignment()

Returns:
the horizontal alignment flag
  • TextRenderer.LEFT - left align the text
  • TextRenderer.RIGHT - right align the text
  • TextRenderer.CENTER - center the text

setAlignment

public void setAlignment(int align)
Set the horizontal alignment of the text. The function is same to setHorizontalAlignment(int)

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

getHorizontalAlignment

public int getHorizontalAlignment()
Get the text horizontal alignment.

Returns:
the horizontal alignment flag
  • TextRenderer.LEFT - left align the text
  • TextRenderer.RIGHT - right align the text
  • TextRenderer.CENTER - center the text

setHorizontalAlignment

public void setHorizontalAlignment(int align)
Set the horizontal alignment of the text.

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

getVerticalAlignment

public int getVerticalAlignment()
Get the text vertical alignment.

Returns:
the vertical alignment flag
  • TextRenderer.TOP - top align the text
  • TextRenderer.BOTTOM - bottom align the text
  • TextRenderer.CENTER - center the text

setVerticalAlignment

public void setVerticalAlignment(int align)
Sets the vertical alignment of the text.

Parameters:
align - 1 to bottom align the text, 0 for top alignment and 2 for centered text

setVerticalAlignment

public void setVerticalAlignment(java.lang.String value)
Set one or more attributes of the component. The function is same to setHorizontalAlignment(int). Attributes include
align (left|right|center ) or

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

setTransparent

public void setTransparent(boolean b)
Sets the transparency of the text.

Parameters:
b - true to make text transparent

setAlignment

public void setAlignment(java.lang.String value)
Set one or more attributes of the component. The function is same to setHorizontalAlignment(int). Attributes include
align (left|right|center ) or

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of this component.

Overrides:
getPreferredSize in class java.awt.Component
Returns:
a dimension object indicating this component's preferred size
See Also:
Component.getMinimumSize(), LayoutManager

setDoubleBuffered

public void setDoubleBuffered(boolean buffer)
Toggle use of double buffering when painting this component

Parameters:
buffer - true to double buffer