Top Description Inners Fields Constructors Methods
javafx.scene.input

public abstract Class KeyCombination

extends Object
Class Inheritance
Known Direct Subclasses
javafx.scene.input.KeyCharacterCombination, javafx.scene.input.KeyCodeCombination
Imports
com.sun.javafx.tk.Toolkit, java.util.ArrayList, .List, .Locale

Represents a combination of keys which are used in keyboard shortcuts. A key combination consists of a main key and a set of modifier keys. The main key can be specified by its key code - 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.

Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
KeyCombination.Modifier

This class represents a pair of modifier key and its value.

public static enum
KeyCombination.ModifierValue

ModifierValue specifies state of modifier keys.

Field Summary

Modifier and TypeField and Description
private final KeyCombination.ModifierValue
alt

The state of the alt key in this key combination.

public static final KeyCombination.Modifier
ALT_ANY

Modifier which specifies that the alt key can be either up or down.

public static final KeyCombination.Modifier
ALT_DOWN

Modifier which specifies that the alt key must be down.

private final KeyCombination.ModifierValue
control

The state of the control key in this key combination.

public static final KeyCombination.Modifier
CONTROL_ANY

Modifier which specifies that the control key can be either up or down.

public static final KeyCombination.Modifier
CONTROL_DOWN

Modifier which specifies that the control key must be down.

private final KeyCombination.ModifierValue
meta

The state of the meta key in this key combination.

public static final KeyCombination.Modifier
META_ANY

Modifier which specifies that the meta key can be either up or down.

public static final KeyCombination.Modifier
META_DOWN

Modifier which specifies that the meta key must be down.

public static final KeyCombination
NO_MATCH

A KeyCombination that will match with no events.

private static final KeyCombination.Modifier[]
private final KeyCombination.ModifierValue
shift

The state of the shift key in this key combination.

public static final KeyCombination.Modifier
SHIFT_ANY

Modifier which specifies that the shift key can be either up or down.

public static final KeyCombination.Modifier
SHIFT_DOWN

Modifier which specifies that the shift key must be down.

private final KeyCombination.ModifierValue
shortcut

The state of the shortcut key in this key combination.

public static final KeyCombination.Modifier
SHORTCUT_ANY

Modifier which specifies that the shortcut key can be either up or down.

public static final KeyCombination.Modifier
SHORTCUT_DOWN

Modifier which specifies that the shortcut key must be down.

Constructor Summary

AccessConstructor and Description
protected
KeyCombination(final KeyCombination.ModifierValue
the value of the shift modifier key
shift
,
final KeyCombination.ModifierValue
the value of the control modifier key
control
,
final KeyCombination.ModifierValue
the value of the alt modifier key
alt
,
final KeyCombination.ModifierValue
the value of the meta modifier key
meta
,
final KeyCombination.ModifierValue
the value of the shortcut modifier key
shortcut
)

Constructs a KeyCombination with an explicit specification of all modifier keys.

protected
KeyCombination(final KeyCombination.Modifier...
the list of modifier keys and their corresponding values
modifiers
)

Constructs a KeyCombination with the specified list of modifiers.

Method Summary

Modifier and TypeMethod and Description
private static void
addModifierIntoString(final StringBuilder sb, final KeyCode modifierKey, final KeyCombination.ModifierValue modifierValue)

private void
public boolean

Returns:

true if the objects are equal, false otherwise
equals
(final Object
the object to compare to
obj
)

Overrides java.lang.Object.equals.

Tests whether this KeyCombination equals to the specified object.

public final KeyCombination.ModifierValue

Returns:

The state of the alt key in this key combination.
getAlt
()

The state of the alt key in this key combination.

public final KeyCombination.ModifierValue

Returns:

The state of the control key in this key combination
getControl
()

The state of the control key in this key combination.

public String

Returns:

A string representation of this KeyCombination, suitable for display in a user interface.
getDisplayText
()

Returns a string representation of this KeyCombination that is suitable for display in a user interface (for example, beside a menu item).

public final KeyCombination.ModifierValue

Returns:

The state of the meta key in this key combination
getMeta
()

The state of the meta key in this key combination.

pack-priv static KeyCombination.Modifier
getModifier(final String name)

private static KeyCombination.ModifierValue
getModifierValue(final KeyCombination.Modifier[] modifiers, final KeyCode modifierKey)

public String

Returns:

the string representation of this KeyCombination
getName
()

Returns a string representation of this KeyCombination.

public final KeyCombination.ModifierValue

Returns:

The state of the shift key in this key combination
getShift
()

The state of the shift key in this key combination.

public final KeyCombination.ModifierValue

Returns:

The state of the shortcut key in this key combination
getShortcut
()

The state of the shortcut key in this key combination.

public int

Returns:

the hash code value
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this KeyCombination.

public static KeyCombination

Returns:

the constructed KeyCombination
keyCombination
(String
the string which represents the requested key combination
name
)

Constructs a new KeyCombination from the specified string.

public boolean

Returns:

true if the key combinations match, false otherwise
match
(final KeyEvent
the key event
event
)

