com.sas.swing.visuals
Class LabelView

com.sas.swing.visuals.LabelView
All Implemented Interfaces:
Constants, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants
Direct Known Subclasses:
DefaultTableCellRenderer, SortSelectorRenderer

public class LabelView
implements javax.swing.SwingConstants, Constants

LabelView is a class that can display lines of text, an image, or both. The text can be single or multiline. The text can also be horizontally or vertically oriented and aligned.
Notes:


You can specify where in the label's display area the label's contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.

You can also specify the position of the text relative to the image. By default, text is on the trailing edge of the image, with the text and image vertically aligned.

A label's leading and trailing edge are determined from the value of its ComponentOrientation property. At present, the default ComponentOrientation setting maps the leading edge to left and the trailing edge to right.

You can also specify if the text is painted horizontally or vertically. By default, text is painted horizontally. Each line of text can be set to indivdually align with the horizontal alignment property, or the text can be aligned as one block of text. The default value is to align each line of text indivudally.

Also, you can specify whether the text should wrap across lines, and whether it should wrap on word boundaries or not. By default, the text wraps lines on word boundaries.

If the text is painted horizontally and the text paints beyond the widht of the label, the clipped proeprty can be set to paint the text with "..." to show text is not visible. The default value is true. Also, a pixel gap can be specfied to set the distance between lines, the default value is 0. This property is more likely to be used for vertical oriented text, but works for horizontal text as well.

Finally, you can use the setIconTextGap method to specify how many pixels should appear between the text and the image. The default is 4 pixels.

See Also:
Serialized Form

Field Summary
protected  int alignmentMode
           
static int BLOCK
          An alignment mode that aligns the entire block of text in the label view according to the horizontal alignment property of the label view
protected  boolean clipped
           
static int INDIVIDUAL
          An alignment mode that aligns each line of text in the label view indivually according to the horizontal alignment property of the label view
protected  int leadingContentOffset
           
protected  int lineGap
           
protected  boolean lineWrap
           
protected  int orientation
           
protected  java.awt.Dimension preferredSpanSize
           
protected  boolean replaceNewline
           
protected  boolean replaceTab
           
static int SPAN_FILL
           
protected  int tabSize
           
protected  int topContentOffset
           
protected  boolean wordWrap
           
 
Fields inherited from interface com.sas.swing.Constants
CENTER_BOTTOM, CENTER_LEADING, CENTER_LEFT, CENTER_RIGHT, CENTER_TOP, CENTER_TRAILING
 
Constructor Summary
LabelView()
          Creates a LabelView instance with no image and with an empty string for the title.
LabelView(javax.swing.Icon image)
          Creates a LabelView instance with the specified image.
LabelView(javax.swing.Icon image, int horizontalAlignment)
          Creates a LabelView instance with the specified image and horizontal alignment.
LabelView(java.lang.String text)
          Creates a LabelView instance with the specified text.
LabelView(java.lang.String text, javax.swing.Icon icon, int horizontalAlignment)
          Creates a LabelView instance with the specified text, image, and horizontal alignment.
LabelView(java.lang.String text, int horizontalAlignment)
          Creates a LabelView instance with the specified text and horizontal alignment.
 
Method Summary
protected  int checkHorizontalKey(int key, java.lang.String message)
          Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
protected  int checkVerticalKey(int key, java.lang.String message)
          Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
 int getAlignmentMode()
          The alignment policy for the text in the label view.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns property information about the LabelView.
 int getGapBetweenLines()
          The pixel gap between the lines of text.
 int getHorizontalAlignment()
          Returns the alignment of the label's contents along the X axis.
 int getHorizontalTextPosition()
          Returns the horizontal position of the label's text, relative to its image.
 int getLeadingContentOffset()
          The number of pixels away from the horizontal alignment property the content is rendererd.
 boolean getLineWrap()
          Gets the line-wrapping policy of the label view.
 int getOrientation()
          Returns the orientation of the label, either HORIZONTAL or VERTICAL.
 java.awt.Dimension getPreferredSpanSize()
          Returns a dimension which helps determine the preferred size of the label view.
 int getTabSize()
          Gets the number of characters used to expand tabs.
 int getTopContentOffset()
          The number of pixels away from the vertical alignment property the content is rendererd.
 java.lang.String getUIClassID()
          Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.
 int getVerticalAlignment()
          Returns the alignment of the label's contents along the Y axis.
 int getVerticalTextPosition()
          Returns the vertical position of the label's text, relative to its image.
 boolean getWrapStyleWord()
          Get the style of wrapping used if the label view is wrapping lines.
protected  void initializeLocalVars()
          Initializes label properties to their default values.
 boolean isClipped()
          Returns whether the text is painted with "..." when not all visible.
 void setAlignmentMode(int newValue)
          Sets the alignment policy for the text in the label view.
 void setClipped(boolean newValue)
          Sets whether the text is painted with "..." when not all visible.
 void setGapBetweenLines(int newValue)
          Sets the pixel gap between the lines of text.
 void setHorizontalAlignment(int alignment)
          Sets the alignment of the label's contents along the X axis.
 void setHorizontalTextPosition(int textPosition)
          Sets the horizontal position of the label's text, relative to its image.
 void setLeadingContentOffset(int newValue)
          Sets the number of pixels away from the horizontal alignment property the content is rendererd.
 void setLineWrap(boolean wrap)
          Sets the line-wrapping policy of the label view.
 void setOrientation(int newValue)
          Sets the orientation the text in the label is painted.
 void setPreferredSpanSize(java.awt.Dimension newSize)
          Helps determine what the preferred size of the label view should be.
 void setTabSize(int newValue)
          Sets the number of characters to expand tabs to.
 void setTopContentOffset(int newValue)
          Sets the number of pixels away from the vertical alignment property the content is rendererd.
 void setVerticalAlignment(int alignment)
          Sets the alignment of the label's contents along the Y axis.
 void setVerticalTextPosition(int textPosition)
          Sets the vertical position of the label's text, relative to its image.
 void setWrapStyleWord(boolean word)
          Set the style of wrapping used if the label view is wrapping lines.
 void updateUI()
          Notification from the UIManager that the look and feel (L&F) has changed.
 

Field Detail

alignmentMode

protected int alignmentMode

clipped

protected boolean clipped

orientation

protected int orientation

lineWrap

protected boolean lineWrap

wordWrap

protected boolean wordWrap

lineGap

protected int lineGap

preferredSpanSize

protected java.awt.Dimension preferredSpanSize

tabSize

protected int tabSize

leadingContentOffset

protected int leadingContentOffset

topContentOffset

protected int topContentOffset

replaceTab

protected boolean replaceTab

replaceNewline

protected boolean replaceNewline

INDIVIDUAL

public static final int INDIVIDUAL
An alignment mode that aligns each line of text in the label view indivually according to the horizontal alignment property of the label view

See Also:
Constant Field Values

BLOCK

public static final int BLOCK
An alignment mode that aligns the entire block of text in the label view according to the horizontal alignment property of the label view

See Also:
Constant Field Values

SPAN_FILL

public static final int SPAN_FILL
See Also:
Constant Field Values
Constructor Detail

LabelView

public LabelView(java.lang.String text,
                 javax.swing.Icon icon,
                 int horizontalAlignment)
Creates a LabelView instance with the specified text, image, and horizontal alignment. The label view is horizontally oriented and centered vertically in its display area. Line-wrapping is turned on, wrapping on word boundaries is possible. The text is on the trailing edge of the image.

Parameters:
text - The text to be displayed by the label view.
icon - The image to be displayed by the label view.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.

LabelView

public LabelView(java.lang.String text,
                 int horizontalAlignment)
Creates a LabelView instance with the specified text and horizontal alignment. The label view is horizontally oriented and centered vertically in its display area. Line-wrapping is turned on, wrapping on word boundaries is possible.

Parameters:
text - The text to be displayed by the label view.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.

LabelView

public LabelView(java.lang.String text)
Creates a LabelView instance with the specified text. The label view is horizontally oriented and centered vertically in its display area. Line-wrapping is turned on, wrapping on word boundaries is possible. The label is aligned against the leading edge of its display area.

Parameters:
text - The text to be displayed by the label view.

LabelView

public LabelView(javax.swing.Icon image,
                 int horizontalAlignment)
Creates a LabelView instance with the specified image and horizontal alignment. The label view is horizontally oriented and centered vertically in its display area. Line-wrapping is turned on, wrapping on word boundaries is possible.

Parameters:
image - Icon
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.

LabelView

