public class Shortcut
extends java.lang.Object
Every platform has a "standard" modifier key which is normally used for activating menu items. That modifier is represented by the DEFAULT_MASK constant. In most cases, you can simply use a constructor which does not specify modifier keys, in which case the platform-specific default modifier will be used. If you want to add other modifier keys, you should generally combine them with the default mask. For example:
new Shortcut('X', Shortcut.SHIFT_MASK | Shortcut.DEFAULT_MASK)
will correspond to control-shift-X on Windows, and meta-shift-X on Macintosh.
Modifier and Type | Field and Description |
---|---|
static int |
ALT_MASK |
static int |
CTRL_MASK |
static int |
DEFAULT_MASK |
static int |
META_MASK |
static int |
SHIFT_MASK |
Constructor and Description |
---|
Shortcut(char c)
Create a Shortcut representing a particular character, combined with the platform-specific default
modifier key.
|
Shortcut(char c,
int modifiers)
Create a Shortcut representing a particular character, combined with a set of modifier keys.
|
Shortcut(int key)
Create a Shortcut representing a particular key, combined with the platform-specific default
modifier key.
|
Shortcut(int key,
int modifiers)
Create a Shortcut representing a particular key, combined with a set of modifier keys.
|
Modifier and Type | Method and Description |
---|---|
char |
getKeyChar()
Get the character which must be typed to activate this shortcut.
|
int |
getKeyCode()
Get the key code (defined by the KeyEvent class) which must be typed to activate this shortcut.
|
javax.swing.KeyStroke |
getKeyStroke()
Get a KeyStroke corresponding to this Shortcut.
|
int |
getModifiers()
Get the set of modifier keys (a sum of the mask constants defined by this class) which must be
held down to activate this shortcut.
|
public static final int SHIFT_MASK
public static final int CTRL_MASK
public static final int META_MASK
public static final int ALT_MASK
public static final int DEFAULT_MASK
public Shortcut(char c)
c
- the character which must be typed to activate the shortcutpublic Shortcut(int key)
key
- the key code (defined by the KeyEvent class) which must be typed to activate the shortcutpublic Shortcut(char c, int modifiers)
c
- the character which must be typed to activate the shortcutmodifiers
- the set of modifier keys required to activate the shortcut. This should be an ORed
combination of the mask constants defined in this classpublic Shortcut(int key, int modifiers)
key
- the key code (defined by the KeyEvent class) which must be typed to activate the shortcutmodifiers
- the set of modifier keys required to activate the shortcut. This should be an ORed
combination of the mask constants defined in this classpublic javax.swing.KeyStroke getKeyStroke()
public char getKeyChar()
public int getKeyCode()
public int getModifiers()
Written by Peter Eastman.