public class MnemonicUtil extends Object
Modifier and Type | Field and Description |
---|---|
static char |
CLOSING_PARENTHESIS
Constant for the closing parenthesis (=right parenthesis) ')'.
|
static char |
MNEMONIC_INDICATOR
Constant for the mnemonic indicator '&'.
|
static char |
OPENING_PARENTHESIS
Constant for the opening parenthesis (=left parenthesis) '('.
|
Constructor and Description |
---|
MnemonicUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
addMnemonicToLabel(String label,
char mnemonic)
Returns label text with mnemonic character enclosed in parenthesis.
|
static String |
extractLabelTextWithMnemonic(String labelAndMnemonic)
Extracts label text by removing non-displayable mnemonic indicator (conventionally ampersand (' ')) from label text and mnemonic resource.
|
static String |
extractLabelTextWithoutMnemonic(String labelAndMnemonic)
Extracts label text by removing mnemonic characters (e.g., "(F)" and "(&F)") from label text resource containing mnemonic.
|
static int |
getMnemonicCharacter(String labelAndMnemonic)
Gets the keyboard mnemonic from label and mnemonic text.
|
static int |
getMnemonicIndex(String labelAndMnemonic)
Gets the index of the mnemonic from label and mnemonic text.
|
static MnemonicKeyValidator |
getMnemonicKeyValidator() |
static boolean |
isValidMnemonicKey(int key)
Returns true if key is an valid mnemonic key based on mnemonic key validator associated with thid class.
|
static void |
setLabelAndTextFor(JLabel label,
Component labelFor,
LocaleMessage labelText) |
static void |
setMnemonicKeyValidator(MnemonicKeyValidator mnemonicKeyValidator) |
static void |
setTextAndMnemonic(AbstractButton button,
LocaleMessage buttonText)
Set label text and keyboard mnemonic of specified this component
|
public static final char MNEMONIC_INDICATOR
public static final char OPENING_PARENTHESIS
public static final char CLOSING_PARENTHESIS
public static int getMnemonicCharacter(String labelAndMnemonic) throws NullPointerException
For example,
From To &File → F ファイル(&F) → F
labelAndMnemonic
- label text containing mnemonicNullPointerException
- if labelAndMnemonic is nullpublic static int getMnemonicIndex(String labelAndMnemonic) throws NullPointerException
Gets the index of the mnemonic from label and mnemonic text.
For example,
From To &File → F ファイル(&F) → F
labelAndMnemonic
- label text containing mnemonicNullPointerException
- if labelAndMnemonic is nullpublic static String extractLabelTextWithMnemonic(String labelAndMnemonic) throws NullPointerException
For example,
From To &File → File ファイル(&F) → ファイル(F)
labelAndMnemonic
- label text containing mnemonicNullPointerException
- if labelAndMnemonic is nullpublic static String addMnemonicToLabel(String label, char mnemonic) throws NullPointerException
When you need menu label for CJK translation (or translated menu label does not contain mnemonic character), you have to add mnemonic label after menu label text. The mnemonic character should be enclosed in parenthesis and added end of menu label for CJK translation.
For example,
From To F + ファイル → ファイル(F)
label
- mnemonic
- NullPointerException
- if labelAndMnemonic is nullpublic static String extractLabelTextWithoutMnemonic(String labelAndMnemonic) throws NullPointerException
For example,
From To &File → File ファイル(&F) → ファイル ファイル(F) → ファイル
Conventionally, mnemonic indicator is ampersand ('&') and mnemonic character for CJK translation is enclosed by OPENING_PARENTHESIS ('(') and CLOSING_PARENTHESIS (')').
If label and mnemonic text contains two or more mnemonic indicator, second and after appearance of mnemonic indicators are ignored.
If parenthesis are not enclosing only mnemonic character, parenthesis are not removed.
If mnemonic indicator is not found in CJK translation resource, last occurrence of the parenthesis and enclosed mnemonic character will be
removed.
labelAndMnemonic
- NullPointerException
- if labelAndMnemonic is nullpublic static void setTextAndMnemonic(AbstractButton button, LocaleMessage buttonText)
button
- component to set label text and mnemonicbuttonText
- label text with mnemonic characterpublic static void setLabelAndTextFor(JLabel label, Component labelFor, LocaleMessage labelText)
public static boolean isValidMnemonicKey(int key)
key
- mnemonic keypublic static void setMnemonicKeyValidator(MnemonicKeyValidator mnemonicKeyValidator)
public static MnemonicKeyValidator getMnemonicKeyValidator()