public LabelView(javax.swing.Icon image)
Creates a LabelView instance with the specified image. The label view is centered vertically and horizontally in its display area. The label view is horizontally oriented and line-wrapping is turned on, wrapping on word boundaries is possible.

Parameters:
image - Icon

LabelView

public LabelView()
Creates a LabelView instance with no image and with an empty string for the title. The label view is horizontally oriented and centered vertically in its display area. The label's contents, once set, will be displayed on the leading edge of the label's display area and the lines will be wrapped on word boundaries when neccessary.

Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns property information about the LabelView.

Returns:
an ExtendedBeanInfo object containing property information about the LabelView.

updateUI

public void updateUI()
Notification from the UIManager that the look and feel (L&F) has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class javax.swing.JLabel
See Also:
JComponent.updateUI()

getUIClassID

public java.lang.String getUIClassID()
Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.

Overrides:
getUIClassID in class javax.swing.JLabel
Returns:
the string "LabelViewUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

initializeLocalVars

protected void initializeLocalVars()
Initializes label properties to their default values.


getAlignmentMode

public int getAlignmentMode()
The alignment policy for the text in the label view. A mode of INDIVIDUAL aligns each line of text in the label view indivually according to the horizontal alignment property of the label view. A mode of BLOCK aligns the entire block of text in the label view according to the horizontal alignment property of the label view. The default value is INDIVIDUAL.

Returns:
the alignment policy for the text in the label view
See Also:
JLabel.getHorizontalAlignment(), setAlignmentMode(int)

setAlignmentMode

public void setAlignmentMode(int newValue)
Sets the alignment policy for the text in the label view. A mode of INDIVIDUAL aligns each line of text in the label view indivually according to the horizontal alignment property of the label view. A mode of BLOCK aligns the entire block of text in the label view according to the horizontal alignment property of the label view. The default value is INDIVIDUAL.

Parameters:
newValue - the alignment policy for the text in the label view
See Also:
JLabel.getHorizontalAlignment(), getAlignmentMode()

isClipped

public boolean isClipped()
Returns whether the text is painted with "..." when not all visible. This option is ignored if the orientation is vertical. The default value is true.

Returns:
whether the text is painted as clipped when not fully visble
See Also:
setClipped(boolean)

setClipped

public void setClipped(boolean newValue)
Sets whether the text is painted with "..." when not all visible. This option is ignored if the orientation is vertical. The default value is true.

Parameters:
newValue - whether to paint text as clipped when it extends beyond the label's width
See Also:
isClipped()

getOrientation

public int getOrientation()
Returns the orientation of the label, either HORIZONTAL or VERTICAL. The default value is HORIZONTAL.

Returns:
the direction the text is painted within the label view
See Also:
setOrientation(int)

setOrientation

public void setOrientation(int newValue)
Sets the orientation the text in the label is painted. Valid values are either HORIZONTAL or VERTICAL. The default value is HORIZONTAL.

Parameters:
newValue - indicates the orientation the text should be painted, valid values one of the following constants defined in SwingConstants: HORIZONTAL, VERTICAL
See Also:
getOrientation()

getGapBetweenLines

public int getGapBetweenLines()
The pixel gap between the lines of text. The default value is 0.

Returns:
the pixel gap space between lines of horizontal or vertical text
See Also:
setGapBetweenLines(int)

setGapBetweenLines

public void setGapBetweenLines(int newValue)
Sets the pixel gap between the lines of text. The default value is 0.

Parameters:
newValue - the pixel gap space between lines of horizontal or vertical text
See Also:
getGapBetweenLines()

getLeadingContentOffset

public int getLeadingContentOffset()
The number of pixels away from the horizontal alignment property the content is rendererd. The default is 0, but if a user wants the ability to always horizontally offset the content 5 pixels from the center, they can use this property to do so.

Returns:
the number of pixels the content is offset from its horizontal alignment proeprty
See Also:
setLeadingContentOffset(int)

setLeadingContentOffset

public void setLeadingContentOffset(int newValue)
Sets the number of pixels away from the horizontal alignment property the content is rendererd. The default is 0, but if a user wants the ability to always horizontally offset the content 5 pixels from the center, they can use this property to do so.

Parameters:
newValue - the number of pixels to offset the content horizontally
See Also:
getLeadingContentOffset()

getTopContentOffset

