abbot.editor.widgets
Class Mnemonic

java.lang.Object
  extended by abbot.editor.widgets.Mnemonic

public class Mnemonic
extends Object

Provide access to mnemonics appropriate for the current platform and locale. Encapsulates displayed text, a KeyEvent.VK_ constant, and a displayed mnemonic index. All instances are obtained through the factory method, getMnemonic(String).

See Also:
KeyEvent, AbstractButton.setMnemonic(int), AbstractButton.setDisplayedMnemonicIndex(int), JLabel.setDisplayedMnemonic(int), JLabel.setDisplayedMnemonicIndex(int), Action.MNEMONIC_KEY

Field Summary
 int index
          The index to use as an argument to AbstractButton.setDisplayedMnemonicIndex(int).
 int keycode
          The keycode to use as an argument to AbstractButton.setMnemonic(int).
 String text
          The unencoded text.
 
Method Summary
static Mnemonic getMnemonic(String input)
          Create a Mnemonic instance with the mnemonic information from the given encoded String.
static void setDisplayedMnemonicIndex(Component c, int index)
          Set the displayed mnemonic index, if doing so is supported.
 void setMnemonic(AbstractButton button)
          Apply this mnemonic to the given AbstractButton.
 void setMnemonic(Action action)
          Apply this mnemonic to the given Action.
 void setMnemonic(JLabel label)
          Apply this mnemonic to the given JLabel.
 void setMnemonic(JTabbedPane tabbedPane, int tabIndex)
          Apply this mnemonic to the given JLabel.
 String toString()
           
static boolean useMnemonics()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

public String text
The unencoded text. For example "&File" results in "File".


keycode

public int keycode
The keycode to use as an argument to AbstractButton.setMnemonic(int). Returns KeyEvent.VK_UNDEFINED if no mnemonic was found.


index

public int index
The index to use as an argument to AbstractButton.setDisplayedMnemonicIndex(int). Returns -1 if the default value should be used.

Method Detail

setDisplayedMnemonicIndex

public static void setDisplayedMnemonicIndex(Component c,
                                             int index)
Set the displayed mnemonic index, if doing so is supported.


toString

public String toString()
Overrides:
toString in class Object

setMnemonic

public void setMnemonic(AbstractButton button)
Apply this mnemonic to the given AbstractButton.


setMnemonic

public void setMnemonic(JLabel label)
Apply this mnemonic to the given JLabel.


setMnemonic

public void setMnemonic(JTabbedPane tabbedPane,
                        int tabIndex)
Apply this mnemonic to the given JLabel.


setMnemonic

public void setMnemonic(Action action)
Apply this mnemonic to the given Action.


getMnemonic

public static Mnemonic getMnemonic(String input)
Create a Mnemonic instance with the mnemonic information from the given encoded String. Unencoded text, the mnemonic keycode, and the display index are encapsulated in the returned Mnemonic object. Encoding consists of placing an ampersand (&) prior to the character designated as the mnemonic.

Mnemonics may be encoded as follows:

Original TextVisible TextMnemonic
&FileFileVK_F
Save &As...Save As...VK_A second instance
Me&&&YouMe&YouVK_Y ambiguous ampersands must be escaped
Sugar & SpiceSugar & SpiceNone ampersand is unambiguous, whitespace is not allowed as a mnemonic

Swing restricts mnemonics to available KeyEvent VK_ constants, so there must exist a mapping between text characters and said constants. If the obvious mappings (A-Z, a-z, 0-9) don't hold, lookup falls back to other methods. Whitespace, quotes, and ampersand are disallowed as mnemonics.

Mappings from arbitrary characters to mnemonic keys may be defined by providing a property MNEMONIC_{unicode char}={KeyEvent.VK_ constant name} within a bundle accessible by abbot.i18n.Strings. If no such mapping is defined, a VK_ code is guessed by checking if there can be found a keystroke mapping for the original character.

See Also:
KeyStrokeMap, Strings

useMnemonics

public static boolean useMnemonics()


Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge