From: Roland Haeder Date: Fri, 24 Jul 2015 09:21:47 +0000 (+0200) Subject: Introduced initStatusPanel() which initializes status panel + renamed methods accordi... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=53f82048c662991034ded4ace8b4f13d2fe7cbed;p=addressbook-swing.git Introduced initStatusPanel() which initializes status panel + renamed methods according to naming convention Signed-off-by:Roland Häder --- diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java index 3759d97..eab7e71 100644 --- a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -175,7 +175,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli } // Init client - client.initClient(); + client.init(); // Set client instance this.setClient(client); diff --git a/Addressbook/src/org/mxchange/addressbook/client/Client.java b/Addressbook/src/org/mxchange/addressbook/client/Client.java index 136c95a..6e28668 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/Client.java +++ b/Addressbook/src/org/mxchange/addressbook/client/Client.java @@ -1,189 +1,189 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client; - -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * An interface for application clients - * - * @author Roland Haeder - */ -public interface Client extends FrameworkInterface { - - /** - * Displays a "box" for the address - * - * @param contact Contact to show address from - */ - public void displayAddressBox (final Contact contact); - - /** - * The user changes own name data - * @param contact - */ - public void doChangeOwnNameData (final Contact contact); - - /** - * The user changes own address data - * - * @param contact Contact instance to change - */ - public void doChangeOwnAddressData (final Contact contact); - - /** - * The user changes own other data - * - * @param contact Constact instance to change - */ - public void doChangeOwnOtherData (final Contact contact); - - /** - * Allows the user to enter own data - * - * @return Finished Contact instance - */ - public Contact doEnterOwnData (); - - /** - * Shuts down the client and therefore whole application - */ - public void doShutdown (); - - /** - * Displays a message to the user - * - * @param message Message to show to the user - */ - public void outputMessage (final String message); - - /** - * Displays a "box" for the name - * - * @param contact Contact to show name from - */ - public void displayNameBox (final Contact contact); - - /** - * Displays a "box" for other data - * - * @param contact Contact to show other data from - */ - public void displayOtherDataBox (final Contact contact); - - /** - * Let the user choose what to change on the address: [n]ame, [a]ddress, - * [o]ther - * - * @param contact Contact instance to let the user change data - * @throws UnhandledUserChoiceException If choice is not supported - */ - public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException; - - /** - * Asks the user for a choice and proceeds accordingly - * - * @throws UnhandledUserChoiceException If choice is not supported - */ - public void doUserMenuChoice () throws UnhandledUserChoiceException ; - - /** - * Enables isRunning attribute which singals that the client is running - */ - public void enableIsRunning(); - - /** - * Asks the the user to enter a single character which must match validChars - * - * @param validChars Valid chars that are accepted - * @param message Message to user - * @return Allowed character - */ - public char enterChar (final char[] validChars, final String message); - - /** - * Reads a string of minimum and maximum length from the user. An empty - * string should be generally not allowed, but might be okay for e.g. - * company name. - * - * @param minLength Minimum length of the string to read - * @param maxLength Maximum length of the string to read - * @param message Message to user - * @param allowEmpty Whether empty strings are allowed - * @return Entered string by user or null if empty string is allowed - */ - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty); - - /** - * Reads an integer (int) from the user - * - * @param minimum Minimum allowed number - * @param maximum Maximum allowed number - * @param message Message to user - * @return Entered string by user or null if empty string is allowed - */ - public int enterInt (final int minimum, final int maximum, final String message); - - /** - * Setter for current menu choice - * - * @param currentMenu Current menu choice - */ - public void setCurrentMenu (final String currentMenu); - - /** - * Some "Getter" for menu item - * - * @param accessKey Key to press to access this menu - * @param text Text to show to user - * @return - */ - public SelectableMenuItem getMenuItem (final char accessKey, final String text); - - /** - * Determines whether the client is still active by checking some - * conditions - * - * @return Whether the client is still active - */ - public boolean isRunning(); - - /** - * Shows given menu entry in client - * - * @param item Menu item to show - */ - public void showEntry (final SelectableMenuItem item); - - /** - * Shows introduction to user - */ - public void showWelcome(); - - /** - * Shows current menu selection to the user - */ - public void showCurrentMenu(); - - /** - * Inizializes this client - */ - public void initClient (); -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client; + +import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * An interface for application clients + * + * @author Roland Haeder + */ +public interface Client extends FrameworkInterface { + + /** + * Displays a "box" for the address + * + * @param contact Contact to show address from + */ + public void displayAddressBox (final Contact contact); + + /** + * The user changes own name data + * @param contact + */ + public void doChangeOwnNameData (final Contact contact); + + /** + * The user changes own address data + * + * @param contact Contact instance to change + */ + public void doChangeOwnAddressData (final Contact contact); + + /** + * The user changes own other data + * + * @param contact Constact instance to change + */ + public void doChangeOwnOtherData (final Contact contact); + + /** + * Allows the user to enter own data + * + * @return Finished Contact instance + */ + public Contact doEnterOwnData (); + + /** + * Shuts down the client and therefore whole application + */ + public void doShutdown (); + + /** + * Displays a message to the user + * + * @param message Message to show to the user + */ + public void outputMessage (final String message); + + /** + * Displays a "box" for the name + * + * @param contact Contact to show name from + */ + public void displayNameBox (final Contact contact); + + /** + * Displays a "box" for other data + * + * @param contact Contact to show other data from + */ + public void displayOtherDataBox (final Contact contact); + + /** + * Let the user choose what to change on the address: [n]ame, [a]ddress, + * [o]ther + * + * @param contact Contact instance to let the user change data + * @throws UnhandledUserChoiceException If choice is not supported + */ + public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException; + + /** + * Asks the user for a choice and proceeds accordingly + * + * @throws UnhandledUserChoiceException If choice is not supported + */ + public void doUserMenuChoice () throws UnhandledUserChoiceException ; + + /** + * Enables isRunning attribute which singals that the client is running + */ + public void enableIsRunning(); + + /** + * Asks the the user to enter a single character which must match validChars + * + * @param validChars Valid chars that are accepted + * @param message Message to user + * @return Allowed character + */ + public char enterChar (final char[] validChars, final String message); + + /** + * Reads a string of minimum and maximum length from the user. An empty + * string should be generally not allowed, but might be okay for e.g. + * company name. + * + * @param minLength Minimum length of the string to read + * @param maxLength Maximum length of the string to read + * @param message Message to user + * @param allowEmpty Whether empty strings are allowed + * @return Entered string by user or null if empty string is allowed + */ + public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty); + + /** + * Reads an integer (int) from the user + * + * @param minimum Minimum allowed number + * @param maximum Maximum allowed number + * @param message Message to user + * @return Entered string by user or null if empty string is allowed + */ + public int enterInt (final int minimum, final int maximum, final String message); + + /** + * Setter for current menu choice + * + * @param currentMenu Current menu choice + */ + public void setCurrentMenu (final String currentMenu); + + /** + * Some "Getter" for menu item + * + * @param accessKey Key to press to access this menu + * @param text Text to show to user + * @return + */ + public SelectableMenuItem getMenuItem (final char accessKey, final String text); + + /** + * Determines whether the client is still active by checking some + * conditions + * + * @return Whether the client is still active + */ + public boolean isRunning(); + + /** + * Shows given menu entry in client + * + * @param item Menu item to show + */ + public void showEntry (final SelectableMenuItem item); + + /** + * Shows introduction to user + */ + public void showWelcome(); + + /** + * Shows current menu selection to the user + */ + public void showCurrentMenu(); + + /** + * Inizializes this client + */ + public void init (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 8d55309..2015873 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -1,505 +1,505 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client.console; - -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Scanner; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.application.AddressbookApplication; -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.client.BaseClient; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.contact.user.UserContact; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.addressbook.menu.MenuTools; -import org.mxchange.addressbook.menu.console.ConsoleMenu; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; - -/** - * A client for the console - * - * @author Roland Haeder - */ -public class ConsoleClient extends BaseClient implements Client { - /** - * Scanner instance for reading data from console input - */ - private final Scanner scanner; - - /** - * Parameterless constructor - * @param application An instance of an Application class - */ - public ConsoleClient (final Application application) { - super(); - - // Set application instance - this.setApplication(application); - - // Init scanner instance - this.scanner = new Scanner(System.in); - } - - /** - * Displays a textual address "box" of given contact - * - * @param contact Contact to show address for - */ - @Override - public void displayAddressBox (final Contact contact) { - // Simple display ... - this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode())); - } - - /** - * Displays a textual name "box" of given contact - * - * @param contact Contact to show name for - */ - @Override - public void displayNameBox (final Contact contact) { - // Get translated gender as the user may want to see "Mr.", "Mrs." - String gender = contact.getTranslatedGender(); - - // Get company name - String companyName = contact.getCompanyName(); - - // If it is empty/null, then assume private contact - if ((companyName == null) || (companyName.isEmpty())) { - // Now put all together: gender, surname, family name - // @todo Use mask - this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName())); - } else { - // Company contact - this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName())); - } - } - - /** - * Displays a textual other data "box" of given contact - * - * @param contact Contact to show other data for - */ - @Override - public void displayOtherDataBox (final Contact contact) { - // Cellphone and such ... - this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment())); - } - - @Override - public void doChangeOwnAddressData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Own address data - String street = this.getContactManager().enterOwnStreet(); - - // Get zip code - int zipCode = this.getContactManager().enterOwnZipCode(); - - // Get city name - String city = this.getContactManager().enterOwnCity(); - - // Get country code - String countryCode = this.getContactManager().enterOwnCountryCode(); - - // Update address data - contact.updateAddressData(street, zipCode, city, countryCode); - } - - @Override - public void doChangeOwnNameData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Gender: - char gender = this.getContactManager().enterOwnGender(); - - // Surname - String surname = this.getContactManager().enterOwnSurname(); - - // Family name - String familyName = this.getContactManager().enterOwnFamilyName(); - - // And company - String companyName = this.getContactManager().enterOwnCompanyName(); - - // Update contact instance - contact.updateNameData(gender, surname, familyName, companyName); - } - - @Override - public void doChangeOwnOtherData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Phone number - String phoneNumber = this.getContactManager().enterOwnPhoneNumber(); - - // Phone number - String cellNumber = this.getContactManager().enterOwnCellNumber(); - - // Fax number - String faxNumber = this.getContactManager().enterOwnFaxNumber(); - - // Email address - String email = this.getContactManager().enterOwnEmailAddress(); - - // Comment - String comment = this.getContactManager().enterOwnComment(); - - // Update contact instance - contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment); - } - - @Override - public Contact doEnterOwnData () { - // First ask for gender - char gender = this.getContactManager().enterOwnGender(); - - // 2nd for surname - String surname = this.getContactManager().enterOwnSurname(); - - // And 3rd for family name - String familyName = this.getContactManager().enterOwnFamilyName(); - - // Company name ... - String companyName = this.getContactManager().enterOwnCompanyName(); - - // Construct UserContact instance - Contact contact = new UserContact(gender, surname, familyName, companyName); - - // And return object - return contact; - } - - /** - * 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.getMenus(), this.getCurrentMenu()); - - // Output textural message and ask for a char as input - char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); - - // @TODO Rewrite this ugly switch() block - switch (choice) { - case '1': // Enter/add own data - this.getContactManager().doEnterOwnData(); - break; - - case '2': // Change own data - this.getContactManager().changeOwnData(); - break; - - case '3': // Add new addess - this.getContactManager().addOtherAddress(); - break; - - 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 '7': // Delete other address - this.getContactManager().deleteOtherAddress(); - break; - - case '0': // Program exit - this.getApplication().doShutdown(); - break; - - default: - // @TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); - } - } - - /** - * Asks the the user to enter a single character which must match validChars - * @param validChars Valid chars that are accepted - * @param message Message to user - * @return Allowed character - */ - @Override - public char enterChar (final char[] validChars, final String message) { - char input = 0; - - // Sort array, else binarySearch() won't work - Arrays.sort(validChars); - - // Keep asking until valid char has been entered - while (Arrays.binarySearch(validChars, input) < 0) { - // Output message - System.out.print(message); - - // Read char - input = this.readChar(); - } - - // Return read char - return input; - } - - /** - * Reads an integer (int) with a textural message from the user - * - * @param minimum Minimum allowed number - * @param maximum Maximum allowed number - * @param message Messager to display in console - * @return - */ - @Override - public int enterInt (final int minimum, final int maximum, final String message) { - // Minimum should not be below zero - assert(minimum >= 0); - assert(maximum > minimum); - - // Init input - int input = -1; - - while ((input < minimum) || (input > maximum)) { - // Output message - System.out.print(message); - - // Read integer from user - input = this.readInt(); - } - - // Return it - return input; - } - - /** - * Reads a string of minimum and maximum length from the user - * - * @param minLength Minimum length of the string to read - * @param maxLength Maximum length of the string to read - * @param message Message to user - * @param allowEmpty Whether to allow empty string - * @return Entered string by user or null for empty strings - */ - @Override - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { - // Check on length, e.g. country codes are excactly 2 chars long - assert(maxLength >= minLength); - - // Init input - String input = null; - - // Check if it is to short or to long - while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) { - // Output message - System.out.print(message); - - // Read line - input = this.readString(); - } - - // Return it - return input; - } - - /** - * Returns a console menu item - * - * @param accessKey Key to access the menu - * @param text Text to show to user - * @return A SelectableMenuItem - * @todo Make sure the access key is unique - */ - @Override - public SelectableMenuItem getMenuItem (final char accessKey, final String text) { - // Return a new console menu item - 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 - */ - @Override - public void outputMessage (final String message) { - System.out.println(message); - } - - /** - * Shows textural menu on console - */ - @Override - public void showCurrentMenu () { - 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 - this.outputMessage("[" + item.getAccessKey() + "] " + item.getText()); - } - - /** - * Shows a textural message to the user - */ - @Override - public void showWelcome () { - this.outputMessage(MessageFormat.format("Welcome to {0}", 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 { - // Ask the user for editing [name], [a]ddress or [other] data - char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) "); - - // @TODO Get rid of this ugly switch block, too - switch (choice) { - case 'n': // Name data - this.getContactManager().doChangeNameData(contact, this); - break; - - case 'a': // Address data - this.getContactManager().doChangeAddressData(contact, this); - break; - - case 'o': // Other data - this.getContactManager().doChangeOtherData(contact, this); - break; - - case 'x': // Exit this menu - // Ignored as it should go back - break; - - default: - // @TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); - } - } - - /** - * Reads one character - * - * @return A single character - */ - private char readChar () { - // Read line - String input = this.scanner.nextLine(); - - // This must be only one character - if (input.length() != 1) { - // Return zero - return 0; - } - - // Get char from first (and only) position - return input.charAt(0); - } - - /** - * Reads an integer (int) from user - * - * @return An integer number - */ - private int readInt () { - // First read a string - String input = this.readString(); - - // Init number with invalid value - int num = -1; - - // Parse number, this can be risky - try { - num = Integer.parseInt(input); - } catch (final NumberFormatException e) { - this.outputMessage("Bitte geben Sie nur Zahlen ein!"); - this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); - } - - // Return read number - return num; - } - - /** - * Reads a string from a scanner until RETURN is pressed - * - * @return Read string from scanner - */ - private String readString () { - return this.scanner.nextLine(); - } - - /** - * Fills menu map with menu entries - */ - @Override - protected final void fillMenuMap () { - // Initialize first (main) menu - Menu menu = new ConsoleMenu("main", this); - - // Add it - this.getMenus().put("main", menu); - } -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client.console; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Scanner; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.application.AddressbookApplication; +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.client.BaseClient; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.contact.user.UserContact; +import org.mxchange.addressbook.menu.Menu; +import org.mxchange.addressbook.menu.MenuTools; +import org.mxchange.addressbook.menu.console.ConsoleMenu; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; +import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; + +/** + * A client for the console + * + * @author Roland Haeder + */ +public class ConsoleClient extends BaseClient implements Client { + /** + * Scanner instance for reading data from console input + */ + private final Scanner scanner; + + /** + * Parameterless constructor + * @param application An instance of an Application class + */ + public ConsoleClient (final Application application) { + super(); + + // Set application instance + this.setApplication(application); + + // Init scanner instance + this.scanner = new Scanner(System.in); + } + + /** + * Displays a textual address "box" of given contact + * + * @param contact Contact to show address for + */ + @Override + public void displayAddressBox (final Contact contact) { + // Simple display ... + this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode())); + } + + /** + * Displays a textual name "box" of given contact + * + * @param contact Contact to show name for + */ + @Override + public void displayNameBox (final Contact contact) { + // Get translated gender as the user may want to see "Mr.", "Mrs." + String gender = contact.getTranslatedGender(); + + // Get company name + String companyName = contact.getCompanyName(); + + // If it is empty/null, then assume private contact + if ((companyName == null) || (companyName.isEmpty())) { + // Now put all together: gender, surname, family name + // @todo Use mask + this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName())); + } else { + // Company contact + this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName())); + } + } + + /** + * Displays a textual other data "box" of given contact + * + * @param contact Contact to show other data for + */ + @Override + public void displayOtherDataBox (final Contact contact) { + // Cellphone and such ... + this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment())); + } + + @Override + public void doChangeOwnAddressData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Own address data + String street = this.getContactManager().enterOwnStreet(); + + // Get zip code + int zipCode = this.getContactManager().enterOwnZipCode(); + + // Get city name + String city = this.getContactManager().enterOwnCity(); + + // Get country code + String countryCode = this.getContactManager().enterOwnCountryCode(); + + // Update address data + contact.updateAddressData(street, zipCode, city, countryCode); + } + + @Override + public void doChangeOwnNameData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Gender: + char gender = this.getContactManager().enterOwnGender(); + + // Surname + String surname = this.getContactManager().enterOwnSurname(); + + // Family name + String familyName = this.getContactManager().enterOwnFamilyName(); + + // And company + String companyName = this.getContactManager().enterOwnCompanyName(); + + // Update contact instance + contact.updateNameData(gender, surname, familyName, companyName); + } + + @Override + public void doChangeOwnOtherData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Phone number + String phoneNumber = this.getContactManager().enterOwnPhoneNumber(); + + // Phone number + String cellNumber = this.getContactManager().enterOwnCellNumber(); + + // Fax number + String faxNumber = this.getContactManager().enterOwnFaxNumber(); + + // Email address + String email = this.getContactManager().enterOwnEmailAddress(); + + // Comment + String comment = this.getContactManager().enterOwnComment(); + + // Update contact instance + contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment); + } + + @Override + public Contact doEnterOwnData () { + // First ask for gender + char gender = this.getContactManager().enterOwnGender(); + + // 2nd for surname + String surname = this.getContactManager().enterOwnSurname(); + + // And 3rd for family name + String familyName = this.getContactManager().enterOwnFamilyName(); + + // Company name ... + String companyName = this.getContactManager().enterOwnCompanyName(); + + // Construct UserContact instance + Contact contact = new UserContact(gender, surname, familyName, companyName); + + // And return object + return contact; + } + + /** + * 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.getMenus(), this.getCurrentMenu()); + + // Output textural message and ask for a char as input + char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); + + // @TODO Rewrite this ugly switch() block + switch (choice) { + case '1': // Enter/add own data + this.getContactManager().doEnterOwnData(); + break; + + case '2': // Change own data + this.getContactManager().doChangeOwnData(); + break; + + case '3': // Add new addess + this.getContactManager().doAddOtherAddress(); + break; + + case '4': // List contacts + this.getContactManager().doListContacts(); + break; + + case '5': // Search addresses + this.getContactManager().doSearchContacts(); + break; + + case '6': // Change other addess + this.getContactManager().doChangeOtherAddress(); + break; + + case '7': // Delete other address + this.getContactManager().doDeleteOtherAddress(); + break; + + case '0': // Program exit + this.getApplication().doShutdown(); + break; + + default: + // @TODO throw own exception + throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); + } + } + + /** + * Asks the the user to enter a single character which must match validChars + * @param validChars Valid chars that are accepted + * @param message Message to user + * @return Allowed character + */ + @Override + public char enterChar (final char[] validChars, final String message) { + char input = 0; + + // Sort array, else binarySearch() won't work + Arrays.sort(validChars); + + // Keep asking until valid char has been entered + while (Arrays.binarySearch(validChars, input) < 0) { + // Output message + System.out.print(message); + + // Read char + input = this.readChar(); + } + + // Return read char + return input; + } + + /** + * Reads an integer (int) with a textural message from the user + * + * @param minimum Minimum allowed number + * @param maximum Maximum allowed number + * @param message Messager to display in console + * @return + */ + @Override + public int enterInt (final int minimum, final int maximum, final String message) { + // Minimum should not be below zero + assert(minimum >= 0); + assert(maximum > minimum); + + // Init input + int input = -1; + + while ((input < minimum) || (input > maximum)) { + // Output message + System.out.print(message); + + // Read integer from user + input = this.readInt(); + } + + // Return it + return input; + } + + /** + * Reads a string of minimum and maximum length from the user + * + * @param minLength Minimum length of the string to read + * @param maxLength Maximum length of the string to read + * @param message Message to user + * @param allowEmpty Whether to allow empty string + * @return Entered string by user or null for empty strings + */ + @Override + public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { + // Check on length, e.g. country codes are excactly 2 chars long + assert(maxLength >= minLength); + + // Init input + String input = null; + + // Check if it is to short or to long + while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) { + // Output message + System.out.print(message); + + // Read line + input = this.readString(); + } + + // Return it + return input; + } + + /** + * Returns a console menu item + * + * @param accessKey Key to access the menu + * @param text Text to show to user + * @return A SelectableMenuItem + * @todo Make sure the access key is unique + */ + @Override + public SelectableMenuItem getMenuItem (final char accessKey, final String text) { + // Return a new console menu item + return new ConsoleMenuItem(accessKey,text); + } + + /** + * Inizializes this client + */ + @Override + public void init () { + // Init contact manager here + this.initContactManager(); + + // Fill menu map + this.fillMenuMap(); + } + + /** + * Displays textural message to the user + * @param message + */ + @Override + public void outputMessage (final String message) { + System.out.println(message); + } + + /** + * Shows textural menu on console + */ + @Override + public void showCurrentMenu () { + 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 + this.outputMessage("[" + item.getAccessKey() + "] " + item.getText()); + } + + /** + * Shows a textural message to the user + */ + @Override + public void showWelcome () { + this.outputMessage(MessageFormat.format("Welcome to {0}", 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 { + // Ask the user for editing [name], [a]ddress or [other] data + char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) "); + + // @TODO Get rid of this ugly switch block, too + switch (choice) { + case 'n': // Name data + this.getContactManager().doChangeNameData(contact, this); + break; + + case 'a': // Address data + this.getContactManager().doChangeAddressData(contact, this); + break; + + case 'o': // Other data + this.getContactManager().doChangeOtherData(contact, this); + break; + + case 'x': // Exit this menu + // Ignored as it should go back + break; + + default: + // @TODO throw own exception + throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); + } + } + + /** + * Reads one character + * + * @return A single character + */ + private char readChar () { + // Read line + String input = this.scanner.nextLine(); + + // This must be only one character + if (input.length() != 1) { + // Return zero + return 0; + } + + // Get char from first (and only) position + return input.charAt(0); + } + + /** + * Reads an integer (int) from user + * + * @return An integer number + */ + private int readInt () { + // First read a string + String input = this.readString(); + + // Init number with invalid value + int num = -1; + + // Parse number, this can be risky + try { + num = Integer.parseInt(input); + } catch (final NumberFormatException e) { + this.outputMessage("Bitte geben Sie nur Zahlen ein!"); + this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); + } + + // Return read number + return num; + } + + /** + * Reads a string from a scanner until RETURN is pressed + * + * @return Read string from scanner + */ + private String readString () { + return this.scanner.nextLine(); + } + + /** + * Fills menu map with menu entries + */ + @Override + protected final void fillMenuMap () { + // Initialize first (main) menu + Menu menu = new ConsoleMenu("main", this); + + // Add it + this.getMenus().put("main", menu); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index 0cd0a3f..c0f132f 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -62,6 +62,15 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Return instance return self; } + /** + * Frame instance for "add own data" + */ + private JMenuItem addOwnItem; + + /** + * Frame instance for "edit own data" + */ + private JMenuItem editOwnItem; /** * Frame instance @@ -78,11 +87,6 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame */ private JLabel statusLabel; - /** - * Frame instance - */ - private JMenuItem addOwnItem; - /** * Creates an instance of this frame with a client instance * @@ -123,8 +127,11 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Debug message this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); - // Not entered yet, so enable menu + // Not entered yet, so disable "add" menu this.addOwnItem.setEnabled(false); + } else { + // Disable "edit" + this.editOwnItem.setEnabled(false); } // Make the frame visible @@ -142,7 +149,7 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice */ @Override - public void initFrame () throws FrameAlreadyInitializedException { + public void init () throws FrameAlreadyInitializedException { // Debug line this.getLogger().trace("CALLED!"); @@ -216,14 +223,8 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Init status label (which needs to be updated this.statusLabel = new JLabel(this.getBundle().getString("AddressbookFrame.statusLabel.initializing.text")); - // Init status bar in south - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); - panel.add(this.statusLabel); - panel.setBorder(BorderFactory.createEtchedBorder()); - - // Add panel to frame - this.frame.add(panel, BorderLayout.SOUTH); + // Init status panel + initStatusPanel(); } /** @@ -287,6 +288,26 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Add item -> menu menu.add(this.addOwnItem); + // 2.2) Edit own data + this.editOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.text")); + this.editOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.toolTipText")); + + // Add listener to exit menu + this.editOwnItem.addActionListener(new ActionListener() { + /** + * If the user has performed this action + * + * @param e An instance of an ActionEvent class + */ + @Override + public void actionPerformed (final ActionEvent e) { + self.getClient().getContactManager().doChangeOwnData(); + } + }); + + // Add item -> menu + menu.add(this.editOwnItem); + // Add menu -> menu bar menuBar.add(menu); @@ -294,4 +315,17 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame this.frame.add(menuBar, BorderLayout.NORTH); } + /** + * Initializes status panel + */ + private void initStatusPanel () { + // Init status bar in south + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); + panel.add(this.statusLabel); + panel.setBorder(BorderFactory.createEtchedBorder()); + + // Add panel to frame + this.frame.add(panel, BorderLayout.SOUTH); + } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java index f0cc531..5039528 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -33,8 +33,8 @@ public interface ClientFrame extends FrameworkInterface { public void doShutdown (); /** - * Setups the frame (and starts it). You have to call initFrame() before you - * can call this method. + * Setups the frame (and starts it). You have to call init() before you + can call this method. * * @param client Client instance */ @@ -45,7 +45,7 @@ public interface ClientFrame extends FrameworkInterface { * * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice */ - public void initFrame () throws FrameAlreadyInitializedException; + public void init () throws FrameAlreadyInitializedException; /** * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index c616ae9..29fc9a6 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -153,7 +153,7 @@ public class SwingClient extends BaseClient implements Client { * Inizializes this client */ @Override - public void initClient () { + public void init () { // Debug message this.getLogger().trace("CALLED!"); @@ -162,7 +162,7 @@ public class SwingClient extends BaseClient implements Client { try { // Init frame - this.frame.initFrame(); + this.frame.init(); } catch (final FrameAlreadyInitializedException ex) { this.getLogger().catching(ex); System.exit(1); diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties index 29fec7d..e6907ee 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties @@ -22,3 +22,5 @@ AddressbookFrame.menuItem.exitProgram.text=Programm beenden AddressbookFrame.menu.addressbook.text=Adressbuch AddressbookFrame.menuItem.addOwnData.text=Eigene Adresse hinzuf\u00fcgen AddressbookFrame.menuItem.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten. +AddressbookFrame.menuItem.editOwnData.text=Eigene Adresse \u00e4ndern +AddressbookFrame.menuItem.editOwnData.toolTipText=Erlaubt das \u00c4ndern eigener Daten. diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties index 4def06b..c929532 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties @@ -22,3 +22,5 @@ AddressbookFrame.menuItem.exitProgram.text=Exit program AddressbookFrame.addressbookMenu.text=Addressbook AddressbookFrame.menuItem.addOwnData.text=Add own address AddressbookFrame.menuItem.addOwnData.toolTipText=Allows the user to add own address data +AddressbookFrame.menuItem.editOwnData.text=Edit own data +AddressbookFrame.menuItem.editOwnData.toolTipText=Allows the user to edit own address data diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index 5c4f54e..da2fe32 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -96,7 +96,7 @@ public class ContactManager extends BaseManager implements ManageableContact { * Let the user add a new other address */ @Override - public void addOtherAddress () { + public void doAddOtherAddress () { throw new UnsupportedOperationException("Not supported yet."); } @@ -104,7 +104,7 @@ public class ContactManager extends BaseManager implements ManageableContact { * Let the user change other address */ @Override - public void changeOtherAddress () { + public void doChangeOtherAddress () { throw new UnsupportedOperationException("Not supported yet."); } @@ -112,7 +112,7 @@ public class ContactManager extends BaseManager implements ManageableContact { * Allows the user to change his/her own data */ @Override - public void changeOwnData () { + public void doChangeOwnData () { /* * First check if the user has registered own contact, before that * nothing can be changed. @@ -146,7 +146,7 @@ public class ContactManager extends BaseManager implements ManageableContact { * Let the user delete other address */ @Override - public void deleteOtherAddress () { + public void doDeleteOtherAddress () { throw new UnsupportedOperationException("Not supported yet."); } @@ -423,7 +423,7 @@ public class ContactManager extends BaseManager implements ManageableContact { } @Override - public void listContacts () { + public void doListContacts () { throw new UnsupportedOperationException("Not supported yet."); } @@ -455,7 +455,7 @@ public class ContactManager extends BaseManager implements ManageableContact { } @Override - public void searchContacts () { + public void doSearchContacts () { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java index 736053d..6914a26 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java @@ -1,229 +1,229 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.manager.contact; - -import java.util.List; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.manager.Manageable; - -/** - * - * @author Roland Haeder - */ -public interface ManageableContact extends Manageable { - - /** - * Shuts down this contact manager - */ - public void doShutdown (); - - /** - * Allows the user to enter own cellphone number. - * - * @return Cellphone number - */ - public String enterOwnCellNumber (); - - /** - * Allows the user to enter own city name. - * - * @return City name - */ - public String enterOwnCity (); - - /** - * Allows the user to enter comment for own entry. - * - * @return Comment - */ - public String enterOwnComment (); - - /** - * Allows the user to enter own company name. - * - * @return Company name - */ - public String enterOwnCompanyName (); - - /** - * Allows the user to enter own country code. - * - * @return Country code - */ - public String enterOwnCountryCode (); - - /** - * Allows the user to enter own email address. - * - * @return Email address - */ - public String enterOwnEmailAddress (); - - /** - * Allows the user to enter own family name. - * - * @return Family name - */ - public String enterOwnFamilyName (); - - /** - * Allows the user to enter own fax number. - * - * @return Fax number - */ - public String enterOwnFaxNumber (); - - /** - * Allows the user to enter own gender. - * - * @return Gender - */ - public char enterOwnGender (); - - /** - * Allows the user to enter own phone number. - * - * @return Phone number - */ - public String enterOwnPhoneNumber (); - - /** - * Allows the user to enter own street and house number. - * - * @return Street and house number - */ - public String enterOwnStreet (); - - /** - * Allows the user to enter own surname. - * - * @return Surname - */ - public String enterOwnSurname (); - - /** - * Allows the user to enter own ZIP code. - * - * @return ZIP code - */ - public int enterOwnZipCode (); - - /** - * Getter for column count - * - * @return Column count - */ - public int getColumnCount (); - - /** - * List all contacts - */ - public void listContacts (); - - /** - * Adds given contact to address book - * - * @param contact Contact being added - * @todo Add check for book size - */ - public void registerContact (final Contact contact); - - /** - * Adds given Contact instance to list - * - * @param contact Contact instance to add - */ - public void addContact (final Contact contact); - - /** - * Let the user add a new other address - */ - public void addOtherAddress(); - - /** - * The user can change address data, like street, ZIP code, city and country - * of given Contact instance. - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeAddressData (final Contact contact, final Client client); - - /** - * The user can change name data, like gender, surname, family name and - * company name (if business contact). - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeNameData (final Contact contact, final Client client); - - /** - * Let the user change other address - */ - public void changeOtherAddress(); - - /** - * The user can change other data, like phone numbers or comments. - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeOtherData (final Contact contact, final Client client); - - /** - * Let the user change own data - */ - public void changeOwnData(); - - /** - * Let the user delete other address - */ - public void deleteOtherAddress(); - - /** - * Asks user for own data - */ - public void doEnterOwnData(); - - /** - * Getter for whole list - * @return List of all contacts - */ - public List getList (); - - /** - * Searches address book for a contact - */ - public void searchContacts (); - - /** - * Checks whether own contact is already added by checking all entries for - * isOwnContact flag - * - * @return Whether own contact is already added - */ - public boolean isOwnContactAdded (); - - /** - * Getter for size - * - * @return size of contact "book" - */ - public int size(); -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.manager.contact; + +import java.util.List; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.manager.Manageable; + +/** + * + * @author Roland Haeder + */ +public interface ManageableContact extends Manageable { + + /** + * Shuts down this contact manager + */ + public void doShutdown (); + + /** + * Allows the user to enter own cellphone number. + * + * @return Cellphone number + */ + public String enterOwnCellNumber (); + + /** + * Allows the user to enter own city name. + * + * @return City name + */ + public String enterOwnCity (); + + /** + * Allows the user to enter comment for own entry. + * + * @return Comment + */ + public String enterOwnComment (); + + /** + * Allows the user to enter own company name. + * + * @return Company name + */ + public String enterOwnCompanyName (); + + /** + * Allows the user to enter own country code. + * + * @return Country code + */ + public String enterOwnCountryCode (); + + /** + * Allows the user to enter own email address. + * + * @return Email address + */ + public String enterOwnEmailAddress (); + + /** + * Allows the user to enter own family name. + * + * @return Family name + */ + public String enterOwnFamilyName (); + + /** + * Allows the user to enter own fax number. + * + * @return Fax number + */ + public String enterOwnFaxNumber (); + + /** + * Allows the user to enter own gender. + * + * @return Gender + */ + public char enterOwnGender (); + + /** + * Allows the user to enter own phone number. + * + * @return Phone number + */ + public String enterOwnPhoneNumber (); + + /** + * Allows the user to enter own street and house number. + * + * @return Street and house number + */ + public String enterOwnStreet (); + + /** + * Allows the user to enter own surname. + * + * @return Surname + */ + public String enterOwnSurname (); + + /** + * Allows the user to enter own ZIP code. + * + * @return ZIP code + */ + public int enterOwnZipCode (); + + /** + * Getter for column count + * + * @return Column count + */ + public int getColumnCount (); + + /** + * List all contacts + */ + public void doListContacts (); + + /** + * Adds given contact to address book + * + * @param contact Contact being added + * @todo Add check for book size + */ + public void registerContact (final Contact contact); + + /** + * Adds given Contact instance to list + * + * @param contact Contact instance to add + */ + public void addContact (final Contact contact); + + /** + * Let the user add a new other address + */ + public void doAddOtherAddress(); + + /** + * The user can change address data, like street, ZIP code, city and country + * of given Contact instance. + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeAddressData (final Contact contact, final Client client); + + /** + * The user can change name data, like gender, surname, family name and + * company name (if business contact). + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeNameData (final Contact contact, final Client client); + + /** + * Let the user change other address + */ + public void doChangeOtherAddress(); + + /** + * The user can change other data, like phone numbers or comments. + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeOtherData (final Contact contact, final Client client); + + /** + * Let the user change own data + */ + public void doChangeOwnData(); + + /** + * Let the user delete other address + */ + public void doDeleteOtherAddress(); + + /** + * Asks user for own data + */ + public void doEnterOwnData(); + + /** + * Getter for whole list + * @return List of all contacts + */ + public List getList (); + + /** + * Searches address book for a contact + */ + public void doSearchContacts (); + + /** + * Checks whether own contact is already added by checking all entries for + * isOwnContact flag + * + * @return Whether own contact is already added + */ + public boolean isOwnContactAdded (); + + /** + * Getter for size + * + * @return size of contact "book" + */ + public int size(); +}