1 package be
.nikiroo
.jvcard
.tui
;
5 import be
.nikiroo
.jvcard
.Card
;
6 import be
.nikiroo
.jvcard
.Contact
;
7 import be
.nikiroo
.jvcard
.Data
;
8 import be
.nikiroo
.jvcard
.i18n
.Trans
.StringId
;
10 import com
.googlecode
.lanterna
.input
.KeyStroke
;
11 import com
.googlecode
.lanterna
.input
.KeyType
;
14 * This class represents a keybinding; it encapsulates data about the actual key
15 * to press and the associated action to take.
17 * You are expected to subclass it if you want to create a custom action.
22 public class KeyAction
{
24 * The keybinding mode that will be triggered by this action.
30 NONE
, MOVE
, BACK
, HELP
, FILE_LIST
, CONTACT_LIST
, CONTACT_DETAILS
, SWICTH_FORMAT
,
33 public enum DataType
{
35 * A list of Card {@link File}s.
39 * Contains a list of contacts.
43 * All the known informations about a specific contact person or
48 * An information about a contact.
58 private KeyStroke key
;
61 public KeyAction(Mode mode
, KeyStroke key
, StringId id
) {
67 public KeyAction(Mode mode
, KeyType keyType
, StringId id
) {
69 this.key
= new KeyStroke(keyType
);
73 public KeyAction(Mode mode
, char car
, StringId id
) {
75 this.key
= new KeyStroke(car
, false, false);
80 * Return the key used to trigger this {@link KeyAction} or '\0' if none.
81 * Also check the special key ({@link KeyAction#getKkey}) if any.
83 * @return the shortcut character to use to invoke this {@link KeyAction} or
86 public KeyStroke
getKey() {
90 // check if the given key should trigger this action
91 public boolean match(KeyStroke mkey
) {
92 if (mkey
== null || key
== null)
95 if (mkey
.getKeyType() == key
.getKeyType()) {
96 if (mkey
.getKeyType() != KeyType
.Character
)
99 return mkey
.getCharacter() == key
.getCharacter();
106 * Return the kind of key this {@link KeyAction } is linked to. Will be
107 * {@link KeyType#NormalKey} if only normal keys can invoke this
108 * {@link KeyAction}. Also check the normal key ({@link KeyAction#getKey})
111 * @return the special shortcut key to use to invoke this {@link KeyAction}
112 * or {@link KeyType#NormalKey}
116 * The mode to change to when this action is completed.
118 * @return the new mode
120 public Mode
getMode() {
124 public StringId
getStringId() {
128 public Card
getCard() {
129 Object o
= getObject();
130 if (o
instanceof Card
)
135 public Contact
getContact() {
136 Object o
= getObject();
137 if (o
instanceof Contact
)
142 public Data
getData() {
143 Object o
= getObject();
144 if (o
instanceof Data
)
149 // override this one if needed
150 public Object
getObject() {
155 * The method which is called when the action is performed. You can subclass
156 * it if you want to customize the action (by default, it just accepts the
157 * mode change (see {@link KeyAction#getMode}).
159 * @return false to cancel mode change
161 public boolean onAction() {