--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!-- You may freely edit this file. See commented blocks below for -->\r
+<!-- some examples of how to customize the build. -->\r
+<!-- (If you delete it and reopen the project it will be recreated.) -->\r
+<!-- By default, only the Clean and Build commands use this build script. -->\r
+<!-- Commands such as Run, Debug, and Test only use this build script if -->\r
+<!-- the Compile on Save feature is turned off for the project. -->\r
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->\r
+<!-- in the project's Project Properties dialog box.-->\r
+<project name="Addressbook" default="default" basedir=".">\r
+ <description>Builds, tests, and runs the project Addressbook.</description>\r
+ <import file="nbproject/build-impl.xml"/>\r
+ <!--\r
+\r
+ There exist several targets which are by default empty and which can be \r
+ used for execution of your tasks. These targets are usually executed \r
+ before and after some main targets. They are: \r
+\r
+ -pre-init: called before initialization of project properties\r
+ -post-init: called after initialization of project properties\r
+ -pre-compile: called before javac compilation\r
+ -post-compile: called after javac compilation\r
+ -pre-compile-single: called before javac compilation of single file\r
+ -post-compile-single: called after javac compilation of single file\r
+ -pre-compile-test: called before javac compilation of JUnit tests\r
+ -post-compile-test: called after javac compilation of JUnit tests\r
+ -pre-compile-test-single: called before javac compilation of single JUnit test\r
+ -post-compile-test-single: called after javac compilation of single JUunit test\r
+ -pre-jar: called before JAR building\r
+ -post-jar: called after JAR building\r
+ -post-clean: called after cleaning build products\r
+\r
+ (Targets beginning with '-' are not intended to be called on their own.)\r
+\r
+ Example of inserting an obfuscator after compilation could look like this:\r
+\r
+ <target name="-post-compile">\r
+ <obfuscate>\r
+ <fileset dir="${build.classes.dir}"/>\r
+ </obfuscate>\r
+ </target>\r
+\r
+ For list of available properties check the imported \r
+ nbproject/build-impl.xml file. \r
+\r
+\r
+ Another way to customize the build is by overriding existing main targets.\r
+ The targets of interest are: \r
+\r
+ -init-macrodef-javac: defines macro for javac compilation\r
+ -init-macrodef-junit: defines macro for junit execution\r
+ -init-macrodef-debug: defines macro for class debugging\r
+ -init-macrodef-java: defines macro for class execution\r
+ -do-jar: JAR building\r
+ run: execution of project \r
+ -javadoc-build: Javadoc generation\r
+ test-report: JUnit report generation\r
+\r
+ An example of overriding the target for project execution could look like this:\r
+\r
+ <target name="run" depends="Addressbook-impl.jar">\r
+ <exec dir="bin" executable="launcher.exe">\r
+ <arg file="${dist.jar}"/>\r
+ </exec>\r
+ </target>\r
+\r
+ Notice that the overridden target depends on the jar target and not only on \r
+ the compile target as the regular run target does. Again, for a list of available \r
+ properties which you can use, check the target you are overriding in the\r
+ nbproject/build-impl.xml file. \r
+\r
+ -->\r
+</project>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (C) 2015 Roland Häder
+
+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 <http://www.gnu.org/licenses/>.
+-->
+<Configuration status="WARN">
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Root level="trace">
+ <AppenderRef ref="STDOUT" level="DEBUG"/>
+ </Root>
+ </Loggers>
+</Configuration>
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook;\r
+\r
+import org.apache.logging.log4j.LogManager;\r
+import org.apache.logging.log4j.Logger;\r
+import org.mxchange.addressbook.application.Application;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.manager.contact.ContactManager;\r
+import org.mxchange.addressbook.manager.contact.ManageableContact;\r
+\r
+/**\r
+ * General class\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseFrameworkSystem {\r
+ /**\r
+ * Class' logger\r
+ */\r
+ private final Logger LOG;\r
+\r
+ /**\r
+ * Application instance\r
+ */\r
+ private Application application;\r
+\r
+ /**\r
+ * Client instance\r
+ */\r
+ private Client client;\r
+\r
+ /**\r
+ * Contact manager instance\r
+ */\r
+ private ManageableContact contactManager;\r
+\r
+ /**\r
+ * Initialize object\r
+ */\r
+ {\r
+ LOG = LogManager.getLogger(this);\r
+ }\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseFrameworkSystem () {\r
+ }\r
+\r
+ /**\r
+ * Application instance\r
+ * @return the application\r
+ */\r
+ public Application getApplication () {\r
+ return this.application;\r
+ }\r
+\r
+ /**\r
+ * Application instance\r
+ * @param application the application to set\r
+ */\r
+ protected void setApplication (final Application application) {\r
+ this.application = application;\r
+ }\r
+\r
+ /**\r
+ * Client instance\r
+ * @return the client\r
+ */\r
+ public Client getClient () {\r
+ return this.client;\r
+ }\r
+\r
+ /**\r
+ * Client instance\r
+ * @param client the client to set\r
+ */\r
+ protected void setClient (final Client client) {\r
+ this.client = client;\r
+ }\r
+\r
+ /**\r
+ * Contact manager instance\r
+ * @return the contactManager\r
+ */\r
+ public ManageableContact getContactManager () {\r
+ return this.contactManager;\r
+ }\r
+\r
+ /**\r
+ * Contact manager instance\r
+ * @param contactManager the contactManager to set\r
+ */\r
+ protected void setContactManager(final ManageableContact contactManager) {\r
+ this.contactManager = contactManager;\r
+ }\r
+\r
+ /**\r
+ * Getter for logger\r
+ *\r
+ * @return Logger\r
+ */\r
+ protected Logger getLogger () {\r
+ return this.LOG;\r
+ }\r
+\r
+ /**\r
+ * Initializes contact manager\r
+ * @param client Client instance\r
+ */\r
+ protected void initContactManager (final Client client) {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing contact manager ...");\r
+\r
+ // Init contact manager with console client\r
+ // @TODO Static initial amount of contacts\r
+ ManageableContact manager = new ContactManager (100, client);\r
+\r
+ // Set it here\r
+ this.setContactManager(manager);\r
+\r
+ // Debug message\r
+ this.getLogger().debug("Contact manager has been initialized.");\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 KLC\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook;\r
+\r
+import org.mxchange.addressbook.manager.contact.ManageableContact;\r
+\r
+/**\r
+ *\r
+ * @author KLC\r
+ */\r
+public interface FrameworkInterface {\r
+\r
+ /**\r
+ * Getter for contact manager\r
+ * @return Contact manager instance\r
+ */\r
+ public ManageableContact getContactManager ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.application;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.client.console.ConsoleClient;\r
+import org.mxchange.addressbook.manager.application.ApplicationManager;\r
+\r
+/**\r
+ * ============================================\r
+ * AddressbookApplication management:\r
+ * ============================================\r
+ * \r
+ * Inernet("public" service) and Intranet\r
+ * \r
+ * Version 1.0+:\r
+ * - Single-user local application\r
+ * - Fields:\r
+ * + Gender\r
+ * + Surname\r
+ * + Family name\r
+ * + Company name\r
+ * + Street + number\r
+ * + ZIP code\r
+ * + City\r
+ * + Landline number\r
+ * + Fax number\r
+ * + Cell phone number\r
+ * + Email address\r
+ * + Birth day\r
+ * + Comment (?)\r
+ * - Edit own data\r
+ * - Add new contact\r
+ * - Edit contacts\r
+ * - Delete contacts\r
+ * - Categorization of contacts\r
+ * \r
+ * Version 1.1+:\r
+ * - Permanent storage in database\r
+ * \r
+ * Version 2.0+:\r
+ * - Multi-user web application\r
+ * - Local user registration / login / resend confirmation link / password\r
+ * recovery\r
+ * - User groups (aka. teams)\r
+ * - Administration area (user role)\r
+ * + Create/edit/delete groups\r
+ * + Edit/delete/lock/unlock user\r
+ * + Assign user roles/rights\r
+ * - Allow other users / groups to view addressbook\r
+ * + Full addressbook\r
+ * + Only some categories\r
+ * - VCard export\r
+ * + Allow users/guests (not recommended)\r
+ * - XML export of addressbook and compressable (ZIP)\r
+ * - Form to contact other user/group without need of mail program\r
+ * + User can disabled this\r
+ * - Directory for ussers/groups (who allowed to be listed)\r
+ * + Simple click to add user to own addressbook\r
+ * + Search form?\r
+ * \r
+ * Version 2.1+:\r
+ * - Multi-language support\r
+ * \r
+ * Version 2.2+:("socialized")\r
+ * - "Social login" (OpenID consumer)\r
+ * + Connect user account to social account\r
+ * + Sync own data?\r
+ * - "Social profile"\r
+ * + OpenID provider\r
+ * + RSS/activity feed \r
+ * \r
+ * ============================================\r
+ * Time esitmation:\r
+ * ============================================\r
+ * 1.0 (console):\r
+ * + 2 days\r
+ * \r
+ * 1.1 (database):\r
+ * + 2 day\r
+ * + Initial tables: contacts, categories, contact_category\r
+ * \r
+ * 2.0 (web):\r
+ * + 3 days\r
+ * + Additional tables: admins (?), admin_rights, groups,\r
+ * users, user_contacts, user_user_rights, user_category_rights, \r
+ * \r
+ * 2.1 (language)\r
+ * + 1 day\r
+ * + Additional tables: languages (disable, enable language "pack" ?)\r
+ * \r
+ * 2.2 (social):\r
+ * + 3 days\r
+ * + Additional tables: ???\r
+ * \r
+ * @author Roland Haeder\r
+ * @version 0.0\r
+ * @since 0.0\r
+ */\r
+public class AddressbookApplication extends BaseFrameworkSystem implements Application {\r
+ /**\r
+ * Application title\r
+ */\r
+ public static final String APP_TITLE = "Addressbuch";\r
+\r
+ /**\r
+ * Application version\r
+ */\r
+ public static final String APP_VERSION = "0.0";\r
+\r
+ /**\r
+ * Main method (entry point)\r
+ *\r
+ * @param args the command line arguments\r
+ */\r
+ public static void main (String[] args) {\r
+ // Start application\r
+ new AddressbookApplication().start ();\r
+ }\r
+\r
+ /**\r
+ * Bootstraps application\r
+ */\r
+ @Override\r
+ public void doBootstrap () {\r
+ this.getLogger().debug("Initializing application ...");\r
+ \r
+ // Init client instance\r
+ Client client = new ConsoleClient(this);\r
+\r
+ // Init client instance\r
+ this.setClient(client);\r
+ \r
+ // The application is running at this point\r
+ this.getClient().enableIsRunning();\r
+ }\r
+\r
+ /**\r
+ * Main loop of the application\r
+ */\r
+ @Override\r
+ public void doMainLoop () {\r
+ // @TODO The application should be running now\r
+ \r
+ // Output introduction\r
+ this.showIntro();\r
+\r
+ // Set current menu to main\r
+ this.getClient().setCurrentMenu("main");\r
+\r
+ // --- Main loop starts here ---\r
+ while (this.getClient().isApplicationRunning()) {\r
+ // The application is still active, show menu selection\r
+ this.getClient().showCurrentMenu();\r
+\r
+ try {\r
+ // Ask for user input and run proper method\r
+ this.getClient().doUserChoice();\r
+ } catch (final Exception ex) {\r
+ this.getLogger().catching(ex);\r
+ }\r
+ }\r
+ // --- Main loop ends here ---\r
+\r
+ // Debug message\r
+ this.getLogger().debug("Main loop exit - shutting down ...");\r
+ }\r
+\r
+ /**\r
+ * Show introduction which depends on client\r
+ */\r
+ private void showIntro () {\r
+ // Let the client show it\r
+ this.getClient().showWelcome();\r
+ }\r
+\r
+ /**\r
+ * Launches the application\r
+ */\r
+ private void start () {\r
+ this.getLogger().info("Program is started.");\r
+\r
+ // Launch application\r
+ ApplicationManager.getManager(this).start ();\r
+\r
+ this.getLogger().info("End of program (last line)");\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.application;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface Application extends FrameworkInterface {\r
+ /**\r
+ * Bootstraps the application\r
+ */\r
+ public void doBootstrap ();\r
+\r
+ /**\r
+ * Run the main loop\r
+ */\r
+ public void doMainLoop ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.client;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ * A general client\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseClient extends BaseFrameworkSystem {\r
+\r
+ /**\r
+ * Current menu choice\r
+ */\r
+ private String currentMenu;\r
+\r
+ /**\r
+ * Application is not running by default\r
+ */\r
+ private boolean isRunning;\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseClient () {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * Disables running state, so the main loop can abort.\r
+ */\r
+ public void disableIsRunning () {\r
+ this.isRunning = false;\r
+ }\r
+\r
+ public void enableIsRunning () {\r
+ this.isRunning = true;\r
+ }\r
+\r
+ /**\r
+ * Current menu choice\r
+ * @return the currentMenu\r
+ */\r
+ public String getCurrentMenu () {\r
+ return this.currentMenu;\r
+ }\r
+\r
+ /**\r
+ * Current menu choice\r
+ * @param currentMenu the currentMenu to set\r
+ */\r
+ public void setCurrentMenu (final String currentMenu) {\r
+ this.currentMenu = currentMenu;\r
+ }\r
+\r
+ public boolean isApplicationRunning () {\r
+ // In console client, 0 may have been used\r
+ return this.isRunning;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.client;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface Client extends FrameworkInterface {\r
+\r
+ /**\r
+ * Displays a message to the user\r
+ * @param message Message to show to the user\r
+ */\r
+ public void displayMessage (final String message);\r
+\r
+ /**\r
+ * Asks the user for a choice and proceeds accordingly\r
+ * @throws java.lang.Exception\r
+ */\r
+ public void doUserChoice () throws Exception ;\r
+\r
+ /**\r
+ * Enables isRunning attribute which singals that the client is running\r
+ */\r
+ public void enableIsRunning ();\r
+\r
+ /**\r
+ * Asks the the user to enter a single character which must match validChars\r
+ * @param validChars Valid chars that are accepted\r
+ * @param message Message to user\r
+ * @return Allowed character\r
+ */\r
+ public char enterChar (final char[] validChars, final String message);\r
+\r
+ /**\r
+ * Reads a string of minimum and maximum length from the user\r
+ * @param minLength Minimum length of the string to read\r
+ * @param maxLength Maximum length of the string to read\r
+ * @param message Message to user\r
+ * @return \r
+ */\r
+ public String enterString (final int minLength, final int maxLength, final String message);\r
+\r
+ /**\r
+ * Setter for current menu choice\r
+ * @param currentMenu Current menu choice\r
+ */\r
+ public void setCurrentMenu (final String currentMenu);\r
+\r
+ /**\r
+ * Some "Getter" for menu item\r
+ * @param accessKey Key to press to access this menu\r
+ * @param text Text to show to user\r
+ * @return \r
+ */\r
+ public SelectableMenuItem getMenuItem (final char accessKey, final String text);\r
+\r
+ /**\r
+ * Determines whether the application is still active by checking some\r
+ * conditions\r
+ * \r
+ * @return Whether the application is still active\r
+ */\r
+ public boolean isApplicationRunning ();\r
+\r
+ /**\r
+ * Shows given menu entry in client\r
+ * @param item Menu item to show\r
+ */\r
+ public void showEntry (final SelectableMenuItem item);\r
+\r
+ /**\r
+ * Shows introduction to user\r
+ */\r
+ public void showWelcome ();\r
+\r
+ /**\r
+ * Shows current menu selection to the user\r
+ */\r
+ public void showCurrentMenu ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.client.console;\r
+\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.application.AddressbookApplication;\r
+import org.mxchange.addressbook.application.Application;\r
+import org.mxchange.addressbook.client.BaseClient;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.Menu;\r
+import org.mxchange.addressbook.menu.MenuTools;\r
+import org.mxchange.addressbook.menu.console.ConsoleMenu;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem;\r
+\r
+/**\r
+ * A client for the console\r
+ *\r
+ * @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
+ private final Scanner scanner;\r
+\r
+ /**\r
+ * Parameterless constructor\r
+ * @param application An instance of an Application class\r
+ */\r
+ public ConsoleClient (final Application application) {\r
+ super();\r
+\r
+ // 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
+ * Displays textural message to the user\r
+ * @param message \r
+ */\r
+ @Override\r
+ public void displayMessage (final String message) {\r
+ System.out.println(message);\r
+ }\r
+\r
+ @Override\r
+ public void doUserChoice () throws Exception {\r
+ // Get all access keys from menu\r
+ char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.menus, this.getCurrentMenu());\r
+\r
+ // Output textural message and ask for a char as input\r
+ char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Beenden/Zurück in's vorherhige Menü): ");\r
+\r
+ // @TODO Rewrite this ugly switch() block\r
+ switch (choice) {\r
+ case '1': // Enter/add own data\r
+ this.getContactManager().enterOwnData();\r
+ break;\r
+ \r
+ case '2': // Change own data\r
+ this.getContactManager().changeOwnData();\r
+ break;\r
+ \r
+ case '3': // Add new addess\r
+ this.getContactManager().addOtherAddress();\r
+ break;\r
+ \r
+ case '4': // Change other addess\r
+ this.getContactManager().changeOtherAddress();\r
+ break;\r
+ \r
+ case '5': // Delete other address\r
+ this.getContactManager().deleteOtherAddress();\r
+ break;\r
+\r
+ case '0': // Program exit\r
+ this.disableIsRunning();\r
+ break;\r
+ \r
+ default:\r
+ // @TODO throw on exception\r
+ throw new Exception("choice " + choice + " invalid");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Asks the the user to enter a single character which must match validChars\r
+ * @param validChars Valid chars that are accepted\r
+ * @param message Message to user\r
+ * @return Allowed character\r
+ */\r
+ @Override\r
+ public char enterChar (final char[] validChars, final String message) {\r
+ char input = 0;\r
+\r
+ // Sort array, else binarySearch() won't work\r
+ Arrays.sort(validChars);\r
+\r
+ // Keep asking until valid char has been entered\r
+ while (Arrays.binarySearch(validChars, input) < 0) {\r
+ // Output message\r
+ System.out.print(message);\r
+\r
+ // Read char\r
+ input = this.readChar();\r
+ }\r
+\r
+ // Return read char\r
+ return input;\r
+ }\r
+\r
+ /**\r
+ * Reads a string of minimum and maximum length from the user\r
+ * @param minLength Minimum length of the string to read\r
+ * @param maxLength Maximum length of the string to read\r
+ * @param message Message to user\r
+ * @return \r
+ */\r
+ @Override\r
+ public String enterString (final int minLength, final int maxLength, final String message) {\r
+ // Init input\r
+ String input = null;\r
+\r
+ // Check if it is to short or to long\r
+ while ((input == null) || (input.length() < minLength) || (input.length() > maxLength)) {\r
+ // Output message\r
+ System.out.print(message);\r
+\r
+ // Read line\r
+ input = this.readString();\r
+ }\r
+\r
+ // Return it\r
+ return input;\r
+ }\r
+\r
+ /**\r
+ * Returns a console menu item\r
+ * \r
+ * @param accessKey Key to access the menu\r
+ * @param text Text to show to user\r
+ * @return A SelectableMenuItem\r
+ * @todo Make sure the access key is unique\r
+ */\r
+ @Override\r
+ public SelectableMenuItem getMenuItem (final char accessKey, final String text) {\r
+ // Return a new console menu item\r
+ return new ConsoleMenuItem(accessKey,text);\r
+ }\r
+\r
+ /**\r
+ * Shows textural menu on console\r
+ */\r
+ @Override\r
+ public void showCurrentMenu () {\r
+ this.showMenu(this.getCurrentMenu());\r
+ }\r
+\r
+ @Override\r
+ public void showEntry (final SelectableMenuItem item) {\r
+ // Access key then text\r
+ this.displayMessage("[" + item.getAccessKey() + "] " + item.getText());\r
+ }\r
+\r
+ /**\r
+ * Shows a textural message to the user\r
+ */\r
+ @Override\r
+ public void showWelcome () {\r
+ this.displayMessage("Welcome to " + AddressbookApplication.APP_TITLE + " v" + AddressbookApplication.APP_VERSION);\r
+ this.displayMessage("");\r
+ this.displayMessage("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
+ * 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
+ * @return \r
+ */\r
+ private char readChar () {\r
+ // Read line\r
+ String input = this.scanner.nextLine();\r
+\r
+ // This must be only one character\r
+ if (input.length() != 1) {\r
+ // Return zero\r
+ return 0;\r
+ }\r
+\r
+ // Get char from first (and only) position\r
+ return input.charAt(0);\r
+ }\r
+\r
+ /**\r
+ * Reads a string from a scanner until RETURN is pressed\r
+ * \r
+ * @return Read string from scanner\r
+ */\r
+ private String readString () {\r
+ return this.scanner.nextLine();\r
+ }\r
+\r
+ /**\r
+ * Shows given menu\r
+ *\r
+ * @param menuType Given menu to show\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
+ \r
+ // Show menu\r
+ menu.show(this);\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.contact;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ * A general contact\r
+ *\r
+ * @author Roland Haeder\r
+ * @version 0.0\r
+ * @since 0.0\r
+ */\r
+public class BaseContact extends BaseFrameworkSystem {\r
+ /**\r
+ * Birth day\r
+ */\r
+ private String birthday;\r
+\r
+ /**\r
+ * Cellphone number\r
+ */\r
+ private String cellphoneNumber;\r
+\r
+ /**\r
+ * City\r
+ */\r
+ private String city;\r
+\r
+ /**\r
+ * Optional comments\r
+ */\r
+ private String comment;\r
+\r
+ /**\r
+ * Companyname\r
+ */\r
+ private String companyName;\r
+\r
+ /**\r
+ * Country code\r
+ */\r
+ private String countryCode;\r
+\r
+ /**\r
+ * Email address\r
+ */\r
+ private String emailAddress;\r
+\r
+ /**\r
+ * Family name\r
+ */\r
+ private String familyName;\r
+\r
+ /**\r
+ * Fax number\r
+ */\r
+ private String faxNumber;\r
+\r
+ /**\r
+ * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =\r
+ * Company\r
+ */\r
+ private char gender;\r
+\r
+ /**\r
+ * House number\r
+ */\r
+ private int houseNumber;\r
+\r
+ /**\r
+ * Marker whether this contact is user's own data\r
+ */\r
+ private boolean ownContact;\r
+\r
+ /**\r
+ * Phone number\r
+ */\r
+ private String phoneNumber;\r
+\r
+ /**\r
+ * Street\r
+ */\r
+ private String street;\r
+\r
+ /**\r
+ * Surname\r
+ */\r
+ private String surname;\r
+\r
+ /**\r
+ * ZIP code\r
+ */\r
+ private int zipCode;\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseContact () {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * Enables the flag "own data" which signals that this contact is the user's\r
+ * own data.\r
+ */\r
+ public void enableFlagOwnContact () {\r
+ this.ownContact = true;\r
+ }\r
+\r
+ /**\r
+ * Check if contacts are same or throw an exception\r
+ *\r
+ * @param object Other possible contact class\r
+ * @return Whether both contacts are same\r
+ */\r
+ @Override\r
+ public boolean equals (Object object) {\r
+ // Try to cast\r
+ BaseContact c = (BaseContact) object;\r
+ \r
+ /*\r
+ * Now test some data @todo Definedly needs improvement\r
+ */\r
+ return ((this.getGender() == c.getGender())\r
+ && (this.getSurname().toLowerCase().equals(c.getSurname().toLowerCase()))\r
+ && (this.getFamilyName().toLowerCase().equals(c.getFamilyName().toLowerCase())));\r
+ }\r
+\r
+ /**\r
+ * Birth day\r
+ *\r
+ * @return the birthday\r
+ */\r
+ public String getBirthday () {\r
+ return this.birthday;\r
+ }\r
+\r
+ /**\r
+ * Birth day\r
+ *\r
+ * @param birthday the birthday to set\r
+ */\r
+ public void setBirthday (final String birthday) {\r
+ this.birthday = birthday;\r
+ }\r
+\r
+ /**\r
+ * Cellphone number\r
+ *\r
+ * @return the cellphoneNumber\r
+ */\r
+ public String getCellphoneNumber () {\r
+ return this.cellphoneNumber;\r
+ }\r
+\r
+ /**\r
+ * Cellphone number\r
+ *\r
+ * @param cellphoneNumber the cellphoneNumber to set\r
+ */\r
+ public void setCellphoneNumber (final String cellphoneNumber) {\r
+ this.cellphoneNumber = cellphoneNumber;\r
+ }\r
+\r
+ /**\r
+ * City\r
+ *\r
+ * @return the city\r
+ */\r
+ public String getCity () {\r
+ return this.city;\r
+ }\r
+\r
+ /**\r
+ * City\r
+ *\r
+ * @param city the city to set\r
+ */\r
+ public void setCity (final String city) {\r
+ this.city = city;\r
+ }\r
+\r
+ /**\r
+ * Comments\r
+ *\r
+ * @return the comment\r
+ */\r
+ public String getComment () {\r
+ return this.comment;\r
+ }\r
+\r
+ /**\r
+ * Comments\r
+ *\r
+ * @param comment the comment to set\r
+ */\r
+ public void setComment (final String comment) {\r
+ this.comment = comment;\r
+ }\r
+\r
+ /**\r
+ * Companyname\r
+ *\r
+ * @return the companyName\r
+ */\r
+ public String getCompanyName () {\r
+ return this.companyName;\r
+ }\r
+\r
+ /**\r
+ * Companyname\r
+ *\r
+ * @param companyName the companyName to set\r
+ */\r
+ public void setCompanyName (final String companyName) {\r
+ this.companyName = companyName;\r
+ }\r
+\r
+ /**\r
+ * Country code\r
+ *\r
+ * @return the countryCode\r
+ */\r
+ public String getCountryCode () {\r
+ return this.countryCode;\r
+ }\r
+\r
+ /**\r
+ * Country code\r
+ *\r
+ * @param countryCode the countryCode to set\r
+ */\r
+ public void setCountryCode (final String countryCode) {\r
+ this.countryCode = countryCode;\r
+ }\r
+\r
+ /**\r
+ * Email address\r
+ *\r
+ * @return the emailAddress\r
+ */\r
+ public String getEmailAddress () {\r
+ return this.emailAddress;\r
+ }\r
+\r
+ /**\r
+ * Email address\r
+ *\r
+ * @param emailAddress the emailAddress to set\r
+ */\r
+ public void setEmailAddress (final String emailAddress) {\r
+ this.emailAddress = emailAddress;\r
+ }\r
+\r
+ /**\r
+ * Family name\r
+ *\r
+ * @return the familyName\r
+ */\r
+ public String getFamilyName () {\r
+ return this.familyName;\r
+ }\r
+\r
+ /**\r
+ * Family name\r
+ *\r
+ * @param familyName the familyName to set\r
+ */\r
+ public void setFamilyName (final String familyName) {\r
+ this.familyName = familyName;\r
+ }\r
+\r
+ /**\r
+ * Fax number\r
+ *\r
+ * @return the faxNumber\r
+ */\r
+ public String getFaxNumber () {\r
+ return this.faxNumber;\r
+ }\r
+\r
+ /**\r
+ * Fax number\r
+ *\r
+ * @param faxNumber the faxNumber to set\r
+ */\r
+ public void setFaxNumber (final String faxNumber) {\r
+ this.faxNumber = faxNumber;\r
+ }\r
+\r
+ /**\r
+ * Gender of the contact\r
+ *\r
+ * @return the gender\r
+ */\r
+ public char getGender () {\r
+ return this.gender;\r
+ }\r
+\r
+ /**\r
+ * Gender of the contact\r
+ *\r
+ * @param gender the gender to set\r
+ */\r
+ public void setGender (final char gender) {\r
+ this.gender = gender;\r
+ }\r
+\r
+ /**\r
+ * House number\r
+ *\r
+ * @return the houseNumber\r
+ */\r
+ public int getHouseNumber () {\r
+ return this.houseNumber;\r
+ }\r
+\r
+ /**\r
+ * House number\r
+ *\r
+ * @param houseNumber the houseNumber to set\r
+ */\r
+ public void setHouseNumber (final int houseNumber) {\r
+ this.houseNumber = houseNumber;\r
+ }\r
+\r
+ /**\r
+ * Phone number\r
+ *\r
+ * @return the phoneNumber\r
+ */\r
+ public String getPhoneNumber () {\r
+ return this.phoneNumber;\r
+ }\r
+\r
+ /**\r
+ * Phone number\r
+ *\r
+ * @param phoneNumber the phoneNumber to set\r
+ */\r
+ public void setPhoneNumber (final String phoneNumber) {\r
+ this.phoneNumber = phoneNumber;\r
+ }\r
+\r
+ /**\r
+ * Street\r
+ *\r
+ * @return the street\r
+ */\r
+ public String getStreet () {\r
+ return this.street;\r
+ }\r
+\r
+ /**\r
+ * Street\r
+ *\r
+ * @param street the street to set\r
+ */\r
+ public void setStreet (final String street) {\r
+ this.street = street;\r
+ }\r
+\r
+ /**\r
+ * Surname\r
+ *\r
+ * @return the surname\r
+ */\r
+ public String getSurname () {\r
+ return this.surname;\r
+ }\r
+\r
+ /**\r
+ * Surname\r
+ *\r
+ * @param surname the surname to set\r
+ */\r
+ public void setSurname (final String surname) {\r
+ this.surname = surname;\r
+ }\r
+\r
+ /**\r
+ * ZIP code\r
+ *\r
+ * @return the zipCode\r
+ */\r
+ public int getZipCode () {\r
+ return this.zipCode;\r
+ }\r
+\r
+ /**\r
+ * ZIP code\r
+ *\r
+ * @param zipCode the zipCode to set\r
+ */\r
+ public void setZipCode (final int zipCode) {\r
+ this.zipCode = zipCode;\r
+ }\r
+\r
+ /**\r
+ * Checks whether the contact is user's own data\r
+ *\r
+ * @return Own data?\r
+ */\r
+ public boolean isOwnContact () {\r
+ return this.ownContact;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.contact;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface Contact extends FrameworkInterface {\r
+\r
+ /**\r
+ * Enables the flag "own data" which signals that this contact is the user's\r
+ * own data.\r
+ */\r
+ public void enableFlagOwnContact ();\r
+\r
+ /**\r
+ * Checks whether the contact is user's own data\r
+ *\r
+ * @return Own data?\r
+ */\r
+ public boolean isOwnContact ();\r
+\r
+ /**\r
+ * Gender of the contact\r
+ *\r
+ * @return the gender\r
+ */\r
+ public char getGender ();\r
+\r
+ /**\r
+ * Surname\r
+ *\r
+ * @return the surname\r
+ */\r
+ public String getSurname ();\r
+\r
+ /**\r
+ * Family name\r
+ *\r
+ * @return the familyName\r
+ */\r
+ public String getFamilyName ();\r
+\r
+ /**\r
+ * Companyname\r
+ *\r
+ * @return the companyName\r
+ */\r
+ public String getCompanyName ();\r
+\r
+ /**\r
+ * Street\r
+ *\r
+ * @return the street\r
+ */\r
+ public String getStreet ();\r
+\r
+ /**\r
+ * House number\r
+ *\r
+ * @return the houseNumber\r
+ */\r
+ public int getHouseNumber ();\r
+\r
+ /**\r
+ * ZIP code\r
+ *\r
+ * @return the zipCode\r
+ */\r
+ public int getZipCode ();\r
+\r
+ /**\r
+ * City\r
+ *\r
+ * @return the city\r
+ */\r
+ public String getCity ();\r
+\r
+ /**\r
+ * Country code\r
+ *\r
+ * @return the countryCode\r
+ */\r
+ public String getCountryCode ();\r
+\r
+ /**\r
+ * Email address\r
+ *\r
+ * @return the emailAddress\r
+ */\r
+ public String getEmailAddress ();\r
+\r
+ /**\r
+ * Phone number\r
+ *\r
+ * @return the phoneNumber\r
+ */\r
+ public String getPhoneNumber ();\r
+\r
+ /**\r
+ * Fax number\r
+ *\r
+ * @return the faxNumber\r
+ */\r
+ public String getFaxNumber ();\r
+\r
+ /**\r
+ * Cellphone number\r
+ *\r
+ * @return the cellphoneNumber\r
+ */\r
+ public String getCellphoneNumber ();\r
+\r
+ /**\r
+ * Birth day\r
+ *\r
+ * @return the birthday\r
+ */\r
+ public String getBirthday ();\r
+\r
+ /**\r
+ * Comments\r
+ *\r
+ * @return the comment\r
+ */\r
+ public String getComment ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.contact.book;\r
+\r
+import org.mxchange.addressbook.contact.BaseContact;\r
+import org.mxchange.addressbook.contact.Contact;\r
+\r
+/**\r
+ * A contact that can be placed into "contact books"\r
+ *\r
+ * @author Roland Haeder\r
+ * @version 0.0\r
+ * @since 0.0\r
+ */\r
+public class BookContact extends BaseContact implements Contact {\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.contact.user;\r
+\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.contact.book.BookContact;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ * @todo After a Collection has been used in ContactManager, change to BaseContact\r
+ */\r
+public class UserContact extends BookContact implements Contact {\r
+\r
+ /**\r
+ * Creates own contact entry\r
+ *\r
+ * @param gender Gender to be set\r
+ * @param surname Surname to be set\r
+ * @param familyName Family name to be set\r
+ * @todo Add validation of data\r
+ */\r
+ public UserContact (final char gender, final String surname, final String familyName) {\r
+ // Make sure all constructors are called\r
+ this();\r
+\r
+ this.setGender(gender);\r
+ this.setSurname(surname);\r
+ this.setFamilyName(familyName);\r
+ }\r
+\r
+ /**\r
+ * No empty instances can be created of this class\r
+ */\r
+ protected UserContact () {\r
+ super();\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ * A general manager\r
+ *\r
+ * @author Roland Haeder\r
+ * @version 0.0\r
+ * @since 0.0\r
+ */\r
+public class BaseManager extends BaseFrameworkSystem {\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseManager () {\r
+ // Call any other super constructors\r
+ super();\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface Manageable extends FrameworkInterface {\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager.application;\r
+\r
+import org.mxchange.addressbook.application.Application;\r
+import org.mxchange.addressbook.manager.BaseManager;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class ApplicationManager extends BaseManager implements ManageableApplication {\r
+\r
+ /**\r
+ * Getter for application manager\r
+ * @param application An instance of a Application class\r
+ * @return\r
+ */\r
+ public static final ManageableApplication getManager (final Application application) {\r
+ // Get manager\r
+ ManageableApplication manager = new ApplicationManager(application);\r
+\r
+ // Return manager\r
+ return manager;\r
+ }\r
+\r
+ /**\r
+ * Constructor for this manager\r
+ * @param application An instance of an Application class\r
+ */\r
+ private ApplicationManager (final Application application) {\r
+ super();\r
+ \r
+ // Set application instance\r
+ this.setApplication (application);\r
+ }\r
+\r
+ @Override\r
+ public void start () {\r
+ // Bootstrap application\r
+ this.getApplication().doBootstrap();\r
+\r
+ // Run the main loop\r
+ this.getApplication().doMainLoop();\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager.application;\r
+\r
+import org.mxchange.addressbook.manager.Manageable;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface ManageableApplication extends Manageable {\r
+ /**\r
+ * Launches application\r
+ */\r
+ public void start ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager.contact;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.contact.user.UserContact;\r
+import org.mxchange.addressbook.manager.BaseManager;\r
+\r
+/**\r
+ * A manager for contacts\r
+ *\r
+ * @author Roland Haeder\r
+ * @version 0.0\r
+ * @since 0.0\r
+ */\r
+public class ContactManager extends BaseManager implements ManageableContact {\r
+\r
+ /**\r
+ * All contacts\r
+ */\r
+ private final List<Contact> contacts;\r
+\r
+ /**\r
+ * @param maxContacts Maximum allowed contacts\r
+ * @param client Client instance to use\r
+ */\r
+ public ContactManager (final int maxContacts, final Client client) {\r
+ // Always call super constructor first\r
+ super();\r
+\r
+ // Init contacts\r
+ this.contacts = new ArrayList<>(maxContacts);\r
+\r
+ // Debug message\r
+ //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);\r
+\r
+ // Init client\r
+ this.setClient(client);\r
+ }\r
+\r
+ /**\r
+ * Adds given contact to address book\r
+ *\r
+ * @param contact Contact being added\r
+ * @todo Add check for book size\r
+ */\r
+ @Override\r
+ public void addContact (final Contact contact) {\r
+ // Check if contact is found\r
+ if (this.isContactAlreadyAdded(contact)) {\r
+ // Contact already added\r
+ // @todo Do something here\r
+ } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {\r
+ // Own contact already added\r
+ // @todo Do something\r
+ }\r
+\r
+ // Debug message\r
+ /* NOISY-DEBUG: */ this.getLogger().debug("Adding '" + contact.getSurname() + "' '" + contact.getFamilyName() + "' at pos '" + this.size () + "' ...");\r
+\r
+ // Add contact\r
+ this.contacts.add(contact);\r
+ }\r
+\r
+ /**\r
+ * Let the user add a new other address\r
+ */\r
+ @Override\r
+ public void addOtherAddress () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
+ /**\r
+ * Let the user change other address\r
+ */\r
+ @Override\r
+ public void changeOtherAddress () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
+ /**\r
+ * Allows the user to change his/her own data\r
+ */\r
+ @Override\r
+ public void changeOwnData () {\r
+ /*\r
+ * First check if the user has registered own contact, before that \r
+ * nothing can be changed.\r
+ */\r
+ if (!this.isOwnContactAdded()) {\r
+ // Not added\r
+ this.getClient().displayMessage("Sie haben noch nicht Ihre Daten eingegeben.");\r
+\r
+ // Skip any below code\r
+ return;\r
+ }\r
+\r
+ // Instance\r
+ Contact contact = this.getOwnContact();\r
+\r
+ // It must be found\r
+ assert(contact instanceof Contact);\r
+\r
+ // @TODO Unfinished\r
+ throw new UnsupportedOperationException("Method is not finished.");\r
+ }\r
+\r
+ /**\r
+ * Let the user delete other address\r
+ */\r
+ @Override\r
+ public void deleteOtherAddress () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
+ /**\r
+ * Asks user for own data\r
+ */\r
+ @Override\r
+ public void enterOwnData () {\r
+ // First ask for gender\r
+ char gender = this.enterOwnGender();\r
+\r
+ // 2nd for surname\r
+ String surname = this.enterOwnSurname();\r
+ \r
+ // And 3rd for family name\r
+ String familyName = this.enterOwnFamilyName();\r
+\r
+ // Construct UserContact instance\r
+ Contact contact = new UserContact(gender, surname, familyName);\r
+\r
+ // Mark contact as own\r
+ contact.enableFlagOwnContact();\r
+\r
+ // Add it to contact "book"\r
+ this.addContact(contact);\r
+ }\r
+\r
+ /**\r
+ * Getter for size\r
+ *\r
+ * @return size of contact "book"\r
+ */\r
+ @Override\r
+ public int size () {\r
+ return this.contacts.size();\r
+ }\r
+\r
+ /**\r
+ * Asks the user for family name\r
+ * @return Family name of the user\r
+ */\r
+ private String enterOwnFamilyName () {\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ");\r
+ }\r
+\r
+ /**\r
+ * Asks the user for gender, until a valid has been entered\r
+ * @return Gender of the user\r
+ */\r
+ private char enterOwnGender () {\r
+ return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");\r
+ }\r
+\r
+ /**\r
+ * Asks the user for surname\r
+ * @return Surname of the user\r
+ */\r
+ private String enterOwnSurname () {\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ");\r
+ }\r
+\r
+ /**\r
+ * "Getter" for own contact instance or null if not found\r
+ *\r
+ * @return Contact instance or null\r
+ */\r
+ private Contact getOwnContact () {\r
+ // Now get it back from address book, first get an iterator\r
+ Iterator<Contact> iterator = this.contacts.iterator();\r
+\r
+ // Init instance\r
+ Contact contact = null;\r
+\r
+ // Search all contact\r
+ while (iterator.hasNext()) {\r
+ // Get next instance\r
+ Contact next = iterator.next();\r
+\r
+ // Is this own contact?\r
+ if (next.isOwnContact()) {\r
+ // Found it\r
+ contact = next;\r
+ break;\r
+ \r
+ }\r
+ }\r
+\r
+ // Return instance or null\r
+ return contact;\r
+ }\r
+\r
+ /**\r
+ * Checks whether given contact was found in "address book"\r
+ *\r
+ * @param checkContact Contact to be checked\r
+ * @return TRUE if found, FALSE if not found\r
+ */\r
+ private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException {\r
+ // Default is not found\r
+ boolean isFound = false;\r
+\r
+ // Debug message\r
+ //* NOISY-DEBUG: */ this.getLogger().debug("Checking '" + this.contacts.length + "' entries...");\r
+\r
+ // Now get it back from address book, first get an iterator\r
+ Iterator<Contact> iterator = this.contacts.iterator();\r
+\r
+ // Check entries\r
+ while (iterator.hasNext()) {\r
+ // Get next entry\r
+ Contact contact = iterator.next();\r
+\r
+ // Debug message\r
+ //* NOISY-DEBUG: */ this.getLogger().debug("contact=" + contact + ",checkContent=" + checkContact);\r
+\r
+ // Is it valid?\r
+ if ((contact instanceof Contact) && ((contact.equals(checkContact)))) {\r
+ // Found matching entry\r
+ isFound = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ // Return result\r
+ return isFound;\r
+ }\r
+\r
+ /**\r
+ * Checks whether own contact is already added by checking all entries for isOwnContact flag\r
+ * @return Whether own contact is already added\r
+ */\r
+ private boolean isOwnContactAdded () {\r
+ // Default is not added\r
+ boolean isAdded = false;\r
+\r
+ // Now get it back from address book, first get an iterator\r
+ Iterator<Contact> iterator = this.contacts.iterator();\r
+\r
+ // Check entries\r
+ while (iterator.hasNext()) {\r
+ // Get next entry\r
+ Contact contact = iterator.next();\r
+\r
+ // Is it valid?\r
+ if (contact instanceof Contact) {\r
+ // Get flag\r
+ isAdded = contact.isOwnContact();\r
+\r
+ // Is this own contact?\r
+ if (isAdded) {\r
+ // Then abort loop\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ // Return result\r
+ return isAdded;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.manager.contact;\r
+\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.manager.Manageable;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface ManageableContact extends Manageable {\r
+ /**\r
+ * Adds given contact to address book\r
+ *\r
+ * @param contact Contact being added\r
+ * @todo Add check for book size\r
+ */\r
+ public void addContact (final Contact contact);\r
+\r
+ /**\r
+ * Let the user add a new other address\r
+ */\r
+ public void addOtherAddress ();\r
+\r
+ /**\r
+ * Let the user change other address\r
+ */\r
+ public void changeOtherAddress ();\r
+\r
+ /**\r
+ * Let the user change own data\r
+ */\r
+ public void changeOwnData ();\r
+\r
+ /**\r
+ * Let the user delete other address\r
+ */\r
+ public void deleteOtherAddress ();\r
+\r
+ /**\r
+ * Asks user for own data\r
+ */\r
+ public void enterOwnData ();\r
+\r
+ /**\r
+ * Getter for size\r
+ *\r
+ * @return size of contact "book"\r
+ */\r
+ public int size ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu;\r
+\r
+import java.util.List;\r
+import org.apache.logging.log4j.Logger;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ * Utility class for menu structure\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class AddressbookMenu extends BaseFrameworkSystem {\r
+ /**\r
+ * Copies entries for given type into the menu list\r
+ *\r
+ * @param menuList Menu list for later showing\r
+ * @param menuType Type of menu\r
+ * @param client Client instance to call back\r
+ */\r
+ public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {\r
+ // Get logger\r
+ Logger log = new AddressbookMenu().getLogger();\r
+\r
+ // Get list size\r
+ int size = menuList.size();\r
+\r
+ // Debug message\r
+ log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ...");\r
+\r
+ // Depends on type\r
+ switch (menuType) {\r
+ case "main": // Main menu\r
+ // Enter own data\r
+ menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen"));\r
+\r
+ // Change own data\r
+ menuList.add(client.getMenuItem('2', "Eigene Adresse ändern"));\r
+\r
+ // Add new addess\r
+ menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen"));\r
+\r
+ // Change other address\r
+ menuList.add(client.getMenuItem('4', "Adresse ändern"));\r
+\r
+ // Delete other address\r
+ menuList.add(client.getMenuItem('5', "Adresse löschen"));\r
+\r
+ // Always last line: Exit program\r
+ menuList.add(client.getMenuItem('0', "Programm verlassen"));\r
+ break;\r
+\r
+ default: // Not supported\r
+ log.error("Menu type '" + menuType + "' ont supported");\r
+ System.exit(1);\r
+ }\r
+\r
+ // Size must have changed to more entries than before\r
+ assert(menuList.size() > size);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu;\r
+\r
+import java.util.Iterator;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ * @todo find better name\r
+ */\r
+public interface Menu {\r
+\r
+ /**\r
+ * "Getter" for an iterator on all menu items of the current menu\r
+ * @return Iterator on all menu items\r
+ */\r
+ public Iterator<SelectableMenuItem> getMenuItemsIterator ();\r
+\r
+ /**\r
+ * Shows this menu\r
+ * @param client Client instance\r
+ */\r
+ public void show (final Client client);\r
+\r
+ /**\r
+ * Size of all menu items\r
+ * @return \r
+ */\r
+ public int getMenuItemsCount ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu;\r
+\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+import org.apache.logging.log4j.Logger;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class MenuTools extends BaseFrameworkSystem {\r
+\r
+ /**\r
+ * Gets an array with all available access keys back from given menu map.\r
+ * This can later be handle to the client's enterChar() method.\r
+ *\r
+ * @param menus A Map with all menus and their entries\r
+ * @param menuType Menu type\r
+ * @return An array with available access chars\r
+ */\r
+ public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {\r
+ // Get logger\r
+ Logger logger = new MenuTools().getLogger();\r
+\r
+ // First search for the proper menu class\r
+ Menu menu = menus.get(menuType);\r
+\r
+ // Is it there?\r
+ if (!(menu instanceof Menu)) {\r
+ // Not found\r
+ // @todo Rewrite to exception\r
+ logger.error("Menu '" + menuType + "' not found.");\r
+ System.exit(1);\r
+ }\r
+\r
+ // Get iterator\r
+ Iterator<SelectableMenuItem> iterator = menu.getMenuItemsIterator();\r
+\r
+ // Init return array and counter 'i'\r
+ char[] accessKeys = new char[menu.getMenuItemsCount()];\r
+ int i = 0;\r
+\r
+ // Now "walk" through all menu entries\r
+ while (iterator.hasNext()) {\r
+ // Get item\r
+ SelectableMenuItem item = iterator.next();\r
+ //* NOISY-DEBUG: */ logger.debug("item=" + item);\r
+\r
+ // Get access key from item and add it to the array\r
+ accessKeys[i] = item.getAccessKey();\r
+ //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]);\r
+\r
+ // Increment counter\r
+ i++;\r
+ }\r
+\r
+ // Return finished array\r
+ return accessKeys;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu.console;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.AddressbookMenu;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseMenu extends BaseFrameworkSystem {\r
+ /**\r
+ * Menu list\r
+ */\r
+ private List<SelectableMenuItem> menuList;\r
+\r
+ /**\r
+ * No instance from this object\r
+ */\r
+ protected BaseMenu () {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * "Getter" for an iterator of this menu's items\r
+ *\r
+ * @return An iterator of all menu items\r
+ */\r
+ public Iterator<SelectableMenuItem> getMenuItemsIterator () {\r
+ return this.menuList.iterator();\r
+ }\r
+\r
+ /**\r
+ * Size of menu items\r
+ * @return Count of menu items\r
+ */\r
+ public int getMenuItemsCount () {\r
+ return this.menuList.size();\r
+ }\r
+\r
+ /**\r
+ * Shows this menu\r
+ * \r
+ * @param client Client instance to call back\r
+ */\r
+ public void show (final Client client) {\r
+ // Get values\r
+ Iterator<SelectableMenuItem> iterator = this.menuList.iterator();\r
+\r
+ // Debug message\r
+ this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");\r
+\r
+ // Output all menus\r
+ while (iterator.hasNext()) {\r
+ // Get item\r
+ SelectableMenuItem item = iterator.next();\r
+\r
+ // Show this item\r
+ item.show(client);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Initializes menu\r
+ * @param menuType Menu type to initialize\r
+ * @param client CLient to call back\r
+ */\r
+ protected void initMenu (final String menuType, final Client client) {\r
+ // Init menu list\r
+ this.menuList = new ArrayList<>(5);\r
+ \r
+ // Add all items\r
+ AddressbookMenu.addItemsToList(this.menuList, menuType, client);\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu.console;\r
+\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.Menu;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class ConsoleMenu extends BaseMenu implements Menu {\r
+ /**\r
+ * Constructor for this menu\r
+ * @param menuType Menu type to initialize\r
+ * @param client CLient to call back\r
+ */\r
+ public ConsoleMenu (final String menuType, final Client client) {\r
+ this.initMenu(menuType, client);\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu.item;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseMenuItem extends BaseFrameworkSystem {\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu.item;\r
+\r
+import org.mxchange.addressbook.client.Client;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface SelectableMenuItem {\r
+\r
+ /**\r
+ * Shows this menu item\r
+ * @param client Client instance\r
+ */\r
+ public void show (final Client client);\r
+\r
+ /**\r
+ * Access key\r
+ * @return the accessKey\r
+ */\r
+ public char getAccessKey ();\r
+\r
+ /**\r
+ * Text to user\r
+ * @return the text\r
+ */\r
+ public String getText ();\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu.item.console;\r
+\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.item.BaseMenuItem;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem {\r
+ /**\r
+ * Access key\r
+ */\r
+ private char accessKey;\r
+\r
+ /**\r
+ * Text to user\r
+ */\r
+ private String text;\r
+\r
+ /**\r
+ * Constructor for building a console menu with access key and text\r
+ * \r
+ * @param accessKey Access key for this menu entry\r
+ * @param text Text to show to user\r
+ */\r
+ public ConsoleMenuItem (final char accessKey, final String text) {\r
+ this.accessKey = accessKey;\r
+ this.text = text;\r
+ }\r
+\r
+ /**\r
+ * Access key\r
+ * @return the accessKey\r
+ */\r
+ @Override\r
+ public char getAccessKey () {\r
+ return this.accessKey;\r
+ }\r
+\r
+ /**\r
+ * Text to user\r
+ * @return the text\r
+ */\r
+ @Override\r
+ public String getText () {\r
+ return this.text;\r
+ }\r
+\r
+ @Override\r
+ public void show (final Client client) {\r
+ // Call-back client over menu\r
+ client.showEntry(this);\r
+ }\r
+\r
+ /**\r
+ * Text to user\r
+ * @param text the text to set\r
+ */\r
+ private void setText (String text) {\r
+ this.text = text;\r
+ }\r
+\r
+ /**\r
+ * Access key\r
+ * @param accessKey the accessKey to set\r
+ */\r
+ private void setAccessKey (char accessKey) {\r
+ this.accessKey = accessKey;\r
+ }\r
+ \r
+}\r