|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectides.api.utilities.GeneralUtils.JOptionPaneKeyBinder
public static class GeneralUtils.JOptionPaneKeyBinder
This class allows the use of simple keyboard shortcuts for the
Yes/No/etc. buttons in a JOptionPane.
Normally, a JOptionPane has mnemonic key bindings with its
buttons. For example, in order to select the Yes button via the keyboard,
one needs to press Alt+Y. However, this may be
counter-intuitive as many users would expect to use simply the key
Y.
This class provides a hack which lets the use of simple key shortcuts instead of the mnemonic shortcuts. It does the following:
JComponent with the given text message.
Alt+Y for the Yes
button, Alt+N for the No button and no shortcuts for the OK
and Cancel buttons.
Y and
N) and associates these shortcuts with the text component.
Action is created which
looks up the corresponding button in the JOptionPane and calls
AbstractButton.doClick() on it.
JOptionPane
cannot be accessed and customized directly. More information can be found
on this
page.
In order to use this hack, simply wrap your message. For example
JOptionPane.showConfirmDialog(window,message,title,JOptionPane.YES_NO_CANCEL_OPTION);
becomes
JOptionPane.showConfirmDialog(window,GeneralUtils.JOptionPaneKeyBinder.messageLabel(message),title,JOptionPane.YES_NO_CANCEL_OPTION);
| Nested Class Summary | |
|---|---|
protected static class |
GeneralUtils.JOptionPaneKeyBinder.ShortcutHandler
Handler for the activation of the simplified custom shortcuts. |
| Field Summary | |
|---|---|
protected static java.lang.String |
CANCEL
ID for Cancel button. |
protected static java.lang.String |
NO
ID for No button. |
protected static java.lang.String |
OK
ID for OK button. |
protected static java.lang.String |
YES
ID for Yes button. |
| Constructor Summary | |
|---|---|
GeneralUtils.JOptionPaneKeyBinder()
|
|
| Method Summary | |
|---|---|
protected static void |
clickButton(java.awt.Container container,
java.lang.String buttonText)
Calls the AbstractButton.doClick() method on the button with the
given text in the given container. |
protected static java.lang.String |
getMnemonicKey(java.lang.String button)
Retrieve the simple key from the menmonic shortcut for the given JOptionPane button. |
static javax.swing.JComponent |
messageLabel(java.lang.String message)
Wraps a message in a JComponent with simplified key bindings
for the JOptionPane buttons. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.lang.String YES
protected static final java.lang.String NO
protected static final java.lang.String OK
protected static final java.lang.String CANCEL
| Constructor Detail |
|---|
public GeneralUtils.JOptionPaneKeyBinder()
| Method Detail |
|---|
public static javax.swing.JComponent messageLabel(java.lang.String message)
JComponent with simplified key bindings
for the JOptionPane buttons. Use the component instead of the
string message when calling option pane methods.
For example
JOptionPane.showConfirmDialog(window,message,title,JOptionPane.YES_NO_CANCEL_OPTION);
becomes
JOptionPane.showConfirmDialog(window,GeneralUtils.JOptionPaneKeyBinder.messageLabel(message),title,JOptionPane.YES_NO_CANCEL_OPTION);
message - text message
JComponent with simplified key bindings for the
JOptionPane buttonsprotected static java.lang.String getMnemonicKey(java.lang.String button)
JOptionPane button. Only one of
YES, NO,
OK and
CANCEL is a valid input. If the simple
key cannot be retrieved (e.g., there is no mnemonic shortcut
associated with the button), returns null.
button - one of YES,
NO,
OK and
CANCEL
JOptionPane button, or null if there is
no such key
protected static void clickButton(java.awt.Container container,
java.lang.String buttonText)
AbstractButton.doClick() method on the button with the
given text in the given container. If the button cannot be found in
the container, does nothing.
container - container with the buttonbuttonText - text of the button
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||