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