com.symantec.itools.javax.swing
Class JWrappingLabel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.symantec.itools.javax.swing.JWrappingLabel

public class JWrappingLabel
extends javax.swing.JComponent
implements javax.swing.SwingConstants

This class implements a multiple-line text label. It displays text on one or more lines, wrapping text as needed to fit in the available horizontal space.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected  int align
          The current text alignment.
protected  java.lang.String text
          The text string being displayed.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
JWrappingLabel()
          Constructs a default wrapping label.
JWrappingLabel(java.lang.String s)
          Constructs a wrapping label that displays the specified string.
JWrappingLabel(java.lang.String s, int a)
          Constructs wrapping label with the specified text and alignment.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a listener for all event changes.
 void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Adds a vetoable listener for all event changes.
protected  void drawAlignedString(java.awt.Graphics g, java.awt.FontMetrics fm, int baseline, java.lang.String s, int x, int y, int width)
          This helper method draws a string aligned the requested way.
 java.lang.String getText()
          Gets the current label text.
 int getTextAlignment()
          Gets the current text alignment setting.
 void paintComponent(java.awt.Graphics g)
          Paints this component using the given graphics context.
 java.lang.String paramString()
          Returns an empty string.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a listener for all event changes.
 void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Removes a vetoable listener for all event changes.
 void setText(java.lang.String newText)
          Sets the label text.
 void setTextAlignment(int newAlignStyle)
          Sets the text alignment.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
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 text string being displayed.

align

protected int align
The current text alignment. One of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT.
See Also:
SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.RIGHT
Constructor Detail

JWrappingLabel

public JWrappingLabel()
Constructs a default wrapping label. Default values are an empty text string and left alignment.

JWrappingLabel

public JWrappingLabel(java.lang.String s)
Constructs a wrapping label that displays the specified string. The label will default to left alignment.
Parameters:
s - string to be displayed in label

JWrappingLabel

public JWrappingLabel(java.lang.String s,
                      int a)
Constructs wrapping label with the specified text and alignment.
Parameters:
s - the string to be displayed in label
a - the alignment, one of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
See Also:
com.symantec.itools.javax.swing.Alignment, com.symantec.itools.javax.swing.Alignment#ALIGN_LEFT, com.symantec.itools.javax.swing.Alignment#ALIGN_CENTERED, com.symantec.itools.javax.swing.Alignment#ALIGN_RIGHT
Method Detail

getTextAlignment

public int getTextAlignment()
Gets the current text alignment setting.
Returns:
the current alignment, one of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
See Also:
setTextAlignment(int), com.symantec.itools.javax.swing.Alignment, com.symantec.itools.javax.swing.Alignment#ALIGN_LEFT, com.symantec.itools.javax.swing.Alignment#ALIGN_CENTERED, com.symantec.itools.javax.swing.Alignment#ALIGN_RIGHT

setTextAlignment

public void setTextAlignment(int newAlignStyle)
                      throws java.beans.PropertyVetoException
Sets the text alignment.
Parameters:
newAlignStyle - the new alignment style, one of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
Throws:
java.beans.PropertyVetoException - if the specified property value is unacceptable
See Also:
getTextAlignment(), com.symantec.itools.javax.swing.Alignment, com.symantec.itools.javax.swing.Alignment#ALIGN_LEFT, com.symantec.itools.javax.swing.Alignment#ALIGN_CENTERED, com.symantec.itools.javax.swing.Alignment#ALIGN_RIGHT

getText

public java.lang.String getText()
Gets the current label text.
Returns:
the label's text string
See Also:
setText(java.lang.String)

setText

public void setText(java.lang.String newText)
             throws java.beans.PropertyVetoException
Sets the label text.
Parameters:
s - the new label text
Throws:
java.beans.PropertyVetoException - if the specified property value is unacceptable
See Also:
getText()

paramString

public java.lang.String paramString()
Returns an empty string. This is a standard Java AWT method which typically returns a string representing the state of this object.
Overrides:
paramString in class javax.swing.JComponent
Returns:
the empty string

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints this component using the given graphics context. This is a standard Java AWT method which typically gets called by the AWT to handle painting this component. It paints this component using the given graphics context. The graphics context clipping region is set to the bounding rectangle of this component and its [0,0] coordinate is this component's top-left corner.
Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics context used for painting
See Also:
Component.repaint(), Component.update(java.awt.Graphics)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener for all event changes.
Overrides:
addPropertyChangeListener in class javax.swing.JComponent
Parameters:
PropertyChangeListener - listener the listener to add.
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener for all event changes.
Overrides:
removePropertyChangeListener in class javax.swing.JComponent
Parameters:
PropertyChangeListener - listener the listener to remove.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

addVetoableChangeListener

public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a vetoable listener for all event changes.
Overrides:
addVetoableChangeListener in class javax.swing.JComponent
Parameters:
VetoableChangeListener - listener the listener to add.
See Also:
removeVetoableChangeListener(java.beans.VetoableChangeListener)

removeVetoableChangeListener

public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes a vetoable listener for all event changes.
Overrides:
removeVetoableChangeListener in class javax.swing.JComponent
Parameters:
VetoableChangeListener - listener the listener to remove.
See Also:
addVetoableChangeListener(java.beans.VetoableChangeListener)

drawAlignedString

protected void drawAlignedString(java.awt.Graphics g,
                                 java.awt.FontMetrics fm,
                                 int baseline,
                                 java.lang.String s,
                                 int x,
                                 int y,
                                 int width)
This helper method draws a string aligned the requested way.
Parameters:
g - the graphics context used for painting
s - the string to draw
x - the point to start drawing from, x coordinate
y - the point to start drawing from, y coordinate
width - the width of the area to draw in, in pixels