net.xoetrope.awt
Class XLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by net.xoetrope.awt.XLabel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, XAttributedComponent, XTextHolder
Direct Known Subclasses:
XTab, XUnknown

public class XLabel
extends java.awt.Canvas
implements XTextHolder, XAttributedComponent

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

Copyright (c) Xoetrope Ltd., 1998-2003
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  XTextRenderer 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
XLabel()
           
 
Method Summary
 void addNotify()
          Repaint the component once it has been created
 int getAlignment()
          Get the text alignment
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this component.
 java.lang.String getText()
          Gets the text.
 void paint(java.awt.Graphics g)
          Render the text
 void setAlignment(int align)
          Sets the alignment of the text.
 int setAttribute(java.lang.String attribName, java.lang.Object attribValue)
          Set one or more attributes of the component.
 void setDoubleBuffered(boolean buffer)
          Toggle use of double buffering when painting this component
 void setText(java.lang.String str)
          Reset the text
 void setTransparent(boolean b)
          Sets the transparency of the text.
 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 XTextRenderer 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

XLabel

public XLabel()
Method Detail

setText

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

Specified by:
setText in interface XTextHolder
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 XTextHolder
Returns:
the label text

getAlignment

public int getAlignment()
Get the text alignment

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

setAlignment

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

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

setAttribute

public int setAttribute(java.lang.String attribName,
                        java.lang.Object attribValue)
Set one or more attributes of the component. Attributes include
  1. align (left|right|center ) or
  2. alignment (left|right|center )
  3. buffered (true|false) double buffering

Specified by:
setAttribute in interface XAttributedComponent
Parameters:
attribName - the attribute name
attribValue - the attribute value
Returns:
0 for success, non zero for failure or to require some further action

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