public int getTopContentOffset()
The number of pixels away from the vertical alignment property the content is rendererd. The default is 0, but if a user wants the ability to always vertically offset the content 5 pixels from the center, they can use this property to do so.

Returns:
the number of pixels the content is offset from its vertical alignment proeprty
See Also:
setTopContentOffset(int)

setTopContentOffset

public void setTopContentOffset(int newValue)
Sets the number of pixels away from the vertical alignment property the content is rendererd. The default is 0, but if a user wants the ability to always vertically offset the content 5 pixels from the center, they can use this property to do so.

Parameters:
newValue - the number of pixels to offset the content vertically
See Also:
getTopContentOffset()

setLineWrap

public void setLineWrap(boolean wrap)
Sets the line-wrapping policy of the label view. If set to true the lines will be wrapped if they are too long to fit within the allocated width/height. If set to false, the lines will always be unwrapped. The default value is true.

Parameters:
wrap - indicates if lines should be wrapped.
See Also:
getLineWrap()

getLineWrap

public boolean getLineWrap()
Gets the line-wrapping policy of the label view. If set to true the lines will be wrapped if they are too long to fit within the allocated width/height. If set to false, the lines will always be unwrapped.

Returns:
boolean

setWrapStyleWord

public void setWrapStyleWord(boolean word)
Set the style of wrapping used if the label view is wrapping lines. If set to true the lines will be wrapped at word boundaries (whitespace) if they are too long to fit within the allocated width/height. If set to false, the lines will be wrapped at character boundaries. By default this property is true.

Parameters:
word - indicates if word boundaries should be used for line wrapping.
See Also:
getWrapStyleWord()

getWrapStyleWord

public boolean getWrapStyleWord()
Get the style of wrapping used if the label view is wrapping lines. If set to true the lines will be wrapped at word boundaries (whitespace) if they are too long to fit within the allocated width/height. If set to false, the lines will be wrapped at character boundaries.

Returns:
boolean
See Also:
setWrapStyleWord(boolean)

setPreferredSpanSize

public void setPreferredSpanSize(java.awt.Dimension newSize)
Helps determine what the preferred size of the label view should be. For the dimension passed in, if the height or width is set to a value other than -1, the preferred size for that value will be set.
For example, if a dimension with a width of 30 and height of 30 is passed in, the preferred size of the label view will be 30 by 30. If a dimension with a width of 30 and height of -1 is passed in, the preferred size of the label view will be 30 by whatever the label view determines it needs for a hight to fit the content passed on the paramters set. If a dimension with a width of -1 and height of 30 is passed in, the preferred size of the label view will be whatever the label view determines it needs for a width to fit the content passed on the paramters set by 30. If a dimension of -1 by -1 is passed in, the label view will get a preferred size of whatever it needs to fit its content. This is the default value. If the label view is going to have wrapped lines and is going to be a determining factor in the size of the container it is in, a -1 by -1 dimension may cause problems with the size of the container.

Parameters:
newSize - the new dimension to use to help determine the preferred size of the label view
See Also:
getPreferredSpanSize()

getPreferredSpanSize

public java.awt.Dimension getPreferredSpanSize()
Returns a dimension which helps determine the preferred size of the label view. A value of -1 for either the width or height means that the label view will determine this value for the preferred size based on the content.

Returns:
the diemnsion used to help determine the preferred size of the label view
See Also:
setPreferredSpanSize(Dimension)

getTabSize

public int getTabSize()
Gets the number of characters used to expand tabs. The default value is 8.

Returns:
the characters to expand a tab character
See Also:
setTabSize(int)

setTabSize

public void setTabSize(int newValue)
Sets the number of characters to expand tabs to. This will be multiplied by the maximum advance for variable width fonts.

Parameters:
newValue - number of characters to expand to
See Also:
getTabSize()

checkVerticalKey

protected int checkVerticalKey(int key,
                               java.lang.String message)
Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.

Overrides:
checkVerticalKey in class javax.swing.JLabel
Parameters:
key - the property value to check
message - the IllegalArgumentException detail message
Returns:
int
Throws:
java.lang.IllegalArgumentException - if key isn't TOP, CENTER, BOTTOM, CENTER_TOP, or CENTER_BOTTOM.
See Also:
setVerticalAlignment(int), setVerticalTextPosition(int)

checkHorizontalKey