Tests whether this key combination matches the combination in the given KeyEvent.

private static String
normalizeToken(final String token)

private static KeyCombination.ModifierValue
private static String[]
private static boolean
test(final KeyCode testedModifierKey, final KeyCombination.ModifierValue testedModifierValue, final KeyCode shortcutModifierKey, final KeyCombination.ModifierValue shortcutModifierValue, final boolean isKeyDown)

private static boolean
test(final KeyCombination.ModifierValue modifierValue, final boolean isDown)

public String

Returns:

the string representation of this KeyCombination
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this object.

public static KeyCombination

Returns:

the constructed KeyCombination
valueOf
(String
the string which represents the requested key combination
value
)

Constructs a new KeyCombination from the specified string.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

altback to summary
private final KeyCombination.ModifierValue alt

The state of the alt key in this key combination.

ALT_ANYback to summary
public static final KeyCombination.Modifier ALT_ANY

Modifier which specifies that the alt key can be either up or down.

ALT_DOWNback to summary
public static final KeyCombination.Modifier ALT_DOWN

Modifier which specifies that the alt key must be down.

controlback to summary
private final KeyCombination.ModifierValue control

The state of the control key in this key combination.

CONTROL_ANYback to summary
public static final KeyCombination.Modifier CONTROL_ANY

Modifier which specifies that the control key can be either up or down.

CONTROL_DOWNback to summary
public static final KeyCombination.Modifier CONTROL_DOWN

Modifier which specifies that the control key must be down.

metaback to summary
private final KeyCombination.ModifierValue meta

The state of the meta key in this key combination.

META_ANYback to summary
public static final KeyCombination.Modifier META_ANY

Modifier which specifies that the meta key can be either up or down.

META_DOWNback to summary
public static final KeyCombination.Modifier META_DOWN

Modifier which specifies that the meta key must be down.

NO_MATCHback to summary
public static final KeyCombination NO_MATCH

A KeyCombination that will match with no events.

POSSIBLE_MODIFIERSback to summary
private static final KeyCombination.Modifier[] POSSIBLE_MODIFIERS
shiftback to summary
private final KeyCombination.ModifierValue shift

The state of the shift key in this key combination.

SHIFT_ANYback to summary
public static final KeyCombination.Modifier SHIFT_ANY

Modifier which specifies that the shift key can be either up or down.

SHIFT_DOWNback to summary
public static final KeyCombination.Modifier SHIFT_DOWN

Modifier which specifies that the shift key must be down.

shortcutback to summary
private final KeyCombination.ModifierValue shortcut

The state of the shortcut key in this key combination.

SHORTCUT_ANYback to summary
public static final KeyCombination.Modifier SHORTCUT_ANY

Modifier which specifies that the shortcut key can be either up or down.

SHORTCUT_DOWNback to summary
public static final KeyCombination.Modifier SHORTCUT_DOWN

Modifier which specifies that the shortcut key must be down.

Constructor Detail

KeyCombinationback to summary
protected KeyCombination(final KeyCombination.ModifierValue shift, final KeyCombination.ModifierValue control, final KeyCombination.ModifierValue alt, final KeyCombination.ModifierValue meta, final KeyCombination.ModifierValue shortcut)

Constructs a KeyCombination with an explicit specification of all modifier keys. Each modifier key can be set to DOWN, UP or ANY.

Parameters
shift:KeyCombination.ModifierValue

the value of the shift modifier key

control:KeyCombination.ModifierValue

the value of the control modifier key

alt:KeyCombination.ModifierValue

the value of the alt modifier key

meta:KeyCombination.ModifierValue

the value of the meta modifier key

shortcut:KeyCombination.ModifierValue

the value of the shortcut modifier key

KeyCombinationback to summary
protected KeyCombination(final KeyCombination.Modifier... modifiers)

Constructs a 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.

Parameters
modifiers:KeyCombination.Modifier[]

the list of modifier keys and their corresponding values

Method Detail

addModifierIntoStringback to summary
private static void addModifierIntoString(final StringBuilder sb, final KeyCode modifierKey, final KeyCombination.ModifierValue modifierValue)
addModifiersIntoStringback to summary
private void addModifiersIntoString(final StringBuilder sb)
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Tests whether this KeyCombination equals to the specified object.

Parameters
obj:Object

the object to compare to

Returns:boolean

true if the objects are equal, false otherwise

Annotations
@Override
getAltback to summary
public final KeyCombination.ModifierValue getAlt()

The state of the alt key in this key combination.

Returns:KeyCombination.ModifierValue

The state of the alt key in this key combination.

getControlback to summary
public final KeyCombination.ModifierValue getControl()

The state of the control key in this key combination.

Returns:KeyCombination.ModifierValue

The state of the control key in this key combination

getDisplayTextback to summary
public String getDisplayText()

Returns a string representation of this KeyCombination that is suitable for display in a user interface (for example, beside a menu item).

Returns:String

A string representation of this KeyCombination, suitable for display in a user interface.

