X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FKeyAction.java;h=f39b10324f0eeb8d3fcd62d44fc664a28e791e85;hp=a95835eb28b77468b758b6b53516bf0e481bda7f;hb=7da41ecd30228908bf2afcd07ff7943ab59d4c01;hpb=f04d8b1c4c3ed29d4d23cc076f307ef455b2dcb6 diff --git a/src/be/nikiroo/jvcard/tui/KeyAction.java b/src/be/nikiroo/jvcard/tui/KeyAction.java index a95835e..f39b103 100644 --- a/src/be/nikiroo/jvcard/tui/KeyAction.java +++ b/src/be/nikiroo/jvcard/tui/KeyAction.java @@ -5,7 +5,8 @@ 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; @@ -27,7 +28,7 @@ public class KeyAction { * */ public enum Mode { - NONE, MOVE, BACK, HELP, FILE_LIST, CONTACT_LIST, CONTACT_DETAILS_RAW, CONTACT_DETAILS, EDIT_DETAIL, DELETE_CONTACT, SAVE_CARD, + NONE, MOVE, BACK, HELP, FILE_LIST, CONTACT_LIST, CONTACT_DETAILS_RAW, CONTACT_DETAILS, ASK_USER, ASK_USER_KEY, } public enum DataType { @@ -161,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; + } }