Class ShortcutAction
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ShortcutListener
Actions used to create keyboard
shortcuts.
The ShortcutAction is triggered when the user presses a given key in combination with the (optional) given modifier keys.
ShortcutActions can be global (by attaching to the Window), or attached to
different parts of the UI so that a specific shortcut is only valid in part
of the UI. For instance, one can attach shortcuts to a specific
Panel - look for
ComponentContainers implementing
Action.Handler or Action.Notifier.
ShortcutActions have a caption that may be used to display the shortcut visually. This allows the ShortcutAction to be used as a plain Action while still reacting to a keyboard shortcut. Note that this functionality is not very well supported yet, but it might still be a good idea to give a caption to the shortcut.
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceKey codes that can be used for shortcutsstatic interfaceModifier key constantsNested classes/interfaces inherited from class com.vaadin.featurepack.event.Action
Action.Container, Action.Handler, Action.Listener, Action.Notifier, Action.ShortcutNotifier -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charUsed in the caption shorthand notation to indicate the ALT modifier.static final charUsed in the caption shorthand notation to indicate the CTRL modifier.static final charUsed in the caption shorthand notation to indicate the SHIFT modifier. -
Constructor Summary
ConstructorsConstructorDescriptionShortcutAction(String shorthandCaption) Constructs a ShortcutAction using a shorthand notation to encode the keycode and modifiers in the caption.ShortcutAction(String shorthandCaption, int... modifierKeys) Constructs a ShortcutAction using a shorthand notation to encode the keycode a in the caption.ShortcutAction(String caption, int kc, int... m) Creates a shortcut that reacts to the givenShortcutAction.KeyCodeand (optionally)ShortcutAction.ModifierKeys.ShortcutAction(String caption, com.vaadin.flow.component.icon.Icon icon, int kc, int... m) Creates a shortcut that reacts to the givenShortcutAction.KeyCodeand (optionally)ShortcutAction.ModifierKeys. -
Method Summary
Modifier and TypeMethodDescriptionintGet theShortcutAction.KeyCodethat this shortcut reacts to (in combination with theShortcutAction.ModifierKeys).int[]Get theShortcutAction.ModifierKeys required for the shortcut to react.static com.vaadin.flow.component.KeytoKey(int keyCode) Transforms given keyCode toKey.static com.vaadin.flow.component.KeyModifiertoKeyModifier(int keyCode) Transforms given keyCode toKeyModifier.Methods inherited from class com.vaadin.featurepack.event.Action
getCaption, getIcon, setCaption, setIcon, setIcon
-
Field Details
-
SHORTHAND_CHAR_ALT
public static final char SHORTHAND_CHAR_ALTUsed in the caption shorthand notation to indicate the ALT modifier.- See Also:
-
SHORTHAND_CHAR_SHIFT
public static final char SHORTHAND_CHAR_SHIFTUsed in the caption shorthand notation to indicate the SHIFT modifier.- See Also:
-
SHORTHAND_CHAR_CTRL
public static final char SHORTHAND_CHAR_CTRLUsed in the caption shorthand notation to indicate the CTRL modifier.- See Also:
-
-
Constructor Details
-
ShortcutAction
Creates a shortcut that reacts to the givenShortcutAction.KeyCodeand (optionally)ShortcutAction.ModifierKeys.
The shortcut might be shown in the UI (e.g context menu), in which case the caption will be used.- Parameters:
caption- used when displaying the shortcut visuallykc- KeyCode that the shortcut reacts tom- optional modifier keys
-
ShortcutAction
Creates a shortcut that reacts to the givenShortcutAction.KeyCodeand (optionally)ShortcutAction.ModifierKeys.
The shortcut might be shown in the UI (e.g context menu), in which case the caption and icon will be used.- Parameters:
caption- used when displaying the shortcut visuallyicon- used when displaying the shortcut visuallykc- KeyCode that the shortcut reacts tom- optional modifier keys
-
ShortcutAction
Constructs a ShortcutAction using a shorthand notation to encode the keycode and modifiers in the caption.Insert one or more modifier characters before the character to use as keycode. E.g
"invalid input: '&Save'"will make a shortcut responding to ALT-S,"E^xit"will respond to CTRL-X.
Multiple modifiers can be used, e.g"invalid input: '&'^Delete"will respond to CTRL-ALT-D (the order of the modifier characters is not important).The modifier characters will be removed from the caption. The modifier character is be escaped by itself: two consecutive characters are turned into the original character w/o the special meaning. E.g
"Saveinvalid input: '&'invalid input: '&'invalid input: '&close'"will respond to ALT-C, and the caption will say "Saveinvalid input: '&close'".- Parameters:
shorthandCaption- the caption in modifier shorthand
-
ShortcutAction
Constructs a ShortcutAction using a shorthand notation to encode the keycode a in the caption.This works the same way as
ShortcutAction(String), with the exception that the modifiers given override those indicated in the caption. I.e use any of the modifier characters in the caption to indicate the keycode, but the modifier will be the given set.
E.gnew ShortcutAction("Do invalid input: '&stuff'", new int[]{ShortcutAction.ModifierKey.CTRL}));will respond to CTRL-S.- Parameters:
shorthandCaption-modifierKeys-
-
-
Method Details
-
getKeyCode
public int getKeyCode()Get theShortcutAction.KeyCodethat this shortcut reacts to (in combination with theShortcutAction.ModifierKeys).- Returns:
- keycode for this shortcut
-
getModifiers
public int[] getModifiers()Get theShortcutAction.ModifierKeys required for the shortcut to react.- Returns:
- modifier keys for this shortcut
-
toKey
public static com.vaadin.flow.component.Key toKey(int keyCode) Transforms given keyCode toKey.- Parameters:
keyCode- int value of the keyCode- Returns:
- Key value
-
toKeyModifier
public static com.vaadin.flow.component.KeyModifier toKeyModifier(int keyCode) Transforms given keyCode toKeyModifier.- Parameters:
keyCode- int value of the keyCode- Returns:
- KeyModifier enum value
-