Since
JavaFX 8u20
getMetaback to summary
public final KeyCombination.ModifierValue getMeta()

The state of the meta key in this key combination.

Returns:KeyCombination.ModifierValue

The state of the meta key in this key combination

getModifierback to summary
pack-priv static KeyCombination.Modifier getModifier(final String name)
getModifierValueback to summary
private static KeyCombination.ModifierValue getModifierValue(final KeyCombination.Modifier[] modifiers, final KeyCode modifierKey)
getNameback to summary
public String getName()

Returns a string representation of this 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'"
Returns:String

the string representation of this KeyCombination

getShiftback to summary
public final KeyCombination.ModifierValue getShift()

The state of the shift key in this key combination.

Returns:KeyCombination.ModifierValue

The state of the shift key in this key combination

getShortcutback to summary
public final KeyCombination.ModifierValue getShortcut()

The state of the shortcut key in this key combination.

Returns:KeyCombination.ModifierValue

The state of the shortcut key in this key combination

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this KeyCombination.

Returns:int

the hash code value

Annotations
@Override
keyCombinationback to summary
public static KeyCombination keyCombination(String name)

Constructs a new KeyCombination from the specified string. This method simply delegates to valueOf(String).

Parameters
name:String

the string which represents the requested key combination

Returns:KeyCombination

the constructed KeyCombination

See Also
valueOf(String)
matchback to summary
public boolean match(final KeyEvent event)

Tests whether this key combination matches the combination in the given 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.

Parameters
event:KeyEvent

the key event

Returns:boolean

true if the key combinations match, false otherwise

normalizeTokenback to summary
private static String normalizeToken(final String token)
resolveModifierValueback to summary
private static KeyCombination.ModifierValue resolveModifierValue(final KeyCombination.ModifierValue firstValue, final KeyCombination.ModifierValue secondValue)
splitNameback to summary
private static String[] splitName(String name)
testback to summary
private static boolean test(final KeyCode testedModifierKey, final KeyCombination.ModifierValue testedModifierValue, final KeyCode shortcutModifierKey, final KeyCombination.ModifierValue shortcutModifierValue, final boolean isKeyDown)
testback to summary
private static boolean test(final KeyCombination.ModifierValue modifierValue, final boolean isDown)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object. Implementation returns the result of the getName() call.

Returns:String

the string representation of this KeyCombination

Annotations
@Override
valueOfback to summary
public static KeyCombination valueOf(String value)

Constructs a new 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.

Parameters
value:String

the string which represents the requested key combination

Returns:KeyCombination

the constructed KeyCombination

Since
JavaFX 2.1
javafx.scene.input back to summary

public final Class KeyCombination.Modifier

extends Object
Class Inheritance

This class represents a pair of modifier key and its value.
Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
private final KeyCode
private final KeyCombination.ModifierValue

Constructor Summary

AccessConstructor and Description
private
Modifier(final KeyCode key, final KeyCombination.ModifierValue value)

Method Summary

Modifier and TypeMethod and Description
public KeyCode

Returns:

the modifier key
getKey
()

Gets the modifier key of this Modifier.

public KeyCombination.ModifierValue

Returns:

the modifier value
getValue
()

Gets the modifier value of this Modifier.

public String

Returns:

a string representation of the modifier
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the modifier.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

keyback to summary
private final KeyCode key
valueback to summary
private final KeyCombination.ModifierValue value

Constructor Detail

Modifierback to summary
private Modifier(final KeyCode key, final KeyCombination.ModifierValue value)

Method Detail

getKeyback to summary
public KeyCode getKey()

Gets the modifier key of this Modifier.

Returns:KeyCode

the modifier key

getValueback to summary
public KeyCombination.ModifierValue getValue()

Gets the modifier value of this Modifier.

Returns:KeyCombination.ModifierValue

the modifier value

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the modifier.

Returns:String

a string representation of the modifier

Annotations
@Override
javafx.scene.input back to summary

public final Enum KeyCombination.ModifierValue

extends Enum<KeyCombination.ModifierValue>
Class Inheritance

ModifierValue specifies state of modifier keys.
Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
public static final KeyCombination.ModifierValue
ANY

Constant which indicates that the modifier key can be either up or down.

public static final KeyCombination.ModifierValue
DOWN

Constant which indicates that the modifier key must be down.

public static final KeyCombination.ModifierValue
UP

Constant which indicates that the modifier key must be up.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static KeyCombination.ModifierValue
public static KeyCombination.ModifierValue[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ANYback to summary
public static final KeyCombination.ModifierValue ANY

Constant which indicates that the modifier key can be either up or down.

DOWNback to summary
public static final KeyCombination.ModifierValue DOWN

Constant which indicates that the modifier key must be down.

UPback to summary
public static final KeyCombination.ModifierValue UP

Constant which indicates that the modifier key must be up.

Constructor Detail

ModifierValueback to summary
private ModifierValue()

Method Detail

valueOfback to summary
public static KeyCombination.ModifierValue valueOf(String name)
valuesback to summary
public static KeyCombination.ModifierValue[] values()