org.springframework.richclient.core
Class LabelInfo

java.lang.Object
  extended by org.springframework.richclient.core.LabelInfo

public final class LabelInfo
extends Object

An immutable parameter object consisting of the text, mnemonic character and mnemonic character index that may be associated with a labeled component. This class also acts as a factory for creating instances of itself based on a string descriptor that adheres to some simple syntax rules as described in the javadoc for the valueOf(String) method.

The syntax used for the label info descriptor is just the text to be displayed by the label with an ampersand (&) optionally inserted before the character that is to be used as a mnemonic for the label.

Example: To create a label with the text My Label and the capital L as a mnemonic, use the following descriptor:

     My &Label
 

A backslash character (\) can be used to escape ampersand characters that are to be displayed as part of the label's text. For example:

     Save \& Run
 

Only one non-escaped backslash can appear in the label descriptor. Attempting to specify more than one mnemonic character will result in an exception being thrown. TODO finish comment regarding backslash chars in props file Note that for label descriptors provided in properties files, an extra backslash will be required to avoid the single backslash being interpreted as a special character.

Author:
Keith Donald, Peter De Bruycker, Kevin Stembridge

Constructor Summary
LabelInfo(String text)
          Creates a new LabelInfo with the given text and no specified mnemonic.
LabelInfo(String text, int mnemonic)
          Creates a new LabelInfo with the given text and mnemonic character.
LabelInfo(String text, int mnemonic, int mnemonicIndex)
          Creates a new LabelInfo with the given text, mnemonic character and mnemonic index.
 
Method Summary
 void configureButton(AbstractButton button)
          Configures the given button with the properties held in this instance.
 void configureLabel(JLabel label)
          Configures the given label with the parameters from this instance.
 void configureLabelFor(JLabel label, JComponent component)
          Configures the given label with the property values described by this instance and then sets it as the label for the given component.
 boolean equals(Object obj)
          
 int getMnemonic()
          Returns the character that is to be treated as the mnemonic character for the label.
 int getMnemonicIndex()
          Returns the index within the label text of the mnemonic character.
 String getText()
          Returns the text to be displayed by the label.
 int hashCode()
          
 String toString()
          
static LabelInfo valueOf(String labelDescriptor)
          Creates a new LabelInfo instance by parsing the given label descriptor to determine the label's text and mnemonic character.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LabelInfo

public LabelInfo(String text)
Creates a new LabelInfo with the given text and no specified mnemonic.

Parameters:
text - The text to be displayed by the label. This may be an empty string but cannot be null.
Throws:
IllegalArgumentException - if text is null.

LabelInfo

public LabelInfo(String text,
                 int mnemonic)
Creates a new LabelInfo with the given text and mnemonic character.

Parameters:
text - The text to be displayed by the label. This may be an empty string but cannot be null.
mnemonic - The character from the label text that acts as a mnemonic.
Throws:
IllegalArgumentException - if text is null or if mnemonic is a negative value.

LabelInfo

public LabelInfo(String text,
                 int mnemonic,
                 int mnemonicIndex)
Creates a new LabelInfo with the given text, mnemonic character and mnemonic index.

Parameters:
text - The text to be displayed by the label. This may be an empty string but cannot be null.
mnemonic - The character from the label text that acts as a mnemonic.
mnemonicIndex - The zero-based index of the mnemonic character within the label text. If the specified label text is an empty string, this property will be ignored and set to -1.
Throws:
IllegalArgumentException - if text is null, if mnemonic is a negative value, if mnemonicIndex is less than -1 or if mnemonicIndex is outside the length of text.
Method Detail

valueOf

public static LabelInfo valueOf(String labelDescriptor)
Creates a new LabelInfo instance by parsing the given label descriptor to determine the label's text and mnemonic character. The syntax rules for the descriptor are as follows:

Parameters:
labelDescriptor - The label descriptor. The text may be null or empty, in which case a blank LabelInfo instance will be returned.
Returns:
A LabelInfo instance that is described by the given descriptor. Never returns null.
Throws:
IllegalArgumentException - if labelDescriptor violates any of the syntax rules described above.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

configureLabel

public void configureLabel(JLabel label)
Configures the given label with the parameters from this instance.

Parameters:
label - The label that is to be configured.
Throws:
IllegalArgumentException - if label is null.

configureLabelFor

public void configureLabelFor(JLabel label,
                              JComponent component)
Configures the given label with the property values described by this instance and then sets it as the label for the given component.

Parameters:
label - The label to be configured.
component - The component that the label is 'for'.
Throws:
IllegalArgumentException - if either argument is null.
See Also:
JLabel.setLabelFor(java.awt.Component)

configureButton

public void configureButton(AbstractButton button)
Configures the given button with the properties held in this instance. Note that this instance doesn't hold any keystroke accelerator information.

Parameters:
button - The button to be configured.
Throws:
IllegalArgumentException - if button is null.

getText

public String getText()
Returns the text to be displayed by the label.

Returns:
The label text, possibly an empty string but never null.

getMnemonic

public int getMnemonic()
Returns the character that is to be treated as the mnemonic character for the label.

Returns:
The mnemonic character.

getMnemonicIndex

public int getMnemonicIndex()
Returns the index within the label text of the mnemonic character.

Returns:
The index of the mnemonic character, or -1 if no mnemonic index is specified.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.