1 package be
.nikiroo
.jvcard
.tui
;
3 import be
.nikiroo
.jvcard
.Card
;
4 import be
.nikiroo
.jvcard
.Contact
;
5 import be
.nikiroo
.jvcard
.Data
;
6 import be
.nikiroo
.jvcard
.i18n
.Trans
.StringId
;
8 import com
.googlecode
.lanterna
.input
.KeyStroke
;
9 import com
.googlecode
.lanterna
.input
.KeyType
;
12 * This class represents a keybinding; it encapsulates data about the actual key
13 * to press and the associated action to take.
15 * You are expected to subclass it if you want to create a custom action.
20 public class KeyAction
{
22 * The keybinding mode that will be triggered by this action.
28 NONE
, MOVE
, BACK
, HELP
, CONTACT_LIST
, CONTACT_DETAILS
, SWICTH_FORMAT
,
32 CONTACT
, CARD
, DATA
, NONE
36 private KeyStroke key
;
39 public KeyAction(Mode mode
, KeyStroke key
, StringId id
) {
45 public KeyAction(Mode mode
, KeyType keyType
, StringId id
) {
47 this.key
= new KeyStroke(keyType
);
51 public KeyAction(Mode mode
, char car
, StringId id
) {
53 this.key
= new KeyStroke(car
, false, false);
58 * Return the key used to trigger this {@link KeyAction} or '\0' if none.
59 * Also check the special key ({@link KeyAction#getKkey}) if any.
61 * @return the shortcut character to use to invoke this {@link KeyAction} or
64 public KeyStroke
getKey() {
68 // check if the given key should trigger this action
69 public boolean match(KeyStroke mkey
) {
70 if (mkey
== null || key
== null)
73 if (mkey
.getKeyType() == key
.getKeyType()) {
74 if (mkey
.getKeyType() != KeyType
.Character
)
77 return mkey
.getCharacter() == key
.getCharacter();
84 * Return the kind of key this {@link KeyAction } is linked to. Will be
85 * {@link KeyType#NormalKey} if only normal keys can invoke this
86 * {@link KeyAction}. Also check the normal key ({@link KeyAction#getKey})
89 * @return the special shortcut key to use to invoke this {@link KeyAction}
90 * or {@link KeyType#NormalKey}
94 * The mode to change to when this action is completed.
96 * @return the new mode
98 public Mode
getMode() {
102 public StringId
getStringId() {
106 public Card
getCard() {
107 Object o
= getObject();
108 if (o
instanceof Card
)
113 public Contact
getContact() {
114 Object o
= getObject();
115 if (o
instanceof Contact
)
120 public Data
getData() {
121 Object o
= getObject();
122 if (o
instanceof Data
)
127 // override this one if needed
128 public Object
getObject() {
133 * The method which is called when the action is performed. You can subclass
134 * it if you want to customize the action (by default, it just accepts the
135 * mode change (see {@link KeyAction#getMode}).
137 * @return false to cancel mode change
139 public boolean onAction() {