public abstract class KeyCombination extends Object
KeyCodeCombination or key
character - KeyCharacterCombination. A modifier key is shift,
control, alt, meta or shortcut and can be
defined as DOWN, UP or ANY.
The shortcut modifier is used to represent the modifier key which is
used commonly in keyboard shortcuts on the host platform. This is for
example control on Windows and meta (command key) on Mac.
By using shortcut key modifier developers can create platform
independent shortcuts. So the "Shortcut+C" key combination is handled
internally as "Ctrl+C" on Windows and "Meta+C" on Mac.
| Modifier and Type | Class and Description |
|---|---|
static class |
KeyCombination.Modifier
This class represents a pair of modifier key and its value.
|
static class |
KeyCombination.ModifierValue
ModifierValue specifies state of modifier keys. |
| Modifier and Type | Field and Description |
|---|---|
static KeyCombination.Modifier |
ALT_ANY
Modifier which specifies that the
alt key can be either up or
down. |
static KeyCombination.Modifier |
ALT_DOWN
Modifier which specifies that the
alt key must be down. |
static KeyCombination.Modifier |
CONTROL_ANY
Modifier which specifies that the
control key can be either up or
down. |
static KeyCombination.Modifier |
CONTROL_DOWN
Modifier which specifies that the
control key must be down. |
static KeyCombination.Modifier |
META_ANY
Modifier which specifies that the
meta key can be either up or
down. |
static KeyCombination.Modifier |
META_DOWN
Modifier which specifies that the
meta key must be down. |
static KeyCombination |
NO_MATCH
A KeyCombination that will match with no events.
|
static KeyCombination.Modifier |
SHIFT_ANY
Modifier which specifies that the
shift key can be either up or
down. |
static KeyCombination.Modifier |
SHIFT_DOWN
Modifier which specifies that the
shift key must be down. |
static KeyCombination.Modifier |
SHORTCUT_ANY
Modifier which specifies that the
shortcut key can be either up
or down. |
static KeyCombination.Modifier |
SHORTCUT_DOWN
Modifier which specifies that the
shortcut key must be down. |
| Modifier | Constructor and Description |
|---|---|
protected |
KeyCombination(KeyCombination.Modifier... modifiers)
Constructs a
KeyCombination with the specified list of modifiers. |
protected |
KeyCombination(KeyCombination.ModifierValue shift,
KeyCombination.ModifierValue control,
KeyCombination.ModifierValue alt,
KeyCombination.ModifierValue meta,
KeyCombination.ModifierValue shortcut)
Constructs a
KeyCombination with an explicit specification
of all modifier keys. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Tests whether this
KeyCombination equals to the specified object. |
KeyCombination.ModifierValue |
getAlt()
The state of the
alt key in this key combination. |
KeyCombination.ModifierValue |
getControl()
The state of the
control key in this key combination. |
String |
getDisplayText()
Returns a string representation of this
KeyCombination that is
suitable for display in a user interface (for example, beside a menu item). |
KeyCombination.ModifierValue |
getMeta()
The state of the
meta key in this key combination. |
String |
getName()
Returns a string representation of this
KeyCombination. |
KeyCombination.ModifierValue |
getShift()
The state of the
shift key in this key combination. |
KeyCombination.ModifierValue |
getShortcut()
The state of the
shortcut key in this key combination. |
int |
hashCode()
Returns a hash code value for this
KeyCombination. |
static KeyCombination |
keyCombination(String name)
Constructs a new
KeyCombination from the specified string. |
boolean |
match(KeyEvent event)
Tests whether this key combination matches the combination in the given
KeyEvent. |
String |
toString()
Returns a string representation of this object.
|
static KeyCombination |
valueOf(String value)
Constructs a new
KeyCombination from the specified string. |
public static final KeyCombination.Modifier SHIFT_DOWN
shift key must be down.public static final KeyCombination.Modifier SHIFT_ANY
shift key can be either up or
down.public static final KeyCombination.Modifier CONTROL_DOWN
control key must be down.public static final KeyCombination.Modifier CONTROL_ANY
control key can be either up or
down.public static final KeyCombination.Modifier ALT_DOWN
alt key must be down.public static final KeyCombination.Modifier ALT_ANY
alt key can be either up or
down.public static final KeyCombination.Modifier META_DOWN
meta key must be down.public static final KeyCombination.Modifier META_ANY
meta key can be either up or
down.public static final KeyCombination.Modifier SHORTCUT_DOWN
shortcut key must be down.public static final KeyCombination.Modifier SHORTCUT_ANY
shortcut key can be either up
or down.public static final KeyCombination NO_MATCH
protected KeyCombination(KeyCombination.ModifierValue shift, KeyCombination.ModifierValue control, KeyCombination.ModifierValue alt, KeyCombination.ModifierValue meta, KeyCombination.ModifierValue shortcut)
KeyCombination with an explicit specification
of all modifier keys. Each modifier key can be set to DOWN,
UP or ANY.shift - the value of the shift modifier keycontrol - the value of the control modifier keyalt - the value of the alt modifier keymeta - the value of the meta modifier keyshortcut - the value of the shortcut modifier keyprotected KeyCombination(KeyCombination.Modifier... modifiers)
KeyCombination with the specified list of modifiers.
All modifier keys which are not explicitly listed are set to the
default UP value.
All possible modifiers which change the default modifier value are
defined as constants in the KeyCombination class.
modifiers - the list of modifier keys and their corresponding valuespublic final KeyCombination.ModifierValue getShift()
shift key in this key combination.shift key in this key combinationpublic final KeyCombination.ModifierValue getControl()
control key in this key combination.control key in this key combinationpublic final KeyCombination.ModifierValue getAlt()
alt key in this key combination.alt key in this key combination.public final KeyCombination.ModifierValue getMeta()
meta key in this key combination.meta key in this key combinationpublic final KeyCombination.ModifierValue getShortcut()
shortcut key in this key combination.shortcut key in this key combinationpublic boolean match(KeyEvent event)
KeyEvent.
The implementation of this method in the KeyCombination class
does only a partial test with the modifier keys. This method is
overridden in subclasses to include the main key in the test.
event - the key eventtrue if the key combinations match, false
otherwisepublic String getName()
KeyCombination.
The string representation consists of sections separated by plus characters. Each section specifies either a modifier key or the main key.
A modifier key section contains the KeyCode name of a modifier
key. It can be prefixed with the Ignored keyword. A non-prefixed
modifier key implies its DOWN value while the prefixed version
implies the ANY (ignored) value. If some modifier key is not
specified in the string at all, it means it has the default UP
value.
The format of the main key section of the key combination string depends
on the KeyCombination subclass. It is either the key code name
for KeyCodeCombination or the single quoted key character for
KeyCharacterCombination.
Examples of KeyCombination string representations:
"Ctrl+Alt+Q" "Ignore Shift+Ctrl+A" "Alt+'w'"
KeyCombinationpublic String getDisplayText()
KeyCombination that is
suitable for display in a user interface (for example, beside a menu item).KeyCombination, suitable
for display in a user interface.public boolean equals(Object obj)
KeyCombination equals to the specified object.public int hashCode()
KeyCombination.public String toString()
getName() call.public static KeyCombination valueOf(String value)
KeyCombination from the specified string. The
string should be in the same format as produced by the getName
method.
If the main key section string is quoted in single quotes the method
creates a new KeyCharacterCombination for the unquoted substring.
Otherwise it finds the key code which name corresponds to the main key
section string and creates a KeyCodeCombination for it. If this
can't be done, it falls back to the KeyCharacterCombination.
value - the string which represents the requested key combinationKeyCombinationpublic static KeyCombination keyCombination(String name)
KeyCombination from the specified string. This
method simply delegates to valueOf(String).name - the string which represents the requested key combinationKeyCombinationvalueOf(String)Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.