X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FKeyAction.java;h=f39b10324f0eeb8d3fcd62d44fc664a28e791e85;hb=7da41ecd30228908bf2afcd07ff7943ab59d4c01;hp=e6aad034a2627da68f1961b18c2d82f879fdbe28;hpb=a3b510ab4bf89a7a2a05f3851ffe0f030b8a78f4;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/KeyAction.java b/src/be/nikiroo/jvcard/tui/KeyAction.java index e6aad03..f39b103 100644 --- a/src/be/nikiroo/jvcard/tui/KeyAction.java +++ b/src/be/nikiroo/jvcard/tui/KeyAction.java @@ -1,9 +1,12 @@ package be.nikiroo.jvcard.tui; +import java.io.File; + import be.nikiroo.jvcard.Card; import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; -import be.nikiroo.jvcard.i18n.Trans.StringId; +import be.nikiroo.jvcard.launcher.Main; +import be.nikiroo.jvcard.resources.Trans.StringId; import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyType; @@ -24,12 +27,32 @@ public class KeyAction { * @author niki * */ - enum Mode { - NONE, MOVE, BACK, HELP, CONTACT_LIST, CONTACT_DETAILS, SWICTH_FORMAT, + public enum Mode { + NONE, MOVE, BACK, HELP, FILE_LIST, CONTACT_LIST, CONTACT_DETAILS_RAW, CONTACT_DETAILS, ASK_USER, ASK_USER_KEY, } - enum DataType { - CONTACT, CARD, DATA, NONE + public enum DataType { + /** + * A list of Card {@link File}s. + */ + CARD_FILES, + /** + * Contains a list of contacts. + */ + CARD, + /** + * All the known informations about a specific contact person or + * company. + */ + CONTACT, + /** + * An information about a contact. + */ + DATA, + /** + * Empty. + */ + NONE } private StringId id; @@ -124,14 +147,14 @@ public class KeyAction { return null; } - // override this one if needed + // override this one if needed, DO NOT process here as it will be call a lot public Object getObject() { return null; } /** * The method which is called when the action is performed. You can subclass - * it if you want to customize the action (by default, it just accepts the + * it if you want to customise the action (by default, it just accepts the * mode change (see {@link KeyAction#getMode}). * * @return false to cancel mode change @@ -139,4 +162,81 @@ public class KeyAction { public boolean onAction() { return true; } + + /** + * Used to callback a function from the menu when the user has to introduce + * some text. + * + * @param answer + * the user answer + * + * @return an error message if any + */ + public String callback(String answer) { + return null; + } + + /** + * When asking a question to the user, return the question. + * + * @return the question + */ + public String getQuestion() { + return null; + } + + /** + * When asking a question to the user (not for one-key mode), return the + * default answer. + * + * @return the default answer + */ + public String getDefaultAnswer() { + return null; + } + + /** + * Translate the given {@link KeyStroke} into a user text {@link String} of + * size 3. + * + * @param key + * the key to translate + * + * @return the translated text + */ + static public String trans(KeyStroke key) { + String keyTrans = ""; + + switch (key.getKeyType()) { + case Enter: + if (Main.isUnicode()) + keyTrans = " ⤶ "; + else + keyTrans = Main.trans(StringId.KEY_ENTER); + break; + case Tab: + if (Main.isUnicode()) + keyTrans = " ↹ "; + else + keyTrans = Main.trans(StringId.KEY_TAB); + + break; + case Character: + keyTrans = " " + key.getCharacter() + " "; + break; + default: + keyTrans = "" + key.getKeyType(); + int width = 3; + if (keyTrans.length() > width) { + keyTrans = keyTrans.substring(0, width); + } else if (keyTrans.length() < width) { + keyTrans = keyTrans + + new String(new char[width - keyTrans.length()]) + .replace('\0', ' '); + } + break; + } + + return keyTrans; + } }