]> git.mxchange.org Git - jfinancials-swing.git/blobdiff - Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
Added a lot stuff:
[jfinancials-swing.git] / Addressbook / src / org / mxchange / addressbook / client / console / ConsoleClient.java
index 841b7b65d8a9d979f17dbc6f75ebba978c3eac83..4803fee54a1594f19e6483198a3f897b08a2741a 100644 (file)
@@ -18,8 +18,6 @@ package org.mxchange.addressbook.client.console;
 \r
 import java.text.MessageFormat;\r
 import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
 import java.util.Scanner;\r
 import org.mxchange.addressbook.UnhandledUserChoiceException;\r
 import org.mxchange.addressbook.application.AddressbookApplication;\r
@@ -39,11 +37,6 @@ import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem;
  * @author Roland Haeder\r
  */\r
 public class ConsoleClient extends BaseClient implements Client {\r
-    /**\r
-     * Menu system\r
-     */\r
-    private final Map<String, Menu> menus;\r
-\r
     /**\r
      * Scanner instance for reading data from console input\r
      */\r
@@ -59,17 +52,8 @@ public class ConsoleClient extends BaseClient implements Client {
        // Set application instance\r
        this.setApplication(application);\r
 \r
-       // Init contact manager here\r
-       this.initContactManager(this);\r
-\r
        // Init scanner instance\r
        this.scanner = new Scanner(System.in);\r
-\r
-       // Init menu map\r
-       this.menus = new HashMap<>(10);\r
-\r
-       // Fill menu map\r
-       this.fillConsoleMenuMap();\r
     }\r
 \r
     /**\r
@@ -81,7 +65,7 @@ public class ConsoleClient extends BaseClient implements Client {
     @Override\r
     public void displayAddressBox (final Contact contact) {\r
        // Simple display ...\r
-        // @todo Use mask\r
+       // @todo Use mask\r
        this.outputMessage("Strasse, PLZ Ort, Land: " + contact.getStreet() + "\n" + contact.getZipCode() + " " + contact.getCity() +  "\n" + contact.getCountryCode());\r
     }\r
 \r
@@ -117,13 +101,24 @@ public class ConsoleClient extends BaseClient implements Client {
     @Override\r
     public void displayOtherDataBox (final Contact contact) {\r
        // Cellphone and such ...\r
-       this.outputMessage("Telefonnumer: " + contact.getPhoneNumber() + "\nFaxnummer: " + contact.getFaxNumber() + "\nHandy: " + contact.getCellphoneNumber() + "\nKommentar:\n" + contact.getComment());\r
+       this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));\r
+    }\r
+\r
+    /**\r
+     * Shutdown this client\r
+     */\r
+    @Override\r
+    public void doShutdown () {\r
+       // Parent call\r
+       super.doShutdown();\r
+\r
+       // @TODO Add other shutdown stuff\r
     }\r
 \r
     @Override\r
     public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
        // Get all access keys from menu\r
-       char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.menus, this.getCurrentMenu());\r
+       char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());\r
 \r
        // Output textural message and ask for a char as input\r
        char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
@@ -142,21 +137,29 @@ public class ConsoleClient extends BaseClient implements Client {
                this.getContactManager().addOtherAddress();\r
                break;\r
        \r
-           case '4': // Change other addess\r
+           case '4': // List contacts\r
+               this.getContactManager().listContacts();\r
+               break;\r
+       \r
+           case '5': // Search addresses\r
+               this.getContactManager().searchContacts();\r
+               break;\r
+\r
+           case '6': // Change other addess\r
                this.getContactManager().changeOtherAddress();\r
                break;\r
        \r
-           case '5': // Delete other address\r
+           case '7': // Delete other address\r
                this.getContactManager().deleteOtherAddress();\r
                break;\r
 \r
            case '0': // Program exit\r
-               this.disableIsRunning();\r
+               this.getApplication().doShutdown();\r
                break;\r
        \r
            default:\r
                // @TODO throw own exception\r
-               throw new UnhandledUserChoiceException("Choice '" + choice + "' not handled yet.");\r
+               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));\r
        }\r
     }\r
 \r
@@ -259,6 +262,18 @@ public class ConsoleClient extends BaseClient implements Client {
        return new ConsoleMenuItem(accessKey,text);\r
     }\r
 \r
+    /**\r
+     * Inizializes this client\r
+     */\r
+    @Override\r
+    public void initClient () {\r
+       // Init contact manager here\r
+       this.initContactManager();\r
+       \r
+       // Fill menu map\r
+       this.fillMenuMap();\r
+    }\r
+\r
     /**\r
      * Displays textural message to the user\r
      * @param message\r
@@ -276,6 +291,11 @@ public class ConsoleClient extends BaseClient implements Client {
        this.showMenu(this.getCurrentMenu());\r
     }\r
 \r
+    /**\r
+     * Shows given menu entry to user\r
+     * \r
+     * @param item Menu entry\r
+     */\r
     @Override\r
     public void showEntry (final SelectableMenuItem item) {\r
        // Access key then text\r
@@ -287,13 +307,13 @@ public class ConsoleClient extends BaseClient implements Client {
      */\r
     @Override\r
     public void showWelcome () {\r
-       this.outputMessage("Welcome to " + AddressbookApplication.APP_TITLE + " v" + AddressbookApplication.APP_VERSION);\r
+       this.outputMessage("Welcome to " + AddressbookApplication.printableTitle());\r
        this.outputMessage("");\r
        this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
        \r
        // Debug message\r
        this.getLogger().debug("Intro shown to user");\r
-     }\r
+    }\r
 \r
     @Override\r
     public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
@@ -324,37 +344,6 @@ public class ConsoleClient extends BaseClient implements Client {
        }\r
     }\r
 \r
-    /**\r
-     * Fills menu map with menu entries\r
-     */\r
-    private void fillConsoleMenuMap () {\r
-       // Initialize first (main) menu\r
-       Menu menu = new ConsoleMenu("main", this);\r
-\r
-       // Add it\r
-       this.menus.put("main", menu);\r
-    }\r
-\r
-    /**\r
-     * "Getter" for given menu type\r
-     * \r
-     * @param menuType Menu type instance to return\r
-     * @return Menu or null if not found\r
-     */\r
-    private Menu getMenu (final String menuType) {\r
-       // Default is not found\r
-       Menu menu = null;\r
-\r
-       // Check array\r
-       if (this.menus.containsKey(menuType)) {\r
-           // Found!\r
-           menu = this.menus.get(menuType);\r
-       }\r
-       \r
-       // Return it\r
-       return menu;\r
-    }\r
-\r
     /**\r
      * Reads one character\r
      * \r
@@ -408,21 +397,14 @@ public class ConsoleClient extends BaseClient implements Client {
     }\r
 \r
     /**\r
-     * Shows given menu\r
-     *\r
-     * @param menuType Given menu to show\r
+     * Fills menu map with menu entries\r
      */\r
-    private void showMenu (final String menuType) {\r
-       Menu menu = this.getMenu(menuType);\r
-       \r
-       // Is the menu set?\r
-       if (!(menu instanceof Menu)) {\r
-           // Not found\r
-           // @todo Own exception?\r
-           throw new NullPointerException("Menu '" + menuType + "' not found.");\r
-       }\r
+    @Override\r
+    protected final void fillMenuMap () {\r
+       // Initialize first (main) menu\r
+       Menu menu = new ConsoleMenu("main", this);\r
        \r
-       // Show menu\r
-       menu.show(this);\r
+       // Add it\r
+       this.getMenus().put("main", menu);\r
     }\r
 }\r