protected int checkHorizontalKey(int key,
                                 java.lang.String message)
Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.

Overrides:
checkHorizontalKey in class javax.swing.JLabel
Parameters:
key - the property value to check
message - the IllegalArgumentException detail message
Returns:
int
Throws:
java.lang.IllegalArgumentException - if key isn't TOP, CENTER, BOTTOM, LEADING, TRAILING, CENTER_LEFT, CENTER_RIGHT, CENTER_LEADING, or CENTER_TRAILING.
See Also:
setVerticalAlignment(int), setVerticalTextPosition(int)

getVerticalAlignment

public int getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.

Overrides:
getVerticalAlignment in class javax.swing.JLabel
Returns:
The value of the verticalAlignment property, one of the following constants defined in SwingConstants or Constants: TOP, CENTER, BOTTOM, CENTER_TOP, or CENTER_BOTTOM.
See Also:
SwingConstants, Constants, setVerticalAlignment(int)

setVerticalAlignment

public void setVerticalAlignment(int alignment)
Sets the alignment of the label's contents along the Y axis. The default value of this property is CENTER.

Overrides:
setVerticalAlignment in class javax.swing.JLabel
Parameters:
alignment - One of the following constants defined in SwingConstants or Constants: TOP, CENTER (the default), BOTTOM, CENTER_TOP, or CENTER_BOTTOM.
See Also:
SwingConstants, Constants, getVerticalAlignment()

getHorizontalAlignment

public int getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.

Overrides:
getHorizontalAlignment in class javax.swing.JLabel
Returns:
The value of the horizontalAlignment property, one of the following constants defined in SwingConstants or Constants: LEFT, CENTER, RIGHT, LEADING, TRAILING, CENTER_LEFT, CENTER_RIGHT, CENTER_LEADING, or CENTER_TRAILING.
See Also:
setHorizontalAlignment(int), SwingConstants, Constants

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)
Sets the alignment of the label's contents along the X axis.

Overrides:
setHorizontalAlignment in class javax.swing.JLabel
Parameters:
alignment - One of the following constants defined in SwingConstants or Constants: LEFT, CENTER (the default for image-only labels), RIGHT, LEADING (the default for text-only labels), TRAILING, CENTER_LEFT, CENTER_RIGHT, CENTER_LEADING, or CENTER_TRAILING.
See Also:
SwingConstants, Constants, getHorizontalAlignment()

getVerticalTextPosition

public int getVerticalTextPosition()
Returns the vertical position of the label's text, relative to its image.

Overrides:
getVerticalTextPosition in class javax.swing.JLabel
Returns:
One of the following constants defined in SwingConstants or Constants: TOP, CENTER, BOTTOM, CENTER_TOP, or CENTER_BOTTOM.
See Also:
setVerticalTextPosition(int), SwingConstants, Constants

setVerticalTextPosition

public void setVerticalTextPosition(int textPosition)
Sets the vertical position of the label's text, relative to its image. The default value of this property is CENTER.

Overrides:
setVerticalTextPosition in class javax.swing.JLabel
Parameters:
textPosition - One of the following constants defined in SwingConstants or Constants: TOP, CENTER (the default), BOTTOM, CENTER_TOP, or CENTER_BOTTOM.
See Also:
SwingConstants, Constants, getVerticalTextPosition()

getHorizontalTextPosition

public int getHorizontalTextPosition()
Returns the horizontal position of the label's text, relative to its image.

Overrides:
getHorizontalTextPosition in class javax.swing.JLabel
Returns:
One of the following constants defined in SwingConstants or Constants: LEFT, CENTER, RIGHT, LEADING, TRAILING, CENTER_LEFT, CENTER_RIGHT, CENTER_LEADING, or CENTER_TRAILING.
See Also:
SwingConstants, Constants

setHorizontalTextPosition

public void setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the label's text, relative to its image.

Overrides:
setHorizontalTextPosition in class javax.swing.JLabel
Parameters:
textPosition - One of the following constants defined in SwingConstants or Constants: LEFT, CENTER, RIGHT, LEADING, TRAILING (the default), CENTER_LEFT, CENTER_RIGHT, CENTER_LEADING, or CENTER_TRAILING.
Throws:
java.lang.IllegalArgumentException
See Also:
SwingConstants, Constants



Copyright © 2009 SAS Institute Inc. All Rights Reserved.