com.vaadin.event.
Class ShortcutAction
java.lang.Object
com.vaadin.event.Action
com.vaadin.event.ShortcutAction
All Implemented Interfaces:
Direct Known Subclasses:
- extends Action
public class ShortcutAction
Shortcuts are a special type of Action
s 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 ComponentContainer
s 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.
Since:
4.0.1
Version:
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
static interface |
ShortcutAction.KeyCode
Key codes that can be used for shortcuts |
static interface |
ShortcutAction.ModifierKey
Modifier key constants |
Nested classes/interfaces inherited from class com.vaadin.event.Action |
---|
Action.Container, Action.Handler, Action.Listener, Action.Notifier, Action.ShortcutNotifier |
Field Summary | |
---|---|
static char |
SHORTHAND_CHAR_ALT
Used in the caption shorthand notation to indicate the ALT modifier. |
static char |
SHORTHAND_CHAR_CTRL
Used in the caption shorthand notation to indicate the CTRL modifier. |
static char |
SHORTHAND_CHAR_SHIFT
Used in the caption shorthand notation to indicate the SHIFT modifier. |
Constructor Summary | |
---|---|
ShortcutAction(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 given ShortcutAction.KeyCode and
(optionally) ShortcutAction.ModifierKey s. |
|
ShortcutAction(String caption,
Resource icon,
int kc,
int[] m)
Creates a shortcut that reacts to the given ShortcutAction.KeyCode and
(optionally) ShortcutAction.ModifierKey s. |
Method Summary | |
---|---|
int |
getKeyCode()
Get the ShortcutAction.KeyCode that this shortcut reacts to (in combination with
the ShortcutAction.ModifierKey s). |
int[] |
getModifiers()
Get the ShortcutAction.ModifierKey s required for the shortcut to react. |
Methods inherited from class com.vaadin.event.Action |
---|
getCaption, getIcon, setCaption, setIcon |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
SHORTHAND_CHAR_ALT
public static final char SHORTHAND_CHAR_ALT
- See Also:
- Constant Field Values
Used in the caption shorthand notation to indicate the ALT modifier.
SHORTHAND_CHAR_SHIFT
public static final char SHORTHAND_CHAR_SHIFT
- See Also:
- Constant Field Values
Used in the caption shorthand notation to indicate the SHIFT modifier.
SHORTHAND_CHAR_CTRL
public static final char SHORTHAND_CHAR_CTRL
- See Also:
- Constant Field Values
Used in the caption shorthand notation to indicate the CTRL modifier.
Constructor Detail |
---|
ShortcutAction
public ShortcutAction(String caption,
int kc,
int[] m)
- Parameters:
caption
- used when displaying the shortcut visuallykc
- KeyCode that the shortcut reacts tom
- optional modifier keys
Creates a shortcut that reacts to the given ShortcutAction.KeyCode
and
(optionally) ShortcutAction.ModifierKey
s.
The shortcut might be shown in the UI (e.g context menu), in which case
the caption will be used.
ShortcutAction
public ShortcutAction(String caption,
Resource icon,
int kc,
int[] m)
- Parameters:
caption
- used when displaying the shortcut visuallyicon
- used when displaying the shortcut visuallykc
- KeyCode that the shortcut reacts tom
- optional modifier keys
Creates a shortcut that reacts to the given ShortcutAction.KeyCode
and
(optionally) ShortcutAction.ModifierKey
s.
The shortcut might be shown in the UI (e.g context menu), in which case
the caption and icon will be used.
ShortcutAction
public ShortcutAction(String shorthandCaption)
- Parameters:
shorthandCaption
- the caption in modifier shorthand
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 "&Save"
will make a shortcut responding to
ALT-S, "E^xit"
will respond to CTRL-X.
Multiple modifiers can be used, e.g "&^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
"Save&&&close"
will respond to ALT-C, and the caption will
say "Save&close".
ShortcutAction
public ShortcutAction(String shorthandCaption,
int[] modifierKeys)
- Parameters:
shorthandCaption
-modifierKeys
-
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.g
new ShortcutAction("Do &stuff", new int[]{ShortcutAction.ModifierKey.CTRL}));
will respond to CTRL-S.
Method Detail |
---|
getKeyCode
public int getKeyCode()
- Returns:
- keycode for this shortcut
Get the ShortcutAction.KeyCode
that this shortcut reacts to (in combination with
the ShortcutAction.ModifierKey
s).
getModifiers
public int[] getModifiers()
- Returns:
- modifier keys for this shortcut
Get the ShortcutAction.ModifierKey
s required for the shortcut to react.