--- /dev/null
+/nbproject/\r
+/manifest.mf\r
+/build/\r
+/data/*.*\r
+/dist/\r
+++ /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="TRACE"/>
- </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
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class BadTokenException extends Exception {\r
-\r
- public BadTokenException (final String str) {\r
- super(str);\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;\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.ManageableContact;\r
-\r
-/**\r
- * General class\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class BaseFrameworkSystem implements FrameworkInterface {\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
- * Name of used database table, handled over to backend\r
- */\r
- private String tableName;\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
- * \r
- * @return the application\r
- */\r
- @Override\r
- public final Application getApplication () {\r
- return this.application;\r
- }\r
-\r
- /**\r
- * Client instance\r
- * \r
- * @return the client\r
- */\r
- @Override\r
- public final Client getClient () {\r
- return this.client;\r
- }\r
-\r
- /**\r
- * Contact manager instance\r
- * @return the contactManager\r
- */\r
- @Override\r
- public final ManageableContact getContactManager () {\r
- return this.contactManager;\r
- }\r
-\r
- /**\r
- * Contact manager instance\r
- * @param contactManager the contactManager to set\r
- */\r
- protected final void setContactManager (final ManageableContact contactManager) {\r
- this.contactManager = contactManager;\r
- }\r
-\r
- /**\r
- * Client instance\r
- * @param client the client to set\r
- */\r
- protected final void setClient (final Client client) {\r
- this.client = client;\r
- }\r
-\r
- /**\r
- * Application instance\r
- *\r
- * @param application the application to set\r
- */\r
- protected final void setApplication(final Application application) {\r
- this.application = application;\r
- }\r
-\r
- /**\r
- * Getter for logger\r
- *\r
- * @return Logger\r
- */\r
- protected final Logger getLogger () {\r
- return this.LOG;\r
- }\r
-\r
- /**\r
- * Name of used database table, handled over to backend\r
- * \r
- * @return the tableName\r
- */\r
- protected final String getTableName () {\r
- return this.tableName;\r
- }\r
-\r
- /**\r
- * Name of used database table, handled over to backend\r
- * \r
- * @param tableName the tableName to set\r
- */\r
- protected final void setTableName (final String tableName) {\r
- this.tableName = tableName;\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.application.Application;\r
-import org.mxchange.addressbook.client.Client;\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
- /**\r
- * Client instance\r
- * \r
- * @return the client\r
- */\r
- public Client getClient ();\r
-\r
- /**\r
- * Application instance\r
- * \r
- * @return the application\r
- */\r
- public Application getApplication ();\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;\r
-\r
-/**\r
- * This exception is thrown when the user made a valid choice but it was not\r
- * handled by the program.\r
- * \r
- * @author Roland Haeder\r
- */\r
-public class UnhandledUserChoiceException extends Exception {\r
-\r
- public UnhandledUserChoiceException (final String message) {\r
- super(message);\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 java.text.MessageFormat;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\r
-import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.client.console.ConsoleClient;\r
-import org.mxchange.addressbook.client.gui.SwingClient;\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 = "Adressbuch";\r
-\r
- /**\r
- * Application version\r
- */\r
- public static final String APP_VERSION = "0.0";\r
-\r
- /**\r
- * Console client is enabled by default\r
- */\r
- private boolean consoleClient = true;\r
-\r
- /**\r
- * GUI client is disabled by default\r
- */\r
- private boolean guiClient = false;\r
-\r
- /**\r
- * Getter for printable application name\r
- * \r
- * @return A printable name\r
- */\r
- public static String printableTitle () {\r
- return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);\r
- }\r
-\r
- /**\r
- * Bootstraps application\r
- */\r
- @Override\r
- public void doBootstrap () {\r
- this.getLogger().debug("Initializing application ...");\r
-\r
- // Init client variable\r
- Client client = null;\r
-\r
- // Is console or Swing choosen?\r
- if (this.isConsole()) {\r
- // Debug message\r
- this.getLogger().debug("Initializing console client ...");\r
-\r
- // Init console client instance\r
- client = new ConsoleClient(this);\r
- } else if (this.isGui()) {\r
- // Debug message\r
- this.getLogger().debug("Initializing GUI (Swing) client ...");\r
-\r
- // Init console instance\r
- client = new SwingClient(this);\r
- } else {\r
- // Not client choosen\r
- this.getLogger().error("No client choosen. Cannot launch.");\r
- System.exit(1);\r
- }\r
-\r
- // Init client\r
- client.initClient();\r
-\r
- // Set 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().isRunning()) {\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().doUserMenuChoice();\r
- } catch (final UnhandledUserChoiceException 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
- * Enables console client by setting propper flag\r
- */\r
- private void enableConsoleClient () {\r
- this.getLogger().debug("Enabling console client (may become optional client) ...");\r
- this.consoleClient = true;\r
- this.guiClient = false;\r
- }\r
-\r
- /**\r
- * Enables GUI client by setting propper flag\r
- */\r
- private void enableGuiClient () {\r
- this.getLogger().debug("Enabling GUI client (may become new default client) ...");\r
- this.consoleClient = false;\r
- this.guiClient = true;\r
- }\r
-\r
- /**\r
- * Checks whether the client shoule be console client should be launched by\r
- * checking if -console is set.\r
- * \r
- * @return Whether console client should be taken\r
- */\r
- private boolean isConsole () {\r
- return this.consoleClient;\r
- }\r
-\r
- /**\r
- * Checks whether the client shoule be GUI client should be launched by\r
- * checking if -gui is set.\r
- * \r
- * @return Whether GUI client should be taken\r
- */\r
- private boolean isGui () {\r
- return this.guiClient;\r
- }\r
-\r
- /**\r
- * Parses all given arguments\r
- *\r
- * @param args Arguments from program launch\r
- */\r
- private void parseArguments (final String[] args) {\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));\r
- \r
- for (final String arg : args) {\r
- // Switch on it\r
- switch (arg) {\r
- case "-console":\r
- enableConsoleClient();\r
- break;\r
- \r
- case "-gui":\r
- enableGuiClient();\r
- break;\r
-}\r
- }\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
- * @param args Arguments handled to program\r
- */\r
- private void start (final String args[]) {\r
- this.getLogger().info("Program is started.");\r
-\r
- // Parse arguments\r
- this.parseArguments(args);\r
-\r
- // Launch application\r
- ApplicationManager.getManager(this).start();\r
-\r
- // Good bye, but this should not be reached ...\r
- this.getLogger().warn("Unusual exit reached.");\r
- this.doShutdown();\r
- }\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(args);\r
- }\r
-\r
- /**\r
- * Shuts down the application.\r
- */\r
- @Override\r
- public void doShutdown () {\r
- // Shutdown client\r
- this.getClient().doShutdown();\r
-\r
- this.getLogger().info("End of program (last line)");\r
- System.exit(0);\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
- /**\r
- * Shutdown the application\r
- */\r
- public void doShutdown ();\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 java.util.HashMap;\r
-import java.util.Map;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.manager.contact.ContactManager;\r
-import org.mxchange.addressbook.manager.contact.ManageableContact;\r
-import org.mxchange.addressbook.menu.Menu;\r
-\r
-/**\r
- * A general client\r
- *\r
- * @author Roland Haeder\r
- */\r
-public abstract 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
- * Menu system\r
- */\r
- private final Map<String, Menu> menus;\r
-\r
- /**\r
- * No instances can be created of this class\r
- */\r
- protected BaseClient () {\r
- super();\r
-\r
- // Init menu map\r
- this.menus = new HashMap<>(10);\r
- }\r
-\r
- /**\r
- * Shutdown method for all clients\r
- */\r
- public void doShutdown () {\r
- // Disable client\r
- this.disableIsRunning();\r
-\r
- // Shuts down contact manager\r
- this.getContactManager().doShutdown();\r
- }\r
-\r
- /**\r
- * Enables the client\r
- */\r
- public void enableIsRunning () {\r
- this.isRunning = true;\r
- }\r
-\r
- /**\r
- * Current menu choice\r
- * \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
- /**\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
- public Menu getMenu (final String menuType) {\r
- // Default is not found\r
- Menu menu = null;\r
- \r
- // Check array\r
- if (this.getMenus().containsKey(menuType)) {\r
- // Found!\r
- menu = this.getMenus().get(menuType);\r
- }\r
- \r
- // Return it\r
- return menu;\r
- }\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 isRunning () {\r
- // In console client, 0 may have been used\r
- return this.isRunning;\r
- }\r
-\r
- /**\r
- * Disables running state, so the main loop can abort.\r
- */\r
- protected void disableIsRunning () {\r
- this.isRunning = false;\r
- }\r
-\r
- /**\r
- * Fills menu map with swing menus\r
- */\r
- protected abstract void fillMenuMap ();\r
-\r
- /**\r
- * Getter for menus map\r
- * @return Map of all menus\r
- */\r
- protected final Map<String, Menu> getMenus () {\r
- return this.menus;\r
- }\r
-\r
- /**\r
- * Initializes contact manager\r
- */\r
- protected void initContactManager () {\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) this);\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
- /**\r
- * Shows given menu\r
- *\r
- * @param menuType Given menu to show\r
- */\r
- protected 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((Client) 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.client;\r
-\r
-import org.mxchange.addressbook.FrameworkInterface;\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
-\r
-/**\r
- * An interface for application clients\r
- * \r
- * @author Roland Haeder\r
- */\r
-public interface Client extends FrameworkInterface {\r
-\r
- /**\r
- * Displays a "box" for the address\r
- *\r
- * @param contact Contact to show address from\r
- */\r
- public void displayAddressBox (final Contact contact);\r
-\r
- /**\r
- * Shuts down the client and therefore whole application\r
- */\r
- public void doShutdown ();\r
-\r
- /**\r
- * Displays a message to the user\r
- *\r
- * @param message Message to show to the user\r
- */\r
- public void outputMessage (final String message);\r
-\r
- /**\r
- * Displays a "box" for the name\r
- *\r
- * @param contact Contact to show name from\r
- */\r
- public void displayNameBox (final Contact contact);\r
-\r
- /**\r
- * Displays a "box" for other data\r
- *\r
- * @param contact Contact to show other data from\r
- */\r
- public void displayOtherDataBox (final Contact contact);\r
-\r
- /**\r
- * Let the user choose what to change on the address: [n]ame, [a]ddress,\r
- * [o]ther\r
- * \r
- * @param contact Contact instance to let the user change data\r
- * @throws UnhandledUserChoiceException If choice is not supported\r
- */\r
- public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException;\r
-\r
- /**\r
- * Asks the user for a choice and proceeds accordingly\r
- * \r
- * @throws UnhandledUserChoiceException If choice is not supported\r
- */\r
- public void doUserMenuChoice () throws UnhandledUserChoiceException ;\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
- * \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. An empty\r
- * string should be generally not allowed, but might be okay for e.g.\r
- * company name.\r
- * \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
- * @param allowEmpty Whether empty strings are allowed\r
- * @return Entered string by user or null if empty string is allowed\r
- */\r
- public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty);\r
-\r
- /**\r
- * Reads an integer (int) from the user\r
- * \r
- * @param minimum Minimum allowed number\r
- * @param maximum Maximum allowed number\r
- * @param message Message to user\r
- * @return Entered string by user or null if empty string is allowed\r
- */\r
- public int enterInt (final int minimum, final int maximum, final String message);\r
-\r
- /**\r
- * Setter for current menu choice\r
- * \r
- * @param currentMenu Current menu choice\r
- */\r
- public void setCurrentMenu (final String currentMenu);\r
-\r
- /**\r
- * Some "Getter" for menu item\r
- * \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 client is still active by checking some\r
- * conditions\r
- * \r
- * @return Whether the client is still active\r
- */\r
- public boolean isRunning();\r
-\r
- /**\r
- * Shows given menu entry in client\r
- * \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
- /**\r
- * Inizializes this client\r
- */\r
- public void initClient ();\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.text.MessageFormat;\r
-import java.util.Arrays;\r
-import java.util.Scanner;\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\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.contact.Contact;\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
- * 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 scanner instance\r
- this.scanner = new Scanner(System.in);\r
- }\r
-\r
- /**\r
- * Displays a textual address "box" of given contact\r
- *\r
- * @param contact Contact to show address for\r
- * @todo Use mask\r
- */\r
- @Override\r
- public void displayAddressBox (final Contact contact) {\r
- // Simple display ...\r
- // @todo Use mask\r
- this.outputMessage("Strasse, PLZ Ort, Land: " + contact.getStreet() + "\n" + contact.getZipCode() + " " + contact.getCity() + "\n" + contact.getCountryCode());\r
- }\r
-\r
- /**\r
- * Displays a textual name "box" of given contact\r
- *\r
- * @param contact Contact to show name for\r
- */\r
- @Override\r
- public void displayNameBox (final Contact contact) {\r
- // Get translated gender as the user may want to see "Mr.", "Mrs."\r
- String gender = contact.getTranslatedGender();\r
-\r
- // Get company name\r
- String companyName = contact.getCompanyName();\r
-\r
- // If it is empty/null, then assume private contact\r
- if ((companyName == null) || (companyName.isEmpty())) {\r
- // Now put all together: gender, surname, family name\r
- // @todo Use mask\r
- this.outputMessage("Anrede, Vorname, Name: " + gender + " " + contact.getSurname() + " " + contact.getFamilyName());\r
- } else {\r
- // Company contact\r
- this.outputMessage("Firma: " + companyName + "\nAnsprechpartner: " + gender + " " + contact.getSurname() + " " + contact.getFamilyName());\r
- }\r
- }\r
-\r
- /**\r
- * Displays a textual other data "box" of given contact\r
- *\r
- * @param contact Contact to show other data for\r
- */\r
- @Override\r
- public void displayOtherDataBox (final Contact contact) {\r
- // Cellphone and such ...\r
- this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));\r
- }\r
-\r
- /**\r
- * Shutdown this client\r
- */\r
- @Override\r
- public void doShutdown () {\r
- // Parent call\r
- super.doShutdown();\r
-\r
- // @TODO Add other shutdown stuff\r
- }\r
-\r
- @Override\r
- public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
- // Get all access keys from menu\r
- char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());\r
-\r
- // Output textural message and ask for a char as input\r
- char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
-\r
- // @TODO Rewrite this ugly switch() block\r
- switch (choice) {\r
- case '1': // Enter/add own data\r
- this.getContactManager().doEnterOwnData();\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': // List contacts\r
- this.getContactManager().listContacts();\r
- break;\r
- \r
- case '5': // Search addresses\r
- this.getContactManager().searchContacts();\r
- break;\r
-\r
- case '6': // Change other addess\r
- this.getContactManager().changeOtherAddress();\r
- break;\r
- \r
- case '7': // Delete other address\r
- this.getContactManager().deleteOtherAddress();\r
- break;\r
-\r
- case '0': // Program exit\r
- this.getApplication().doShutdown();\r
- break;\r
- \r
- default:\r
- // @TODO throw own exception\r
- throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));\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 an integer (int) with a textural message from the user\r
- * \r
- * @param minimum Minimum allowed number\r
- * @param maximum Maximum allowed number\r
- * @param message Messager to display in console\r
- * @return \r
- */\r
- @Override\r
- public int enterInt (final int minimum, final int maximum, final String message) {\r
- // Minimum should not be below zero\r
- assert(minimum >= 0);\r
- assert(maximum > minimum);\r
-\r
- // Init input\r
- int input = -1;\r
-\r
- while ((input < minimum) || (input > maximum)) {\r
- // Output message\r
- System.out.print(message);\r
-\r
- // Read integer from user\r
- input = this.readInt();\r
- }\r
-\r
- // Return it\r
- return input;\r
- }\r
-\r
- /**\r
- * Reads a string of minimum and maximum length from the user\r
- * \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
- * @param allowEmpty Whether to allow empty string\r
- * @return Entered string by user or null for empty strings\r
- */\r
- @Override\r
- public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
- // Check on length, e.g. country codes are excactly 2 chars long\r
- assert(maxLength >= minLength);\r
-\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) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (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
- * Inizializes this client\r
- */\r
- @Override\r
- public void initClient () {\r
- // Init contact manager here\r
- this.initContactManager();\r
- \r
- // Fill menu map\r
- this.fillMenuMap();\r
- }\r
-\r
- /**\r
- * Displays textural message to the user\r
- * @param message\r
- */\r
- @Override\r
- public void outputMessage (final String message) {\r
- System.out.println(message);\r
- }\r
-\r
- /**\r
- * Shows textural menu on console\r
- */\r
- @Override\r
- public void showCurrentMenu () {\r
- this.showMenu(this.getCurrentMenu());\r
- }\r
-\r
- /**\r
- * Shows given menu entry to user\r
- * \r
- * @param item Menu entry\r
- */\r
- @Override\r
- public void showEntry (final SelectableMenuItem item) {\r
- // Access key then text\r
- this.outputMessage("[" + item.getAccessKey() + "] " + item.getText());\r
- }\r
-\r
- /**\r
- * Shows a textural message to the user\r
- */\r
- @Override\r
- public void showWelcome () {\r
- this.outputMessage("Welcome to " + AddressbookApplication.printableTitle());\r
- this.outputMessage("");\r
- this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
- \r
- // Debug message\r
- this.getLogger().debug("Intro shown to user");\r
- }\r
-\r
- @Override\r
- public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
- // Ask the user for editing [name], [a]ddress or [other] data\r
- 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) ");\r
- \r
- // @TODO Get rid of this ugly switch block, too\r
- switch (choice) {\r
- case 'n': // Name data\r
- this.getContactManager().doChangeNameData(contact, this);\r
- break;\r
- \r
- case 'a': // Address data\r
- this.getContactManager().doChangeAddressData(contact, this);\r
- break;\r
- \r
- case 'o': // Other data\r
- this.getContactManager().doChangeOtherData(contact, this);\r
- break;\r
- \r
- case 'x': // Exit this menu\r
- // Ignored as it should go back\r
- break;\r
- \r
- default:\r
- // @TODO throw own exception\r
- throw new UnhandledUserChoiceException("Choice '" + choice + "' not handled yet.");\r
- }\r
- }\r
-\r
- /**\r
- * Reads one character\r
- * \r
- * @return A single character\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 an integer (int) from user\r
- * \r
- * @return An integer number\r
- */\r
- private int readInt () {\r
- // First read a string\r
- String input = this.readString();\r
-\r
- // Init number with invalid value\r
- int num = -1;\r
-\r
- // Parse number, this can be risky\r
- try {\r
- num = Integer.parseInt(input);\r
- } catch (final NumberFormatException e) {\r
- this.outputMessage("Bitte geben Sie nur Zahlen ein!");\r
- this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage()));\r
- }\r
-\r
- // Return read number\r
- return num;\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
- * Fills menu map with menu entries\r
- */\r
- @Override\r
- protected final void fillMenuMap () {\r
- // Initialize first (main) menu\r
- Menu menu = new ConsoleMenu("main", this);\r
- \r
- // Add it\r
- this.getMenus().put("main", menu);\r
- }\r
-}\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
- <NonVisualComponents>
- <Container class="javax.swing.JDialog" name="enterDownDataDialog">
- <Properties>
- <Property name="alwaysOnTop" type="boolean" value="true"/>
- </Properties>
- <AccessibilityProperties>
- <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- </AccessibilityProperties>
-
- <Layout>
- <DimensionLayout dim="0">
- <Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
- </Group>
- </DimensionLayout>
- <DimensionLayout dim="1">
- <Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
- </Group>
- </DimensionLayout>
- </Layout>
- </Container>
- <Menu class="javax.swing.JMenuBar" name="menuBar">
- <SubComponents>
- <Menu class="javax.swing.JMenu" name="mainMenu">
- <Properties>
- <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- <Property name="focusable" type="boolean" value="false"/>
- <Property name="name" type="java.lang.String" value="" noResource="true"/>
- </Properties>
- <SubComponents>
- <MenuItem class="javax.swing.JMenuItem" name="exitProgram">
- <Properties>
- <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
- <KeyStroke key="Alt+X"/>
- </Property>
- <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.exitProgram.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.exitProgram.toolTipText" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- </Properties>
- <Events>
- <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exitProgramActionPerformed"/>
- </Events>
- </MenuItem>
- </SubComponents>
- </Menu>
- <Menu class="javax.swing.JMenu" name="addressbookMenu">
- <Properties>
- <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addressbookMenu.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- </Properties>
- <SubComponents>
- <MenuItem class="javax.swing.JMenuItem" name="addOwnData">
- <Properties>
- <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addOwn.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addOwnData.toolTipText" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- <Property name="enabled" type="boolean" value="false"/>
- <Property name="name" type="java.lang.String" value="addOwn" noResource="true"/>
- </Properties>
- <AccessibilityProperties>
- <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addOwnData.AccessibleContext.accessibleName" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
- <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
- </Property>
- </AccessibilityProperties>
- <Events>
- <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addOwnDataActionPerformed"/>
- </Events>
- </MenuItem>
- </SubComponents>
- </Menu>
- </SubComponents>
- </Menu>
- </NonVisualComponents>
- <Properties>
- <Property name="defaultCloseOperation" type="int" value="0"/>
- <Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
- <Connection code="AddressbookApplication.printableTitle()" type="code"/>
- </Property>
- <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
- <Color id="Standardcursor"/>
- </Property>
- <Property name="name" type="java.lang.String" value="main" noResource="true"/>
- </Properties>
- <SyntheticProperties>
- <SyntheticProperty name="menuBar" type="java.lang.String" value="menuBar"/>
- <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
- <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
- </SyntheticProperties>
- <AuxValues>
- <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
- <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
- <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
- <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
- <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
- <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
- <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
- <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
- <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
- </AuxValues>
-
- <Layout>
- <DimensionLayout dim="0">
- <Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
- </Group>
- </DimensionLayout>
- <DimensionLayout dim="1">
- <Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="279" max="32767" attributes="0"/>
- </Group>
- </DimensionLayout>
- </Layout>
-</Form>
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.client.gui;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.mxchange.addressbook.application.AddressbookApplication;
-import org.mxchange.addressbook.application.Application;
-import org.mxchange.addressbook.client.Client;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
-
-/**
- *
- * @author Roland Haeder
- */
-public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame {
- /**
- * Class' logger
- */
- private final Logger LOG;
-
- /**
- * Client instance
- */
- private final Client client;
-
- /**
- * Initialize object
- */
- {
- LOG = LogManager.getLogger(this);
- }
-
- /**
- * Creates an instance of this frame with a client instance
- * @param client
- */
- public AddressbookFrame (final Client client) {
- // Debug line
- this.getLogger().debug("Initializing Swing frame ...");
-
- // Init components
- initComponents();
-
- // Set client here
- this.client = client;
- }
-
- @Override
- public Application getApplication () {
- throw new UnsupportedOperationException("Not implemented.");
- }
-
- @Override
- public final Client getClient () {
- return this.client;
- }
-
- @Override
- public ManageableContact getContactManager () {
- throw new UnsupportedOperationException("Not implemented.");
- }
-
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings ("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
-
- enterDownDataDialog = new javax.swing.JDialog();
- menuBar = new javax.swing.JMenuBar();
- mainMenu = new javax.swing.JMenu();
- exitProgram = new javax.swing.JMenuItem();
- addressbookMenu = new javax.swing.JMenu();
- addOwnData = new javax.swing.JMenuItem();
-
- enterDownDataDialog.setAlwaysOnTop(true);
-
- javax.swing.GroupLayout enterDownDataDialogLayout = new javax.swing.GroupLayout(enterDownDataDialog.getContentPane());
- enterDownDataDialog.getContentPane().setLayout(enterDownDataDialogLayout);
- enterDownDataDialogLayout.setHorizontalGroup(
- enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
- enterDownDataDialogLayout.setVerticalGroup(
- enterDownDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
- );
-
- java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
- enterDownDataDialog.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName")); // NOI18N
-
- setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
- setTitle(AddressbookApplication.printableTitle());
- setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
- setName("main"); // NOI18N
-
- mainMenu.setText(bundle.getString("AddressbookFrame.text")); // NOI18N
- mainMenu.setFocusable(false);
- mainMenu.setName(""); // NOI18N
-
- exitProgram.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
- exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text")); // NOI18N
- exitProgram.setToolTipText(bundle.getString("AddressbookFrame.exitProgram.toolTipText")); // NOI18N
- exitProgram.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- exitProgramActionPerformed(evt);
- }
- });
- mainMenu.add(exitProgram);
-
- menuBar.add(mainMenu);
-
- addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text")); // NOI18N
-
- addOwnData.setText(bundle.getString("AddressbookFrame.addOwn.text")); // NOI18N
- addOwnData.setToolTipText(bundle.getString("AddressbookFrame.addOwnData.toolTipText")); // NOI18N
- addOwnData.setEnabled(false);
- addOwnData.setName("addOwn"); // NOI18N
- addOwnData.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addOwnDataActionPerformed(evt);
- }
- });
- addressbookMenu.add(addOwnData);
- addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName")); // NOI18N
- addOwnData.getAccessibleContext().setAccessibleDescription(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription")); // NOI18N
-
- menuBar.add(addressbookMenu);
-
- setJMenuBar(menuBar);
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 279, Short.MAX_VALUE)
- );
-
- pack();
- }// </editor-fold>//GEN-END:initComponents
-
- private void exitProgramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed
- // Close application instance
- this.getClient().getApplication().doShutdown();
- }//GEN-LAST:event_exitProgramActionPerformed
-
- private void addOwnDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed
- // Asks the user to enter own data
- this.getClient().getContactManager().doEnterOwnData();
- }//GEN-LAST:event_addOwnDataActionPerformed
-
- /**
- * Setups the frame
- *
- * @param client Client instance
- */
- @Override
- public void setupFrame (final Client client) {
- // Has the user entered own data?
- if (!this.getClient().getContactManager().isOwnContactAdded()) {
- // Debug message
- this.getLogger().debug("Enabling menus: isOwnContactAdded()=false");
-
- // Not entered yet, so enable menu
- addOwnData.setEnabled(true);
- }
-
- /*
- * Set the Nimbus look and feel
- */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /*
- * If Nimbus (introduced in Java SE 6) is not available, stay with the
- * default look and feel. For details see
- * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (final ClassNotFoundException ex) {
- this.getLogger().catching(ex);
- } catch (final InstantiationException ex) {
- this.getLogger().catching(ex);
- } catch (final IllegalAccessException ex) {
- this.getLogger().catching(ex);
- } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
- this.getLogger().catching(ex);
- }
- //</editor-fold>
-
- // Debug line
- this.getLogger().debug("Displaying form ...");
-
- /*
- * Create and display the form
- */
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run () {
- new AddressbookFrame(client).setVisible(true);
- }
- });
- }
-
- /**
- * Getter for logger
- *
- * @return Logger
- */
- protected final Logger getLogger () {
- return this.LOG;
- }
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JMenuItem addOwnData;
- private javax.swing.JMenu addressbookMenu;
- private javax.swing.JDialog enterDownDataDialog;
- private javax.swing.JMenuItem exitProgram;
- private javax.swing.JMenu mainMenu;
- private javax.swing.JMenuBar menuBar;
- // End of variables declaration//GEN-END:variables
-}
+++ /dev/null
-AddressbookFrame.text=Main
-AddressbookFrame.status.AccessibleContext.accessibleName=
-AddressbookFrame.status.text=Welcome ...
-AddressbookFrame.addressbookMenu.text=Addressbook
-AddressbookFrame.exitProgram.toolTipText=Exits the program cleanly.
-AddressbookFrame.exitProgram.text=Exit program
-AddressbookFrame.addOwn.text=Add own address
-AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn
-AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription=
-AddressbookFrame.addOwnData.toolTipText=Allows the user to add own address data
-AddressbookFrame.enterDownDataDialog.AccessibleContext.accessibleName=enterOwnDataWarning
+++ /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.gui;\r
-\r
-import org.mxchange.addressbook.FrameworkInterface;\r
-import org.mxchange.addressbook.client.Client;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public interface ClientFrame extends FrameworkInterface {\r
- /**\r
- * Setups the frame\r
- * \r
- * @param client Client instance\r
- */\r
- public void setupFrame (final Client client);\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.gui;\r
-\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\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.contact.Contact;\r
-import org.mxchange.addressbook.menu.Menu;\r
-import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class SwingClient extends BaseClient implements Client {\r
- /**\r
- * Swing frame instance\r
- */\r
- private final ClientFrame frame;\r
-\r
- /**\r
- * Constructor with application instance\r
- * @param application \r
- */\r
- public SwingClient (final Application application) {\r
- super();\r
-\r
- // Set application instance\r
- this.setApplication(application);\r
-\r
- // Init frame instance\r
- this.frame = new AddressbookFrame(this);\r
- }\r
-\r
- @Override\r
- public void displayAddressBox (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public void displayNameBox (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public void displayOtherDataBox (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public void doShutdown () {\r
- // Parent call\r
- super.doShutdown();\r
-\r
- // @TODO Add other shutdown stuff\r
- }\r
-\r
- @Override\r
- public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
- // Not implemented here\r
- }\r
-\r
- @Override\r
- public char enterChar (final char[] validChars, String message) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public int enterInt (final int minimum, final int maximum, final String message) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public Menu getMenu (final String menuType) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- /**\r
- * Returns a Swing menu item\r
- * \r
- * @param accessKey Key to access the menu\r
- * @param text Text to show to user\r
- * @return A SelectableMenuItem\r
- */\r
- @Override\r
- public SelectableMenuItem getMenuItem (final char accessKey, final String text) {\r
- // Returns null as the menu is now no longer controlled here.\r
- return null;\r
- }\r
-\r
- /**\r
- * Inizializes this client\r
- */\r
- @Override\r
- public void initClient () {\r
- // Init contact manager here\r
- this.initContactManager();\r
- \r
- // Now start the frame\r
- this.frame.setupFrame(this);\r
- }\r
-\r
- @Override\r
- public void outputMessage (final String message) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public void showCurrentMenu () {\r
- // Not implemented here\r
- }\r
-\r
- @Override\r
- public void showEntry (final SelectableMenuItem item) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- @Override\r
- public void showWelcome () {\r
- // Not implemented here\r
- }\r
-\r
- @Override\r
- public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
- }\r
-\r
- /**\r
- * Fills menu map with swing menus\r
- */\r
- @Override\r
- protected final void fillMenuMap () {\r
- // Nothing to fill here as the Swing frame is handling this all\r
- throw new UnsupportedOperationException("Not implemented.");\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 java.util.Objects;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.client.Client;\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 long zipCode;\r
-\r
- /**\r
- * No instances can be created of this class\r
- */\r
- protected BaseContact () {\r
- super();\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
- * @todo Needs a lot improvements\r
- */\r
- @Override\r
- public boolean equals (Object object) {\r
- // Is it same type?\r
- if (!(object instanceof BaseContact)) {\r
- // Not equal types\r
- return false;\r
- } else if (!(object instanceof Contact)) {\r
- // Not correct interface\r
- return false;\r
- }\r
-\r
- // Try to cast\r
- Contact contact = (Contact) object;\r
- \r
- // Now test some data @todo Definedly needs improvement\r
- return ((this.getGender() == contact.getGender())\r
- && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))\r
- && (this.getFamilyName().toLowerCase().equals(contact.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
- * "Serializes" this object into a CSV string (this time with semicolons)\r
- *\r
- * @return "CSV-serialized" version of the stored data\r
- */\r
- public String getCsvStringFromStoreableObject () {\r
- // Get all together\r
- String csvString = String.format(\r
- "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",\r
- this.isOwnContact(),\r
- this.getGender(),\r
- this.getSurname(),\r
- this.getFamilyName(),\r
- this.getCompanyName(),\r
- this.getStreet(),\r
- this.getZipCode(),\r
- this.getCity(),\r
- this.getCountryCode(),\r
- this.getPhoneNumber(),\r
- this.getFaxNumber(),\r
- this.getCellphoneNumber(),\r
- this.getEmailAddress(),\r
- this.getBirthday(),\r
- this.getComment()\r
- );\r
- \r
- // Then return it\r
- return csvString;\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
- * Some "getter" for a translated/human-readable gender\r
- * @return gender Human-readable gender\r
- */\r
- public String getTranslatedGender () {\r
- // Default init\r
- String translated = null;\r
-\r
- // "Translate" it\r
- switch (this.getGender()) {\r
- case 'M': // Mr.\r
- translated = "Herr";\r
- break;\r
-\r
- case 'F': // Mrs.\r
- translated = "Frau";\r
- break;\r
-\r
- case 'C': // "Company"\r
- translated = "Firma";\r
- break;\r
-\r
- default: // Unsupported\r
- this.getLogger().error("Gender " + this.getGender() + " not supported.");\r
- break;\r
- }\r
-\r
- // Return it\r
- return translated;\r
- }\r
-\r
- /**\r
- * ZIP code\r
- *\r
- * @return the zipCode\r
- */\r
- public long 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 long zipCode) {\r
- this.zipCode = zipCode;\r
- }\r
-\r
- @Override\r
- public int hashCode () {\r
- int hash = 7;\r
- hash = 79 * hash + Objects.hashCode(this.getFamilyName());\r
- hash = 79 * hash + this.getGender();\r
- hash = 79 * hash + Objects.hashCode(this.getSurname());\r
- return hash;\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
- /**\r
- * Shows this contact to the user\r
- *\r
- * @param client Client instance to use\r
- */\r
- public void show (final Client client) {\r
- // Display name "box"\r
- client.displayNameBox((Contact) this);\r
-\r
- // Display address "box"\r
- client.displayAddressBox((Contact) this);\r
-\r
- // Display other data "box"\r
- client.displayOtherDataBox((Contact) this);\r
- }\r
-\r
- /**\r
- * Updates address data in this Contact instance\r
- *\r
- * @param street Street\r
- * @param zipCode ZIP code\r
- * @param city City\r
- * @param countryCode Country code\r
- */\r
- public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {\r
- // Set all\r
- if (street != null) {\r
- this.setStreet(street);\r
- }\r
- if (zipCode > 0) {\r
- this.setZipCode(zipCode);\r
- }\r
- if (city != null) {\r
- this.setCity(city);\r
- }\r
- if (countryCode != null) {\r
- this.setCountryCode(countryCode);\r
- }\r
- }\r
-\r
- /**\r
- * Updates name data in this Contact instance\r
- * @param gender Gender (M, F, C)\r
- * @param surname Surname\r
- * @param familyName Family name\r
- * @param companyName Company name\r
- */\r
- public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {\r
- // Set all\r
- this.setGender(gender);\r
- if (surname != null) {\r
- this.setSurname(surname);\r
- }\r
- if (familyName != null) {\r
- this.setFamilyName(familyName);\r
- }\r
- if (companyName != null) {\r
- this.setCompanyName(companyName);\r
- }\r
- }\r
-\r
- /**\r
- * Updates other data in this Contact instance\r
- * \r
- * @param phoneNumber Phone number\r
- * @param cellphoneNumber Cellphone number\r
- * @param faxNumber Fax number\r
- * @param emailAddress Email address\r
- * @param birthday Birth day\r
- * @param comment Comments\r
- */\r
- public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {\r
- // Set all\r
- if (phoneNumber != null) {\r
- this.setPhoneNumber(phoneNumber);\r
- }\r
- if (cellphoneNumber != null) {\r
- this.setCellphoneNumber(cellphoneNumber);\r
- }\r
- if (faxNumber != null) {\r
- this.setFaxNumber(faxNumber);\r
- }\r
- if (emailAddress != null) {\r
- this.setEmailAddress(emailAddress);\r
- }\r
- if (birthday != null) {\r
- this.setBirthday(birthday);\r
- }\r
- if (comment != null) {\r
- this.setComment(comment);\r
- }\r
- }\r
-\r
- /**\r
- * Enables the flag "own data" which signals that this contact is the user's\r
- * own data.\r
- */\r
- protected void enableFlagOwnContact () {\r
- this.ownContact = true;\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
-import org.mxchange.addressbook.client.Client;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public interface Contact extends FrameworkInterface {\r
-\r
- /**\r
- * Some "getter" for translated gender of the contact\r
- * @return Translated / human-readable gender\r
- */\r
- public String getTranslatedGender();\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 long 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
- /**\r
- * Shows the contact to the user\r
- *\r
- * @param client Client instance to call back\r
- */\r
- public void show (final Client client);\r
-\r
- /**\r
- * Updates address data in this Contact instance\r
- * \r
- * @param street Street\r
- * @param zipCode ZIP code\r
- * @param city City\r
- * @param countryCode Country code\r
- */\r
- public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode);\r
-\r
- /**\r
- * Updates name data in this Contact instance\r
- * \r
- * @param gender Gender (M, F, C)\r
- * @param surname Surname\r
- * @param familyName Family name\r
- * @param companyName Company name\r
- */\r
- public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);\r
-\r
- /**\r
- * Updates other data in this Contact instance\r
- * \r
- * @param phoneNumber Phone number\r
- * @param cellNumber Cellphone number\r
- * @param faxNumber Fax number\r
- * @param email Email address\r
- * @param birthday Birthday\r
- * @param comment Comments\r
- */\r
- public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String birthday, final String comment);\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
-import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\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, StoreableCsv {\r
-\r
- /**\r
- * Default constructor, may only be used from database backend\r
- */\r
- public BookContact () {\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.contact.user;\r
-\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.contact.book.BookContact;\r
-import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\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, StoreableCsv {\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
- * @param companyName Company name\r
- * @todo Add validation of data\r
- */\r
- public UserContact (final char gender, final String surname, final String familyName, final String companyName) {\r
- // Make sure all constructors are called\r
- this();\r
-\r
- this.setGender(gender);\r
- this.setSurname(surname);\r
- this.setFamilyName(familyName);\r
- this.setCompanyName(companyName);\r
- }\r
-\r
- /**\r
- * Default constructor, may only be used from database backend\r
- */\r
- public UserContact () {\r
- this.enableFlagOwnContact();\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.database.backend;\r
-\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-\r
-/**\r
- * Generall database backend\r
- * \r
- * @author Roland Haeder\r
- */\r
-public class BaseDatabaseBackend extends BaseFrameworkSystem {\r
- /**\r
- * No instances from this class\r
- */\r
- protected BaseDatabaseBackend () {\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.database.backend;\r
-\r
-import java.io.IOException;\r
-import org.mxchange.addressbook.FrameworkInterface;\r
-import org.mxchange.addressbook.database.storage.Storeable;\r
-\r
-/**\r
- * A generic interface for database frontends\r
- * \r
- * @author Roland Haeder\r
- */\r
-public interface DatabaseBackend extends FrameworkInterface {\r
-\r
- /**\r
- * Shuts down this backend\r
- */\r
- public void doShutdown ();\r
-\r
- /**\r
- * Rewinds backend\r
- */\r
- public void rewind ();\r
-\r
- /**\r
- * Get length of underlaying file\r
- *\r
- * @return Length of underlaying file\r
- */\r
- public long length ();\r
-\r
- /**\r
- * Stores an object in the database.\r
- * \r
- * @param object Object to store in database\r
- * @throws java.io.IOException From inner class\r
- */\r
- public void store (final Storeable object) throws IOException;\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.database.backend.csv;\r
-\r
-import java.util.Iterator;\r
-import org.mxchange.addressbook.BadTokenException;\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public interface CsvBackend extends DatabaseBackend {\r
-\r
- /**\r
- * Gets an iterator for contacts\r
- * \r
- * @return Iterator for contacts\r
- */\r
- public Iterator<Contact> contactIterator () throws BadTokenException;\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.database.backend.csv;\r
-\r
-import java.io.DataOutput;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.io.RandomAccessFile;\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-import org.mxchange.addressbook.BadTokenException;\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.contact.book.BookContact;\r
-import org.mxchange.addressbook.contact.user.UserContact;\r
-import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;\r
-import org.mxchange.addressbook.database.storage.Storeable;\r
-import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\r
-\r
-/**\r
- * A database backend with CSV file as storage implementation\r
- * \r
- * @author Roland Haeder\r
- */\r
-public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend {\r
- /**\r
- * Output stream for this storage engine\r
- */\r
- private RandomAccessFile storageFile;\r
-\r
- /**\r
- * Constructor with table name\r
- * \r
- * @param tableName Name of "table"\r
- */\r
- public CsvDatabaseBackend (final String tableName) {\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName));\r
-\r
- // Set table name here, too\r
- this.setTableName(tableName);\r
-\r
- // Construct file name\r
- String fileName = String.format("data/table_%s.csv", tableName);\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));\r
-\r
- try {\r
- // Try to initialize the storage (file instance)\r
- this.storageFile = new RandomAccessFile(fileName, "rw");\r
- } catch (final FileNotFoundException ex) {\r
- // Did not work\r
- this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString()));\r
- System.exit(1);\r
- }\r
-\r
- // Output message\r
- this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName));\r
- }\r
-\r
- /**\r
- * Gets an iterator for contacts\r
- * \r
- * @return Iterator for contacts\r
- * @throws org.mxchange.addressbook.BadTokenException If the underlaying method has found an invalid token\r
- */\r
- @Override\r
- public Iterator<Contact> contactIterator () throws BadTokenException {\r
- /*\r
- * Then read the file into RAM (yes, not perfect for >1000 entries ...)\r
- * and get a List back.\r
- */\r
- List<Contact> list = this.readContactList();\r
-\r
- // Get iterator from list and return it\r
- return list.iterator();\r
- }\r
-\r
- /**\r
- * Shuts down this backend\r
- */\r
- @Override\r
- public void doShutdown () {\r
- try {\r
- // Close file\r
- this.storageFile.close();\r
- } catch (final IOException ex) {\r
- this.getLogger().catching(ex);\r
- System.exit(1);\r
- }\r
- }\r
-\r
- /**\r
- * Get length of underlaying file\r
- *\r
- * @return Length of underlaying file\r
- */\r
- @Override\r
- public long length () {\r
- long length = 0;\r
- \r
- try {\r
- length = this.storageFile.length();\r
- this.getLogger().debug(MessageFormat.format("length={0}", length));\r
- } catch (final IOException ex) {\r
- // Length cannot be determined\r
- this.getLogger().catching(ex);\r
- System.exit(1);\r
- }\r
- \r
- // Return result\r
- this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length));\r
- return length;\r
- }\r
-\r
- /**\r
- * Rewinds backend\r
- */\r
- @Override\r
- public void rewind (){\r
- this.getLogger().trace("CALLED!");\r
-\r
- try {\r
- // Rewind underlaying database file\r
- this.storageFile.seek(0);\r
- } catch (final IOException ex) {\r
- this.getLogger().catching(ex);\r
- System.exit(1);\r
- }\r
-\r
- this.getLogger().trace("EXIT!");\r
- }\r
-\r
- /**\r
- * Stores given object by "visiting" it\r
- *\r
- * @param object An object implementing Storeable\r
- * @throws java.io.IOException From "inner" class\r
- */\r
- @Override\r
- public void store (final Storeable object) throws IOException {\r
- // Make sure the instance is there (DataOutput flawor)\r
- assert(this.storageFile instanceof DataOutput);\r
-\r
- // Try to cast it, this will fail if the interface is not implemented\r
- StoreableCsv csv = (StoreableCsv) object;\r
-\r
- // Now get a string from the object that needs to be stored\r
- String str = csv.getCsvStringFromStoreableObject();\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));\r
-\r
- // The string is now a valid CSV string\r
- this.storageFile.writeBytes(str);\r
- }\r
-\r
- /**\r
- * Adds given contact to list\r
- * \r
- * @param contact Contact instance to add\r
- * @param list List instance\r
- */\r
- private void addContactToList (final Contact contact, final List<Contact> list) {\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("contact={0}", contact));\r
-\r
- // Is the contact read?\r
- if (contact instanceof Contact) {\r
- // Then add it\r
- boolean added = list.add(contact);\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));\r
-\r
- // Has it been added?\r
- if (!added) {\r
- // Not added\r
- this.getLogger().warn("Contact object has not been added.");\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Checks whether end of file has been reached\r
- * \r
- * @return Whether lines are left to read\r
- */\r
- private boolean isEndOfFile () {\r
- // Default is EOF\r
- boolean isEof = true;\r
-\r
- try {\r
- isEof = (this.storageFile.getFilePointer() >= this.length());\r
- } catch (final IOException ex) {\r
- // Length cannot be determined\r
- this.getLogger().catching(ex);\r
- }\r
-\r
- // Return status\r
- this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof));\r
- return isEof;\r
- }\r
-\r
- /**\r
- * Reads the database file, if available, and adds all read lines into\r
- * the list.\r
- * \r
- * @return A list with Contact instances\r
- */\r
- private List<Contact> readContactList () throws BadTokenException {\r
- this.getLogger().trace("CALLED!");\r
-\r
- // First rewind\r
- this.rewind();\r
-\r
- // Get file size and divide it by 140 (possible average length of one line)\r
- int lines = Math.round(this.length() / 140 + 0.5f);\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("lines={0}", lines));\r
-\r
- // Instance list\r
- // @TODO The maximum length could be guessed from file size?\r
- List<Contact> list = new ArrayList<>(lines);\r
-\r
- // Init variables\r
- StringTokenizer tokenizer;\r
- String line;\r
-\r
- // Read all lines\r
- while (!this.isEndOfFile()) {\r
- // Then read a line\r
- line = this.readLine();\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("line={0}", line));\r
-\r
- // Then tokenize it\r
- // @TODO Move this into separate method\r
- tokenizer = new StringTokenizer(line, ";");\r
-\r
- // Count round\r
- int count = 0;\r
-\r
- // Init contact object\r
- Contact contact = null;\r
-\r
- // The tokens are now available, so get all\r
- while (tokenizer.hasMoreElements()) {\r
- // Get next token\r
- String token = tokenizer.nextToken();\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("token={0}", token));\r
-\r
- // Verify token, it must have double-quotes on each side\r
- if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {\r
- // Something bad was read\r
- throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));\r
- }\r
-\r
- // All fine, so remove it\r
- String strippedToken = token.substring(1, token.length() - 1);\r
-\r
- // Is the string's content "null"?\r
- if (strippedToken.equals("null")) {\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken));\r
-\r
- // This needs to be set to null\r
- strippedToken = null;\r
- }\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));\r
-\r
- // Init number/string data values\r
- String strData = strippedToken;\r
- Long num = null;\r
- Boolean bool = null;\r
- char gender = '?';\r
- \r
- // Now, let's try a number check, if no null\r
- if (strippedToken != null) {\r
- // Okay, no null, maybe the string bears a decimal number?\r
- try {\r
- num = Long.valueOf(strippedToken);\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken));\r
- } catch (final NumberFormatException ex) {\r
- // No number, then set default\r
- num = null;\r
- }\r
- }\r
- \r
- // Now, let's try a boolean check, if no null\r
- if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) {\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken));\r
-\r
- // parseBoolean() is relaxed, so no exceptions\r
- bool = Boolean.valueOf(strippedToken);\r
- }\r
- \r
- // Now, let's try a boolean check, if no null\r
- if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {\r
- // Get first character\r
- gender = strippedToken.charAt(0);\r
- }\r
-\r
- // Now it depends on the counter which position we need to check\r
- switch (count) {\r
- case 0: // isOwnContact\r
- assert((bool instanceof Boolean));\r
-\r
- // Debug message\r
- this.getLogger().debug(MessageFormat.format("bool={0}", bool));\r
-\r
- // Is it own contact?\r
- if (true == bool) {\r
- // Debug message\r
- this.getLogger().debug("Creating UserContact object ...");\r
-\r
- // Own entry\r
- contact = new UserContact();\r
- } else {\r
- // Debug message\r
- this.getLogger().debug("Creating BookContact object ...");\r
-\r
- // Other contact\r
- contact = new BookContact();\r
- }\r
- break;\r
-\r
- case 1: // Gender\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
- assert(gender != '?') : "Gender is not detected.";\r
-\r
- // Update data\r
- contact.updateNameData(gender, null, null, null);\r
- break;\r
-\r
- case 2: // Surname\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
- assert(gender != '?') : "Gender is not detected.";\r
-\r
- // Update data\r
- contact.updateNameData(gender, strippedToken, null, null);\r
- break;\r
-\r
- case 3: // Family name\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
- assert(gender != '?') : "Gender is not detected.";\r
-\r
- // Update data\r
- contact.updateNameData(gender, null, strippedToken, null);\r
- break;\r
-\r
- case 4: // Company name\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
- assert(gender != '?') : "Gender is not detected.";\r
-\r
- // Update data\r
- contact.updateNameData(gender, null, null, strippedToken);\r
- break;\r
-\r
- case 5: // Street number\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateAddressData(strippedToken, 0, null, null);\r
- break;\r
-\r
- case 6: // ZIP code\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateAddressData(null, num, null, null);\r
- break;\r
-\r
- case 7: // City name\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateAddressData(null, 0, strippedToken, null);\r
- break;\r
-\r
- case 8: // Country code\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateAddressData(null, 0, null, strippedToken);\r
- break;\r
-\r
- case 9: // Phone number\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(strippedToken, null, null, null, null, null);\r
- break;\r
-\r
- case 10: // Fax number\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(null, strippedToken, null, null, null, null);\r
- break;\r
-\r
- case 11: // Cellphone number\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(null, null, strippedToken, null, null, null);\r
- break;\r
-\r
- case 12: // Email address\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(null, null, null, strippedToken, null, null);\r
- break;\r
-\r
- case 13: // Birthday\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(null, null, null, null, strippedToken, null);\r
- break;\r
-\r
- case 14: // Birthday\r
- assert(contact instanceof Contact) : "First token was not boolean";\r
-\r
- // Update data\r
- contact.updateOtherData(null, null, null, null, null, strippedToken);\r
- break;\r
-\r
- default: // New data entry\r
- this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count));\r
- break;\r
- }\r
-\r
- // Increment counter for next round\r
- count++;\r
- }\r
-\r
- // Add contact\r
- this.addContactToList(contact, list);\r
- }\r
-\r
- // Return finished list\r
- this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size()));\r
- return list;\r
- }\r
-\r
- /**\r
- * Reads a line from file base\r
- *\r
- * @return Read line from file\r
- */\r
- private String readLine () {\r
- // Init input\r
- String input = null;\r
-\r
- try {\r
- input = this.storageFile.readLine();\r
- } catch (final IOException ex) {\r
- this.getLogger().catching(ex);\r
- }\r
-\r
- // Return read string or null\r
- return input;\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.database.frontend;\r
-\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
-import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend;\r
-\r
-/**\r
- * General database frontend class\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class BaseDatabaseFrontend extends BaseFrameworkSystem {\r
-\r
- /**\r
- * Instance for database backend\r
- */\r
- private DatabaseBackend backend;\r
-\r
- /**\r
- * No instances from this class\r
- */\r
- protected BaseDatabaseFrontend () {\r
- }\r
-\r
- /**\r
- * Instance for database backend\r
- * \r
- * @return the backend\r
- */\r
- protected DatabaseBackend getBackend () {\r
- return this.backend;\r
- }\r
-\r
- /**\r
- * Instance for database backend\r
- * \r
- * @param backend the backend to set\r
- */\r
- protected void setBackend (final DatabaseBackend backend) {\r
- this.backend = backend;\r
- }\r
-\r
- /**\r
- * Initialize backend\r
- */\r
- protected void initBackend () {\r
- // Instance backend\r
- this.backend = new CsvDatabaseBackend(this.getTableName());\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.database.frontend;\r
-\r
-import org.mxchange.addressbook.FrameworkInterface;\r
-\r
-/**\r
- * A generic interface for database frontends\r
- * \r
- * @author Roland Haeder\r
- */\r
-public interface DatabaseWrapper 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.database.frontend.contact;\r
-\r
-import java.io.IOException;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import org.mxchange.addressbook.BadTokenException;\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.database.backend.csv.CsvBackend;\r
-import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;\r
-import org.mxchange.addressbook.database.storage.Storeable;\r
-import org.mxchange.addressbook.manager.contact.ContactManager;\r
-\r
-/**\r
- * Stores and retrieves Contact instances\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {\r
- /**\r
- * Constructor which accepts a contact manager\r
- * @param manager\r
- */\r
- public ContactDatabaseFrontend (final ContactManager manager) {\r
- // Call own constructor\r
- this();\r
- \r
- // Set contact manager\r
- this.setContactManager(manager);\r
- }\r
-\r
- /**\r
- * Basic constrcutor\r
- */\r
- protected ContactDatabaseFrontend () {\r
- super();\r
-\r
- // Set "table" name\r
- this.setTableName("contacts");\r
-\r
- // Initalize backend\r
- this.initBackend();\r
- }\r
-\r
- /**\r
- * Shuts down the database layer\r
- */\r
- @Override\r
- public void doShutdown () {\r
- // Shutdown backend\r
- this.getBackend().doShutdown();\r
- }\r
-\r
- /**\r
- * Flushes all contact entries to database\r
- */\r
- @Override\r
- public void flushAllContacts () {\r
- // Get full list\r
- List<Contact> contacts = this.getContactManager().getList();\r
-\r
- // Get iterator\r
- Iterator<Contact> iterator = contacts.iterator();\r
-\r
- // Rewind backend\r
- this.getBackend().rewind();\r
-\r
- // Get all entries\r
- while (iterator.hasNext()) {\r
- // Get next entry\r
- Contact contact = iterator.next();\r
-\r
- try {\r
- // Store this entry\r
- this.getBackend().store((Storeable) contact);\r
- } catch (final IOException ex) {\r
- // Should not happen?\r
- this.getLogger().catching(ex);\r
- System.exit(1);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Reads all contacts from database backend and handles them over to the\r
- * contact manager\r
- */\r
- @Override\r
- public void readAllContacts () {\r
- // Get iterator and case it\r
- CsvBackend backend = (CsvBackend) this.getBackend();\r
- \r
- // First rewind to beginning\r
- this.getBackend().rewind();\r
-\r
- // Get backend iterator\r
- Iterator<Contact> iterator = null;\r
- try {\r
- iterator = backend.contactIterator();\r
- } catch (final BadTokenException ex) {\r
- this.getLogger().catching(ex);\r
- System.exit(1);\r
- }\r
-\r
- // Read all entries\r
- while (iterator.hasNext()) {\r
- // Get next entry\r
- Contact contact = iterator.next();\r
-\r
- // Add contact instance to manager\r
- this.getContactManager().addContact(contact);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2015 Roland Häder\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.database.frontend.contact;\r
-\r
-import org.mxchange.addressbook.database.frontend.DatabaseWrapper;\r
-\r
-/**\r
- *\r
- * @author Roland Häder\r
- */\r
-public interface ContactWrapper extends DatabaseWrapper {\r
-\r
- /**\r
- * Shuts down the database layer\r
- */\r
- public void doShutdown ();\r
-\r
- /**\r
- * Flushes all contact entries to database\r
- */\r
- public void flushAllContacts ();\r
-\r
- /**\r
- * Reads all contacts from database backend and handles them over to the\r
- * contact manager\r
- */\r
- public void readAllContacts ();\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.database.storage;\r
-\r
-import org.mxchange.addressbook.FrameworkInterface;\r
-\r
-/**\r
- *An interface for objects being stored in databases\r
- * \r
- * @author Roland Haeder\r
- */\r
-public interface Storeable extends FrameworkInterface {\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.database.storage.csv;\r
-\r
-import org.mxchange.addressbook.database.storage.Storeable;\r
-\r
-/**\r
- *\r
- * @author KLC\r
- */\r
-public interface StoreableCsv extends Storeable {\r
- /**\r
- * Getter for a CSV-formated string from object\r
- * @return \r
- */\r
- public String getCsvStringFromStoreableObject ();\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.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\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.database.frontend.contact.ContactDatabaseFrontend;\r
-import org.mxchange.addressbook.database.frontend.contact.ContactWrapper;\r
-import org.mxchange.addressbook.manager.BaseManager;\r
-\r
-/**\r
- * A manager for contacts, please note that this implementation loads the whole\r
- * list into RAM.\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
- * A ContactWrapper instance\r
- */\r
- private final ContactWrapper contactDatabase;\r
-\r
- /**\r
- * A list of 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
- // Init database connection\r
- this.contactDatabase = new ContactDatabaseFrontend(this);\r
-\r
- // Read all entries\r
- this.contactDatabase.readAllContacts();\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 instance to list\r
- *\r
- * @param contact Contact instance to add\r
- */\r
- @Override\r
- public void addContact (final Contact 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().outputMessage("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
- // Display contact\r
- contact.show(this.getClient());\r
- \r
- try {\r
- // Ask user what to change\r
- this.getClient().userChooseChangeContactData(contact);\r
- } catch (final UnhandledUserChoiceException ex) {\r
- this.getLogger().catching(ex);\r
- }\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
- * Let the user change address data\r
- * \r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- */\r
- @Override\r
- public void doChangeAddressData (final Contact contact, final Client client) {\r
- // First display it again\r
- client.displayAddressBox(contact);\r
-\r
- // Is it own data?\r
- if (contact.isOwnContact()) {\r
- // Own address data\r
- String street = this.enterOwnStreet();\r
-\r
- // Get zip code\r
- int zipCode = this.enterOwnZipCode();\r
-\r
- // Get city name\r
- String city = this.enterOwnCity();\r
-\r
- // Get country code\r
- String countryCode = this.enterOwnCountryCode();\r
-\r
- // Update address data\r
- contact.updateAddressData(street, zipCode, city, countryCode);\r
- } else {\r
- // Other contact's address data to change\r
- throw new UnsupportedOperationException("Changing contact entries not finished.");\r
- }\r
-\r
- // Flush whole list\r
- this.flush();\r
- }\r
-\r
- /**\r
- * Let the user change "name data"\r
- * \r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- */\r
- @Override\r
- public void doChangeNameData (final Contact contact, final Client client) {\r
- // First display them again\r
- client.displayNameBox(contact);\r
-\r
- // Is this own data?\r
- if (contact.isOwnContact()) {\r
- // Re-ask own data\r
- // Gender:\r
- char gender = this.enterOwnGender();\r
-\r
- // Surname\r
- String surname = this.enterOwnSurname();\r
-\r
- // Family name\r
- String familyName = this.enterOwnFamilyName();\r
-\r
- // And company\r
- String companyName = this.enterOwnCompanyName();\r
-\r
- // Update contact instance\r
- contact.updateNameData(gender, surname, familyName, companyName);\r
- } else {\r
- // Then re-ask them ...\r
- throw new UnsupportedOperationException("Changing contact entries not finished.");\r
- }\r
-\r
- // Flush whole list\r
- this.flush();\r
- }\r
-\r
- /**\r
- * Let the user change other data\r
- *\r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- * @todo Didn't handle birthday\r
- */\r
- @Override\r
- public void doChangeOtherData (final Contact contact, final Client client) {\r
- // First display them again\r
- client.displayOtherDataBox(contact);\r
-\r
- // Is this own data?\r
- if (contact.isOwnContact()) {\r
- // Re-ask own data\r
- // Phone number\r
- String phoneNumber = this.enterOwnPhoneNumber();\r
-\r
- // Phone number\r
- String cellNumber = this.enterOwnCellNumber();\r
-\r
- // Fax number\r
- String faxNumber = this.enterOwnFaxNumber();\r
-\r
- // Email address\r
- String email = this.enterOwnEmailAddress();\r
-\r
- // Comment\r
- String comment = this.enterOwnComment();\r
-\r
- // Update contact instance\r
- contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment);\r
- } else {\r
- // Then re-ask them ...\r
- throw new UnsupportedOperationException("Changing contact entries not finished.");\r
- }\r
-\r
- // Flush whole list\r
- this.flush();\r
- }\r
-\r
- /**\r
- * Asks user for own data\r
- */\r
- @Override\r
- public void doEnterOwnData () {\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
- // Company name ...\r
- String companyName = this.enterOwnCompanyName();\r
-\r
- // Construct UserContact instance\r
- Contact contact = new UserContact(gender, surname, familyName, companyName);\r
-\r
- // Add it to contact "book"\r
- this.registerContact(contact);\r
- }\r
-\r
- /**\r
- * Shuts down this contact manager\r
- */\r
- @Override\r
- public void doShutdown () {\r
- // Shut down the database layer\r
- this.contactDatabase.doShutdown();\r
- }\r
-\r
- /**\r
- * Getter for whole contact list\r
- * \r
- * @return List of all contacts\r
- */\r
- @Override\r
- public List<Contact> getList () {\r
- return Collections.unmodifiableList(this.contacts);\r
- }\r
-\r
- /**\r
- * Checks whether own contact is already added by checking all entries for\r
- * isOwnContact flag\r
- *\r
- * @return Whether own contact is already added\r
- */\r
- @Override\r
- public 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
- @Override\r
- public void listContacts () {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
- }\r
-\r
- /**\r
- * Adds given contact to address book and flushes all entries to database\r
- *\r
- * @param contact Contact being added\r
- * @todo Add check for book size\r
- */\r
- @Override\r
- public void registerContact (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(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size()));\r
- \r
- // Add contact to internal list\r
- this.addContact(contact);\r
- \r
- // Flush whole list\r
- this.flush();\r
- }\r
-\r
- @Override\r
- public void searchContacts () {\r
- throw new UnsupportedOperationException("Not supported yet.");\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 his/her cellphone number\r
- * \r
- * @return User's cellphone number\r
- */\r
- private String enterOwnCellNumber () {\r
- return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);\r
- }\r
-\r
- /**\r
- * Asks the user for his/her city's name\r
- *\r
- * @return City's name of the user\r
- */\r
- private String enterOwnCity () {\r
- return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);\r
- }\r
-\r
- /**\r
- * Asks the user for his/her city's name\r
- *\r
- * @return City's name of the user\r
- */\r
- private String enterOwnComment () {\r
- return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);\r
- }\r
-\r
- /**\r
- * Asks the user for his/her company name\r
- * \r
- * @return User's company name\r
- */\r
- private String enterOwnCompanyName () {\r
- return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);\r
- }\r
-\r
- /**\r
- * Asks user for his/her own country code\r
- * \r
- * @return User's own country code\r
- */\r
- private String enterOwnCountryCode () {\r
- return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();\r
- }\r
-\r
- /**\r
- * Asks user for his/her own country code\r
- * \r
- * @return User's own country code\r
- */\r
- private String enterOwnEmailAddress () {\r
- return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);\r
- }\r
-\r
- /**\r
- * Asks the user for family name\r
- * \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: ", false);\r
- }\r
-\r
- /**\r
- * Asks the user for family name\r
- * \r
- * @return Family name of the user\r
- */\r
- private String enterOwnFaxNumber () {\r
- return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);\r
- }\r
-\r
- /**\r
- * Asks the user for gender, until a valid has been entered\r
- * \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 phone number\r
- * \r
- * @return Phone number of the user\r
- */\r
- private String enterOwnPhoneNumber () {\r
- return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);\r
- }\r
-\r
- /**\r
- * Asks the user for own street (including number)\r
- */\r
- private String enterOwnStreet () {\r
- return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);\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: ", false);\r
- }\r
-\r
- /**\r
- * Asks the user for own ZIP code\r
- * @return ZIP code\r
- */\r
- private int enterOwnZipCode () {\r
- return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");\r
- }\r
-\r
- /**\r
- * Flushes all entries by calling database backend\r
- */\r
- private void flush () {\r
- // Flusgh all\r
- this.getContactDatabase().flushAllContacts();\r
- }\r
-\r
- /**\r
- * A ContactWrapper instance\r
- *\r
- * @return the database\r
- */\r
- private ContactWrapper getContactDatabase () {\r
- return this.contactDatabase;\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
+++ /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.List;\r
-import org.mxchange.addressbook.client.Client;\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
- /**\r
- * Shuts down this contact manager\r
- */\r
- public void doShutdown ();\r
-\r
- /**\r
- * List all contacts\r
- */\r
- public void listContacts ();\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
- public void registerContact (final Contact contact);\r
-\r
- /**\r
- * Adds given Contact instance to list\r
- * \r
- * @param contact Contact instance to add\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
- * The user can change address data, like street, ZIP code, city and country\r
- * of given Contact instance.\r
- * \r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- */\r
- public void doChangeAddressData (final Contact contact, final Client client);\r
-\r
- /**\r
- * The user can change name data, like gender, surname, family name and\r
- * company name (if business contact).\r
- * \r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- */\r
- public void doChangeNameData (final Contact contact, final Client client);\r
-\r
- /**\r
- * Let the user change other address\r
- */\r
- public void changeOtherAddress();\r
-\r
- /**\r
- * The user can change other data, like phone numbers or comments.\r
- * \r
- * @param contact Instance to change data\r
- * @param client Client instance to call back\r
- */\r
- public void doChangeOtherData (final Contact contact, final Client client);\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 doEnterOwnData();\r
-\r
- /**\r
- * Getter for whole list\r
- * @return List of all contacts\r
- */\r
- public List<Contact> getList ();\r
-\r
- /**\r
- * Searches address book for a contact\r
- */\r
- public void searchContacts ();\r
-\r
- /**\r
- * Checks whether own contact is already added by checking all entries for\r
- * isOwnContact flag\r
- * \r
- * @return Whether own contact is already added\r
- */\r
- public boolean isOwnContactAdded ();\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
- // List entries\r
- menuList.add(client.getMenuItem('4', "Adressbuch anzeigen"));\r
-\r
- // Address search\r
- menuList.add(client.getMenuItem('5', "Adresse suchen"));\r
-\r
- // Change other address\r
- menuList.add(client.getMenuItem('6', "Adresse ändern"));\r
-\r
- // Delete other address\r
- menuList.add(client.getMenuItem('7', "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.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.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
- * Size of menu items\r
- * @return Count of menu items\r
- */\r
- public int getMenuItemsCount () {\r
- return this.menuList.size();\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
- * 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
- * Getter for menu list\r
- *\r
- * @return menuList List of menu entries\r
- */\r
- protected final List<SelectableMenuItem> getMenuList () {\r
- return this.menuList;\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
-}\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 org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.menu.AddressbookMenu;\r
-import org.mxchange.addressbook.menu.BaseMenu;\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
- // Add all items\r
- AddressbookMenu.addItemsToList(this.getMenuList(), 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
- * Access key\r
- * @param accessKey the accessKey to set\r
- */\r
- private void setAccessKey (char accessKey) {\r
- this.accessKey = 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
- /**\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
- @Override\r
- public void show (final Client client) {\r
- // Call-back client over menu\r
- client.showEntry(this);\r
- }\r
- \r
-}\r
--- /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="TRACE"/>
+ </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
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BadTokenException extends Exception {\r
+\r
+ public BadTokenException (final String str) {\r
+ super(str);\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;\r
+\r
+import java.util.ResourceBundle;\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.ManageableContact;\r
+\r
+/**\r
+ * General class\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseFrameworkSystem implements FrameworkInterface {\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
+ * Name of used database table, handled over to backend\r
+ */\r
+ private String tableName;\r
+\r
+ /**\r
+ * Bundle instance\r
+ */\r
+ private final ResourceBundle bundle;\r
+\r
+ /**\r
+ * Initialize object\r
+ */\r
+ {\r
+ LOG = LogManager.getLogger(this);\r
+ bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N\r
+ }\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseFrameworkSystem () {\r
+ }\r
+\r
+ /**\r
+ * Application instance\r
+ * \r
+ * @return the application\r
+ */\r
+ @Override\r
+ public final Application getApplication () {\r
+ return this.application;\r
+ }\r
+\r
+ /**\r
+ * Client instance\r
+ * \r
+ * @return the client\r
+ */\r
+ @Override\r
+ public final Client getClient () {\r
+ return this.client;\r
+ }\r
+\r
+ /**\r
+ * Contact manager instance\r
+ * @return the contactManager\r
+ */\r
+ @Override\r
+ public final ManageableContact getContactManager () {\r
+ return this.contactManager;\r
+ }\r
+\r
+ /**\r
+ * Contact manager instance\r
+ * @param contactManager the contactManager to set\r
+ */\r
+ protected final void setContactManager (final ManageableContact contactManager) {\r
+ this.contactManager = contactManager;\r
+ }\r
+\r
+ /**\r
+ * Client instance\r
+ * @param client the client to set\r
+ */\r
+ protected final void setClient (final Client client) {\r
+ this.client = client;\r
+ }\r
+\r
+ /**\r
+ * Application instance\r
+ *\r
+ * @param application the application to set\r
+ */\r
+ protected final void setApplication(final Application application) {\r
+ this.application = application;\r
+ }\r
+\r
+ /**\r
+ * Getter for logger\r
+ *\r
+ * @return Logger\r
+ */\r
+ protected final Logger getLogger () {\r
+ return this.LOG;\r
+ }\r
+\r
+ /**\r
+ * Name of used database table, handled over to backend\r
+ * \r
+ * @return the tableName\r
+ */\r
+ protected final String getTableName () {\r
+ return this.tableName;\r
+ }\r
+\r
+ /**\r
+ * Name of used database table, handled over to backend\r
+ * \r
+ * @param tableName the tableName to set\r
+ */\r
+ protected final void setTableName (final String tableName) {\r
+ this.tableName = tableName;\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.application.Application;\r
+import org.mxchange.addressbook.client.Client;\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
+ /**\r
+ * Client instance\r
+ * \r
+ * @return the client\r
+ */\r
+ public Client getClient ();\r
+\r
+ /**\r
+ * Application instance\r
+ * \r
+ * @return the application\r
+ */\r
+ public Application getApplication ();\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;\r
+\r
+/**\r
+ * This exception is thrown when the user made a valid choice but it was not\r
+ * handled by the program.\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class UnhandledUserChoiceException extends Exception {\r
+\r
+ public UnhandledUserChoiceException (final String message) {\r
+ super(message);\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 java.text.MessageFormat;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.client.console.ConsoleClient;\r
+import org.mxchange.addressbook.client.gui.SwingClient;\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 = "Adressbuch";\r
+\r
+ /**\r
+ * Application version\r
+ */\r
+ public static final String APP_VERSION = "0.0";\r
+\r
+ /**\r
+ * Console client is enabled by default\r
+ */\r
+ private boolean consoleClient = true;\r
+\r
+ /**\r
+ * GUI client is disabled by default\r
+ */\r
+ private boolean guiClient = false;\r
+\r
+ /**\r
+ * Getter for printable application name\r
+ * \r
+ * @return A printable name\r
+ */\r
+ public static String printableTitle () {\r
+ return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);\r
+ }\r
+\r
+ /**\r
+ * Bootstraps application\r
+ */\r
+ @Override\r
+ public void doBootstrap () {\r
+ this.getLogger().debug("Initializing application ...");\r
+\r
+ // Init client variable\r
+ Client client = null;\r
+\r
+ // Is console or Swing choosen?\r
+ if (this.isConsole()) {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing console client ...");\r
+\r
+ // Init console client instance\r
+ client = new ConsoleClient(this);\r
+ } else if (this.isGui()) {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing GUI (Swing) client ...");\r
+\r
+ // Init console instance\r
+ client = new SwingClient(this);\r
+ } else {\r
+ // Not client choosen\r
+ this.getLogger().error("No client choosen. Cannot launch.");\r
+ System.exit(1);\r
+ }\r
+\r
+ // Init client\r
+ client.initClient();\r
+\r
+ // Set 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().isRunning()) {\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().doUserMenuChoice();\r
+ } catch (final UnhandledUserChoiceException 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
+ * Enables console client by setting propper flag\r
+ */\r
+ private void enableConsoleClient () {\r
+ this.getLogger().debug("Enabling console client (may become optional client) ...");\r
+ this.consoleClient = true;\r
+ this.guiClient = false;\r
+ }\r
+\r
+ /**\r
+ * Enables GUI client by setting propper flag\r
+ */\r
+ private void enableGuiClient () {\r
+ this.getLogger().debug("Enabling GUI client (may become new default client) ...");\r
+ this.consoleClient = false;\r
+ this.guiClient = true;\r
+ }\r
+\r
+ /**\r
+ * Checks whether the client shoule be console client should be launched by\r
+ * checking if -console is set.\r
+ * \r
+ * @return Whether console client should be taken\r
+ */\r
+ private boolean isConsole () {\r
+ return this.consoleClient;\r
+ }\r
+\r
+ /**\r
+ * Checks whether the client shoule be GUI client should be launched by\r
+ * checking if -gui is set.\r
+ * \r
+ * @return Whether GUI client should be taken\r
+ */\r
+ private boolean isGui () {\r
+ return this.guiClient;\r
+ }\r
+\r
+ /**\r
+ * Parses all given arguments\r
+ *\r
+ * @param args Arguments from program launch\r
+ */\r
+ private void parseArguments (final String[] args) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));\r
+ \r
+ for (final String arg : args) {\r
+ // Switch on it\r
+ switch (arg) {\r
+ case "-console":\r
+ enableConsoleClient();\r
+ break;\r
+ \r
+ case "-gui":\r
+ enableGuiClient();\r
+ break;\r
+}\r
+ }\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
+ * @param args Arguments handled to program\r
+ */\r
+ private void start (final String args[]) {\r
+ this.getLogger().info("Program is started.");\r
+\r
+ // Parse arguments\r
+ this.parseArguments(args);\r
+\r
+ // Launch application\r
+ ApplicationManager.getManager(this).start();\r
+\r
+ // Good bye, but this should not be reached ...\r
+ this.getLogger().warn("Unusual exit reached.");\r
+ this.doShutdown();\r
+ }\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(args);\r
+ }\r
+\r
+ /**\r
+ * Shuts down the application.\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shutdown client\r
+ this.getClient().doShutdown();\r
+\r
+ this.getLogger().info("End of program (last line)");\r
+ System.exit(0);\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
+ /**\r
+ * Shutdown the application\r
+ */\r
+ public void doShutdown ();\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 java.util.HashMap;\r
+import java.util.Map;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.manager.contact.ContactManager;\r
+import org.mxchange.addressbook.manager.contact.ManageableContact;\r
+import org.mxchange.addressbook.menu.Menu;\r
+\r
+/**\r
+ * A general client\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public abstract 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
+ * Menu system\r
+ */\r
+ private final Map<String, Menu> menus;\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseClient () {\r
+ super();\r
+\r
+ // Init menu map\r
+ this.menus = new HashMap<>(10);\r
+ }\r
+\r
+ /**\r
+ * Shutdown method for all clients\r
+ */\r
+ public void doShutdown () {\r
+ // Disable client\r
+ this.disableIsRunning();\r
+\r
+ // Shuts down contact manager\r
+ this.getContactManager().doShutdown();\r
+ }\r
+\r
+ /**\r
+ * Enables the client\r
+ */\r
+ public void enableIsRunning () {\r
+ this.isRunning = true;\r
+ }\r
+\r
+ /**\r
+ * Current menu choice\r
+ * \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
+ /**\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
+ public Menu getMenu (final String menuType) {\r
+ // Default is not found\r
+ Menu menu = null;\r
+ \r
+ // Check array\r
+ if (this.getMenus().containsKey(menuType)) {\r
+ // Found!\r
+ menu = this.getMenus().get(menuType);\r
+ }\r
+ \r
+ // Return it\r
+ return menu;\r
+ }\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 isRunning () {\r
+ // In console client, 0 may have been used\r
+ return this.isRunning;\r
+ }\r
+\r
+ /**\r
+ * Disables running state, so the main loop can abort.\r
+ */\r
+ protected void disableIsRunning () {\r
+ this.isRunning = false;\r
+ }\r
+\r
+ /**\r
+ * Fills menu map with swing menus\r
+ */\r
+ protected abstract void fillMenuMap ();\r
+\r
+ /**\r
+ * Getter for menus map\r
+ * @return Map of all menus\r
+ */\r
+ protected final Map<String, Menu> getMenus () {\r
+ return this.menus;\r
+ }\r
+\r
+ /**\r
+ * Initializes contact manager\r
+ */\r
+ protected void initContactManager () {\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) this);\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
+ /**\r
+ * Shows given menu\r
+ *\r
+ * @param menuType Given menu to show\r
+ */\r
+ protected 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((Client) 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.client;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ * An interface for application clients\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface Client extends FrameworkInterface {\r
+\r
+ /**\r
+ * Displays a "box" for the address\r
+ *\r
+ * @param contact Contact to show address from\r
+ */\r
+ public void displayAddressBox (final Contact contact);\r
+\r
+ /**\r
+ * The user changes own name data\r
+ * @param contact \r
+ */\r
+ public void doChangeOwnNameData (final Contact contact);\r
+\r
+ /**\r
+ * The user changes own address data\r
+ *\r
+ * @param contact Contact instance to change\r
+ */\r
+ public void doChangeOwnAddressData (final Contact contact);\r
+\r
+ /**\r
+ * The user changes own other data\r
+ * \r
+ * @param contact Constact instance to change\r
+ */\r
+ public void doChangeOwnOtherData (final Contact contact);\r
+\r
+ /**\r
+ * Allows the user to enter own data\r
+ * \r
+ * @return Finished Contact instance\r
+ */\r
+ public Contact doEnterOwnData ();\r
+\r
+ /**\r
+ * Shuts down the client and therefore whole application\r
+ */\r
+ public void doShutdown ();\r
+\r
+ /**\r
+ * Displays a message to the user\r
+ *\r
+ * @param message Message to show to the user\r
+ */\r
+ public void outputMessage (final String message);\r
+\r
+ /**\r
+ * Displays a "box" for the name\r
+ *\r
+ * @param contact Contact to show name from\r
+ */\r
+ public void displayNameBox (final Contact contact);\r
+\r
+ /**\r
+ * Displays a "box" for other data\r
+ *\r
+ * @param contact Contact to show other data from\r
+ */\r
+ public void displayOtherDataBox (final Contact contact);\r
+\r
+ /**\r
+ * Let the user choose what to change on the address: [n]ame, [a]ddress,\r
+ * [o]ther\r
+ * \r
+ * @param contact Contact instance to let the user change data\r
+ * @throws UnhandledUserChoiceException If choice is not supported\r
+ */\r
+ public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException;\r
+\r
+ /**\r
+ * Asks the user for a choice and proceeds accordingly\r
+ * \r
+ * @throws UnhandledUserChoiceException If choice is not supported\r
+ */\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException ;\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
+ * \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. An empty\r
+ * string should be generally not allowed, but might be okay for e.g.\r
+ * company name.\r
+ * \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
+ * @param allowEmpty Whether empty strings are allowed\r
+ * @return Entered string by user or null if empty string is allowed\r
+ */\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty);\r
+\r
+ /**\r
+ * Reads an integer (int) from the user\r
+ * \r
+ * @param minimum Minimum allowed number\r
+ * @param maximum Maximum allowed number\r
+ * @param message Message to user\r
+ * @return Entered string by user or null if empty string is allowed\r
+ */\r
+ public int enterInt (final int minimum, final int maximum, final String message);\r
+\r
+ /**\r
+ * Setter for current menu choice\r
+ * \r
+ * @param currentMenu Current menu choice\r
+ */\r
+ public void setCurrentMenu (final String currentMenu);\r
+\r
+ /**\r
+ * Some "Getter" for menu item\r
+ * \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 client is still active by checking some\r
+ * conditions\r
+ * \r
+ * @return Whether the client is still active\r
+ */\r
+ public boolean isRunning();\r
+\r
+ /**\r
+ * Shows given menu entry in client\r
+ * \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
+ /**\r
+ * Inizializes this client\r
+ */\r
+ public void initClient ();\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.text.MessageFormat;\r
+import java.util.Arrays;\r
+import java.util.Scanner;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\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.contact.Contact;\r
+import org.mxchange.addressbook.contact.user.UserContact;\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
+ * 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 scanner instance\r
+ this.scanner = new Scanner(System.in);\r
+ }\r
+\r
+ /**\r
+ * Displays a textual address "box" of given contact\r
+ *\r
+ * @param contact Contact to show address for\r
+ */\r
+ @Override\r
+ public void displayAddressBox (final Contact contact) {\r
+ // Simple display ...\r
+ this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode()));\r
+ }\r
+\r
+ /**\r
+ * Displays a textual name "box" of given contact\r
+ *\r
+ * @param contact Contact to show name for\r
+ */\r
+ @Override\r
+ public void displayNameBox (final Contact contact) {\r
+ // Get translated gender as the user may want to see "Mr.", "Mrs."\r
+ String gender = contact.getTranslatedGender();\r
+\r
+ // Get company name\r
+ String companyName = contact.getCompanyName();\r
+\r
+ // If it is empty/null, then assume private contact\r
+ if ((companyName == null) || (companyName.isEmpty())) {\r
+ // Now put all together: gender, surname, family name\r
+ // @todo Use mask\r
+ this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName()));\r
+ } else {\r
+ // Company contact\r
+ this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName()));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Displays a textual other data "box" of given contact\r
+ *\r
+ * @param contact Contact to show other data for\r
+ */\r
+ @Override\r
+ public void displayOtherDataBox (final Contact contact) {\r
+ // Cellphone and such ...\r
+ this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnAddressData (final Contact contact) {\r
+ // Make sure it is own contact\r
+ if (!contact.isOwnContact()) {\r
+ // Not own contact\r
+ throw new IllegalArgumentException("Contact is not own data.");\r
+ }\r
+\r
+ // Own address data\r
+ String street = this.getContactManager().enterOwnStreet();\r
+\r
+ // Get zip code\r
+ int zipCode = this.getContactManager().enterOwnZipCode();\r
+\r
+ // Get city name\r
+ String city = this.getContactManager().enterOwnCity();\r
+\r
+ // Get country code\r
+ String countryCode = this.getContactManager().enterOwnCountryCode();\r
+\r
+ // Update address data\r
+ contact.updateAddressData(street, zipCode, city, countryCode);\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnNameData (final Contact contact) {\r
+ // Make sure it is own contact\r
+ if (!contact.isOwnContact()) {\r
+ // Not own contact\r
+ throw new IllegalArgumentException("Contact is not own data.");\r
+ }\r
+\r
+ // Gender:\r
+ char gender = this.getContactManager().enterOwnGender();\r
+\r
+ // Surname\r
+ String surname = this.getContactManager().enterOwnSurname();\r
+\r
+ // Family name\r
+ String familyName = this.getContactManager().enterOwnFamilyName();\r
+\r
+ // And company\r
+ String companyName = this.getContactManager().enterOwnCompanyName();\r
+\r
+ // Update contact instance\r
+ contact.updateNameData(gender, surname, familyName, companyName);\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnOtherData (final Contact contact) {\r
+ // Make sure it is own contact\r
+ if (!contact.isOwnContact()) {\r
+ // Not own contact\r
+ throw new IllegalArgumentException("Contact is not own data.");\r
+ }\r
+\r
+ // Phone number\r
+ String phoneNumber = this.getContactManager().enterOwnPhoneNumber();\r
+\r
+ // Phone number\r
+ String cellNumber = this.getContactManager().enterOwnCellNumber();\r
+\r
+ // Fax number\r
+ String faxNumber = this.getContactManager().enterOwnFaxNumber();\r
+\r
+ // Email address\r
+ String email = this.getContactManager().enterOwnEmailAddress();\r
+\r
+ // Comment\r
+ String comment = this.getContactManager().enterOwnComment();\r
+\r
+ // Update contact instance\r
+ contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment);\r
+ }\r
+\r
+ @Override\r
+ public Contact doEnterOwnData () {\r
+ // First ask for gender\r
+ char gender = this.getContactManager().enterOwnGender();\r
+\r
+ // 2nd for surname\r
+ String surname = this.getContactManager().enterOwnSurname();\r
+ \r
+ // And 3rd for family name\r
+ String familyName = this.getContactManager().enterOwnFamilyName();\r
+\r
+ // Company name ...\r
+ String companyName = this.getContactManager().enterOwnCompanyName();\r
+\r
+ // Construct UserContact instance\r
+ Contact contact = new UserContact(gender, surname, familyName, companyName);\r
+\r
+ // And return object\r
+ return contact;\r
+ }\r
+\r
+ /**\r
+ * Shutdown this client\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Parent call\r
+ super.doShutdown();\r
+\r
+ // @TODO Add other shutdown stuff\r
+ }\r
+\r
+ @Override\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
+ // Get all access keys from menu\r
+ char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());\r
+\r
+ // Output textural message and ask for a char as input\r
+ char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
+\r
+ // @TODO Rewrite this ugly switch() block\r
+ switch (choice) {\r
+ case '1': // Enter/add own data\r
+ this.getContactManager().doEnterOwnData();\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': // List contacts\r
+ this.getContactManager().listContacts();\r
+ break;\r
+ \r
+ case '5': // Search addresses\r
+ this.getContactManager().searchContacts();\r
+ break;\r
+\r
+ case '6': // Change other addess\r
+ this.getContactManager().changeOtherAddress();\r
+ break;\r
+ \r
+ case '7': // Delete other address\r
+ this.getContactManager().deleteOtherAddress();\r
+ break;\r
+\r
+ case '0': // Program exit\r
+ this.getApplication().doShutdown();\r
+ break;\r
+ \r
+ default:\r
+ // @TODO throw own exception\r
+ throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));\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 an integer (int) with a textural message from the user\r
+ * \r
+ * @param minimum Minimum allowed number\r
+ * @param maximum Maximum allowed number\r
+ * @param message Messager to display in console\r
+ * @return \r
+ */\r
+ @Override\r
+ public int enterInt (final int minimum, final int maximum, final String message) {\r
+ // Minimum should not be below zero\r
+ assert(minimum >= 0);\r
+ assert(maximum > minimum);\r
+\r
+ // Init input\r
+ int input = -1;\r
+\r
+ while ((input < minimum) || (input > maximum)) {\r
+ // Output message\r
+ System.out.print(message);\r
+\r
+ // Read integer from user\r
+ input = this.readInt();\r
+ }\r
+\r
+ // Return it\r
+ return input;\r
+ }\r
+\r
+ /**\r
+ * Reads a string of minimum and maximum length from the user\r
+ * \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
+ * @param allowEmpty Whether to allow empty string\r
+ * @return Entered string by user or null for empty strings\r
+ */\r
+ @Override\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
+ // Check on length, e.g. country codes are excactly 2 chars long\r
+ assert(maxLength >= minLength);\r
+\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) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (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
+ * Inizializes this client\r
+ */\r
+ @Override\r
+ public void initClient () {\r
+ // Init contact manager here\r
+ this.initContactManager();\r
+\r
+ // Fill menu map\r
+ this.fillMenuMap();\r
+ }\r
+\r
+ /**\r
+ * Displays textural message to the user\r
+ * @param message\r
+ */\r
+ @Override\r
+ public void outputMessage (final String message) {\r
+ System.out.println(message);\r
+ }\r
+\r
+ /**\r
+ * Shows textural menu on console\r
+ */\r
+ @Override\r
+ public void showCurrentMenu () {\r
+ this.showMenu(this.getCurrentMenu());\r
+ }\r
+\r
+ /**\r
+ * Shows given menu entry to user\r
+ * \r
+ * @param item Menu entry\r
+ */\r
+ @Override\r
+ public void showEntry (final SelectableMenuItem item) {\r
+ // Access key then text\r
+ this.outputMessage("[" + item.getAccessKey() + "] " + item.getText());\r
+ }\r
+\r
+ /**\r
+ * Shows a textural message to the user\r
+ */\r
+ @Override\r
+ public void showWelcome () {\r
+ this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle()));\r
+ this.outputMessage("");\r
+ this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
+ \r
+ // Debug message\r
+ this.getLogger().debug("Intro shown to user");\r
+ }\r
+\r
+ @Override\r
+ public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
+ // Ask the user for editing [name], [a]ddress or [other] data\r
+ 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) ");\r
+ \r
+ // @TODO Get rid of this ugly switch block, too\r
+ switch (choice) {\r
+ case 'n': // Name data\r
+ this.getContactManager().doChangeNameData(contact, this);\r
+ break;\r
+ \r
+ case 'a': // Address data\r
+ this.getContactManager().doChangeAddressData(contact, this);\r
+ break;\r
+ \r
+ case 'o': // Other data\r
+ this.getContactManager().doChangeOtherData(contact, this);\r
+ break;\r
+ \r
+ case 'x': // Exit this menu\r
+ // Ignored as it should go back\r
+ break;\r
+ \r
+ default:\r
+ // @TODO throw own exception\r
+ throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Reads one character\r
+ * \r
+ * @return A single character\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 an integer (int) from user\r
+ * \r
+ * @return An integer number\r
+ */\r
+ private int readInt () {\r
+ // First read a string\r
+ String input = this.readString();\r
+\r
+ // Init number with invalid value\r
+ int num = -1;\r
+\r
+ // Parse number, this can be risky\r
+ try {\r
+ num = Integer.parseInt(input);\r
+ } catch (final NumberFormatException e) {\r
+ this.outputMessage("Bitte geben Sie nur Zahlen ein!");\r
+ this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage()));\r
+ }\r
+\r
+ // Return read number\r
+ return num;\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
+ * Fills menu map with menu entries\r
+ */\r
+ @Override\r
+ protected final void fillMenuMap () {\r
+ // Initialize first (main) menu\r
+ Menu menu = new ConsoleMenu("main", this);\r
+ \r
+ // Add it\r
+ this.getMenus().put("main", menu);\r
+ }\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Menu class="javax.swing.JMenuBar" name="menuBar">
+ <Properties>
+ <Property name="name" type="java.lang.String" value="menuBar" noResource="true"/>
+ </Properties>
+ <SubComponents>
+ <Menu class="javax.swing.JMenu" name="mainMenu">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="focusable" type="boolean" value="false"/>
+ <Property name="name" type="java.lang.String" value="" noResource="true"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="exitProgram">
+ <Properties>
+ <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
+ <KeyStroke key="Alt+X"/>
+ </Property>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.exitProgram.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="exitProgram" noResource="true"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exitProgramActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ <Menu class="javax.swing.JMenu" name="addressbookMenu">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.addressbookMenu.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="addressbookMenu" noResource="true"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="addOwnData">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.addOwn.text" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="addOwn" noResource="true"/>
+ </Properties>
+ <AccessibilityProperties>
+ <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ </AccessibilityProperties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addOwnDataActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ </SubComponents>
+ </Menu>
+ </NonVisualComponents>
+ <Properties>
+ <Property name="defaultCloseOperation" type="int" value="0"/>
+ <Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+ <Connection code="AddressbookApplication.printableTitle()" type="code"/>
+ </Property>
+ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
+ <Color id="Standardcursor"/>
+ </Property>
+ <Property name="name" type="java.lang.String" value="main" noResource="true"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="menuBar" type="java.lang.String" value="menuBar"/>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosed" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitProgram"/>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
+ <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/>
+ <AuxValue name="FormSettings_formBundle" type="java.lang.String" value="org/mxchange/addressbook/localization/bundle"/>
+ <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
+ <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ </AuxValues>
+
+ <Layout>
+ <DimensionLayout dim="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Component id="statusPanel" max="32767" attributes="0"/>
+ <Component id="listAddressesPanel" alignment="0" pref="700" max="32767" attributes="0"/>
+ <Component id="toolBar" alignment="0" max="32767" attributes="0"/>
+ </Group>
+ </DimensionLayout>
+ <DimensionLayout dim="1">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="1" attributes="0">
+ <Component id="toolBar" min="-2" pref="25" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="listAddressesPanel" min="-2" max="-2" attributes="0"/>
+ <EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
+ <Component id="statusPanel" min="-2" pref="23" max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ </Layout>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="statusPanel">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
+ <EtchetBorder>
+ <Color PropertyName="highlight" blue="c0" green="c0" id="lightGray" palette="1" red="c0" type="palette"/>
+ <Color PropertyName="shadow" blue="99" green="99" red="99" type="rgb"/>
+ </EtchetBorder>
+ </Border>
+ </Property>
+ <Property name="autoscrolls" type="boolean" value="true"/>
+ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
+ <Color id="Standardcursor"/>
+ </Property>
+ <Property name="focusable" type="boolean" value="false"/>
+ <Property name="name" type="java.lang.String" value="status" noResource="true"/>
+ </Properties>
+ <AccessibilityProperties>
+ <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.status.AccessibleContext.accessibleName" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/client/gui/Bundle.properties" key="AddressbookFrame.status.AccessibleContext.accessibleDescription" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ </AccessibilityProperties>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
+ <Property name="axis" type="int" value="0"/>
+ </Layout>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="statusLabel">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/mxchange/addressbook/localization/bundle.properties" key="AddressbookFrame.statusLabel.text_1" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
+ </Property>
+ <Property name="horizontalTextPosition" type="int" value="2"/>
+ <Property name="name" type="java.lang.String" value="statusLabel" noResource="true"/>
+ </Properties>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JScrollPane" name="listAddressesPanel">
+ <Properties>
+ <Property name="name" type="java.lang.String" value="listAddressesPanel" noResource="true"/>
+ </Properties>
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTable" name="addressesTable">
+ <Properties>
+ <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+ <Connection code="new AddressTableModel(this.getClient())" type="code"/>
+ </Property>
+ <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
+ <TableColumnModel selectionModel="2"/>
+ </Property>
+ <Property name="columnSelectionAllowed" type="boolean" value="true"/>
+ <Property name="fillsViewportHeight" type="boolean" value="true"/>
+ <Property name="focusable" type="boolean" value="false"/>
+ <Property name="name" type="java.lang.String" value="addressesTable" noResource="true"/>
+ <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
+ <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
+ </Property>
+ </Properties>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JToolBar" name="toolBar">
+ <Properties>
+ <Property name="floatable" type="boolean" value="false"/>
+ <Property name="rollover" type="boolean" value="true"/>
+ <Property name="name" type="java.lang.String" value="toolBar" noResource="true"/>
+ </Properties>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+ </Container>
+ </SubComponents>
+</Form>
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.client.gui;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.ResourceBundle;
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.GroupLayout;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JToolBar;
+import javax.swing.KeyStroke;
+import javax.swing.LayoutStyle;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+import javax.swing.WindowConstants;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.application.AddressbookApplication;
+import org.mxchange.addressbook.application.Application;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.manager.contact.ManageableContact;
+import org.mxchange.addressbook.model.address.AddressTableModel;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame {
+ /**
+ * Class' logger
+ */
+ private final Logger LOG;
+
+ /**
+ * Client instance
+ */
+ private final Client client;
+
+ /**
+ * Own instance
+ */
+ private static ClientFrame self;
+
+ /**
+ * Bundle instance
+ */
+ private final ResourceBundle bundle;
+
+ /**
+ * Initialize object
+ */
+ {
+ LOG = LogManager.getLogger(this);
+ bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N
+ }
+
+ /**
+ * Creates an instance of this frame with a client instance
+ * @param client
+ */
+ private AddressbookFrame (final Client client) {
+ // Debug line
+ this.getLogger().debug("Initializing Swing frame ...");
+
+ // Set client here
+ this.client = client;
+ }
+
+ @Override
+ public Application getApplication () {
+ throw new UnsupportedOperationException("Not implemented.");
+ }
+
+ @Override
+ public final Client getClient () {
+ return this.client;
+ }
+
+ @Override
+ public ManageableContact getContactManager () {
+ throw new UnsupportedOperationException("Not implemented.");
+ }
+
+ @Override
+ public void initFrame () {
+ // Init components
+ this.initComponents();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings ("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ statusPanel = new JPanel();
+ statusLabel = new JLabel();
+ listAddressesPanel = new JScrollPane();
+ addressesTable = new JTable();
+ toolBar = new JToolBar();
+ menuBar = new JMenuBar();
+ mainMenu = new JMenu();
+ exitProgram = new JMenuItem();
+ addressbookMenu = new JMenu();
+ addOwnData = new JMenuItem();
+
+ setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ setTitle(AddressbookApplication.printableTitle());
+ setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ setName("main"); // NOI18N
+ addWindowListener(new WindowAdapter() {
+ public void windowClosed(WindowEvent evt) {
+ exitProgram(evt);
+ }
+ public void windowClosing(WindowEvent evt) {
+ AddressbookFrame.this.windowClosing(evt);
+ }
+ });
+
+ statusPanel.setBorder(BorderFactory.createEtchedBorder(Color.lightGray, new Color(153, 153, 153)));
+ statusPanel.setAutoscrolls(true);
+ statusPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ statusPanel.setFocusable(false);
+ statusPanel.setName("status"); // NOI18N
+ statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
+
+ ResourceBundle bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N
+ statusLabel.setText(bundle.getString("AddressbookFrame.statusLabel.text_1")); // NOI18N
+ statusLabel.setHorizontalTextPosition(SwingConstants.LEFT);
+ statusLabel.setName("statusLabel"); // NOI18N
+ statusPanel.add(statusLabel);
+
+ listAddressesPanel.setName("listAddressesPanel"); // NOI18N
+
+ addressesTable.setModel(new AddressTableModel(this.getClient()));
+ addressesTable.setColumnSelectionAllowed(true);
+ addressesTable.setFillsViewportHeight(true);
+ addressesTable.setFocusable(false);
+ addressesTable.setName("addressesTable"); // NOI18N
+ listAddressesPanel.setViewportView(addressesTable);
+ addressesTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
+
+ toolBar.setFloatable(false);
+ toolBar.setRollover(true);
+ toolBar.setName("toolBar"); // NOI18N
+
+ menuBar.setName("menuBar"); // NOI18N
+
+ ResourceBundle bundle1 = ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N
+ mainMenu.setText(bundle1.getString("AddressbookFrame.text")); // NOI18N
+ mainMenu.setFocusable(false);
+ mainMenu.setName(""); // NOI18N
+
+ exitProgram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK));
+ exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text_1")); // NOI18N
+ exitProgram.setName("exitProgram"); // NOI18N
+ exitProgram.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ exitProgramActionPerformed(evt);
+ }
+ });
+ mainMenu.add(exitProgram);
+
+ menuBar.add(mainMenu);
+
+ addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text_1")); // NOI18N
+ addressbookMenu.setName("addressbookMenu"); // NOI18N
+
+ addOwnData.setText(bundle1.getString("AddressbookFrame.addOwn.text")); // NOI18N
+ addOwnData.setName("addOwn"); // NOI18N
+ addOwnData.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ addOwnDataActionPerformed(evt);
+ }
+ });
+ addressbookMenu.add(addOwnData);
+ addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1")); // NOI18N
+
+ menuBar.add(addressbookMenu);
+
+ setJMenuBar(menuBar);
+
+ GroupLayout layout = new GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
+ .addComponent(statusPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(listAddressesPanel, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
+ .addComponent(toolBar, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ );
+ layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
+ .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(toolBar, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(listAddressesPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+ .addGap(1, 1, 1)
+ .addComponent(statusPanel, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
+ );
+
+ statusPanel.getAccessibleContext().setAccessibleName(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N
+ statusPanel.getAccessibleContext().setAccessibleDescription(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleDescription")); // NOI18N
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void exitProgramActionPerformed(ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed
+ // Close application instance
+ dispose();
+ }//GEN-LAST:event_exitProgramActionPerformed
+
+ private void addOwnDataActionPerformed(ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed
+ // Asks the user to enter own data
+ this.getClient().getContactManager().doEnterOwnData();
+ }//GEN-LAST:event_addOwnDataActionPerformed
+
+ private void windowClosing(WindowEvent evt) {//GEN-FIRST:event_windowClosing
+ // TODO add your handling code here:
+ dispose();
+ }//GEN-LAST:event_windowClosing
+
+ private void exitProgram(WindowEvent evt) {//GEN-FIRST:event_exitProgram
+ // TODO add your handling code here:
+ this.getClient().getApplication().doShutdown();
+ }//GEN-LAST:event_exitProgram
+
+ /**
+ * Setups the frame
+ *
+ * @param client Client instance
+ */
+ @Override
+ public void setupFrame (final Client client) {
+ // Has the user entered own data?
+ if (this.getClient().getContactManager().isOwnContactAdded()) {
+ // Debug message
+ this.getLogger().debug("Disabling menus: isOwnContactAdded()=false");
+
+ // Not entered yet, so enable menu
+ addOwnData.setEnabled(false);
+ }
+
+ /*
+ * Set the Nimbus look and feel
+ */
+ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+ /*
+ * If Nimbus (introduced in Java SE 6) is not available, stay with the
+ * default look and feel. For details see
+ * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (final ClassNotFoundException ex) {
+ this.getLogger().catching(ex);
+ } catch (final InstantiationException ex) {
+ this.getLogger().catching(ex);
+ } catch (final IllegalAccessException ex) {
+ this.getLogger().catching(ex);
+ } catch (final javax.swing.UnsupportedLookAndFeelException ex) {
+ this.getLogger().catching(ex);
+ }
+ //</editor-fold>
+
+ // All done here
+ statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text"));
+
+ // Debug line
+ this.getLogger().debug("Displaying form ...");
+
+ /*
+ * Create and display the form
+ */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run () {
+ AddressbookFrame.getSelfInstance(client).setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Singelton getter for this frame instance.
+ *
+ * @param client Client instance
+ * @return Returns a singelton instance of this frame
+ */
+ public static final ClientFrame getSelfInstance (final Client client) {
+ // Is it set?
+ if (!(self instanceof ClientFrame)) {
+ // Create new instance
+ self = new AddressbookFrame(client);
+ }
+
+ // Return instance
+ return self;
+ }
+
+ /**
+ * Getter for logger
+ *
+ * @return Logger
+ */
+ protected final Logger getLogger () {
+ return this.LOG;
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private JMenuItem addOwnData;
+ private JMenu addressbookMenu;
+ private JTable addressesTable;
+ private JMenuItem exitProgram;
+ private JScrollPane listAddressesPanel;
+ private JMenu mainMenu;
+ private JMenuBar menuBar;
+ private JLabel statusLabel;
+ private JPanel statusPanel;
+ private JToolBar toolBar;
+ // End of variables declaration//GEN-END:variables
+}
--- /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.gui;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.client.Client;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface ClientFrame extends FrameworkInterface {\r
+\r
+ /**\r
+ * From JFrame\r
+ * \r
+ * @param visible Set visibility\r
+ */\r
+ public void setVisible (boolean visible);\r
+\r
+ /**\r
+ * Setups the frame (and starts it). You have to call initFrame() before you\r
+ * can call this method.\r
+ * \r
+ * @param client Client instance\r
+ */\r
+ public void setupFrame (final Client client);\r
+\r
+ /**\r
+ * Initializes frame\r
+ */\r
+ public void initFrame ();\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.gui;\r
+\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\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.contact.Contact;\r
+import org.mxchange.addressbook.menu.Menu;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class SwingClient extends BaseClient implements Client {\r
+ /**\r
+ * Swing frame instance\r
+ */\r
+ private final ClientFrame frame;\r
+\r
+ /**\r
+ * Constructor with an Application instance.\r
+ * \r
+ * @param application Application instance\r
+ */\r
+ public SwingClient (final Application application) {\r
+ super();\r
+\r
+ // Set application instance\r
+ this.setApplication(application);\r
+\r
+ // Init frame instance\r
+ this.frame = AddressbookFrame.getSelfInstance(this);\r
+ }\r
+\r
+ @Override\r
+ public void displayAddressBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void displayNameBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void displayOtherDataBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnAddressData (Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnNameData (Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void doChangeOwnOtherData (Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public Contact doEnterOwnData () {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void doShutdown () {\r
+ // Parent call\r
+ super.doShutdown();\r
+\r
+ // @TODO Add other shutdown stuff\r
+ }\r
+\r
+ @Override\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
+ // Not implemented here\r
+ }\r
+\r
+ @Override\r
+ public char enterChar (final char[] validChars, String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public int enterInt (final int minimum, final int maximum, final String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public Menu getMenu (final String menuType) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ /**\r
+ * Returns a Swing menu item\r
+ * \r
+ * @param accessKey Key to access the menu\r
+ * @param text Text to show to user\r
+ * @return A SelectableMenuItem\r
+ */\r
+ @Override\r
+ public SelectableMenuItem getMenuItem (final char accessKey, final String text) {\r
+ // Returns null as the menu is now no longer controlled here.\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Inizializes this client\r
+ */\r
+ @Override\r
+ public void initClient () {\r
+ // Init contact manager here\r
+ this.initContactManager();\r
+\r
+ // Init frame\r
+ this.frame.initFrame();\r
+\r
+ // Now start the frame\r
+ this.frame.setupFrame(this);\r
+ }\r
+\r
+ @Override\r
+ public void outputMessage (final String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void showCurrentMenu () {\r
+ // Not implemented here\r
+ }\r
+\r
+ @Override\r
+ public void showEntry (final SelectableMenuItem item) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void showWelcome () {\r
+ // Not implemented here\r
+ }\r
+\r
+ @Override\r
+ public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ /**\r
+ * Fills menu map with swing menus\r
+ */\r
+ @Override\r
+ protected final void fillMenuMap () {\r
+ // Nothing to fill here as the Swing frame is handling this all\r
+ throw new UnsupportedOperationException("Not implemented.");\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 java.util.Objects;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.client.Client;\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 long zipCode;\r
+\r
+ /**\r
+ * No instances can be created of this class\r
+ */\r
+ protected BaseContact () {\r
+ super();\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
+ * @todo Needs a lot improvements\r
+ */\r
+ @Override\r
+ public boolean equals (Object object) {\r
+ // Is it same type?\r
+ if (!(object instanceof BaseContact)) {\r
+ // Not equal types\r
+ return false;\r
+ } else if (!(object instanceof Contact)) {\r
+ // Not correct interface\r
+ return false;\r
+ }\r
+\r
+ // Try to cast\r
+ Contact contact = (Contact) object;\r
+ \r
+ // Now test some data @todo Definedly needs improvement\r
+ return ((this.getGender() == contact.getGender())\r
+ && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))\r
+ && (this.getFamilyName().toLowerCase().equals(contact.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
+ * "Serializes" this object into a CSV string (this time with semicolons)\r
+ *\r
+ * @return "CSV-serialized" version of the stored data\r
+ */\r
+ public String getCsvStringFromStoreableObject () {\r
+ // Get all together\r
+ String csvString = String.format(\r
+ "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",\r
+ this.isOwnContact(),\r
+ this.getGender(),\r
+ this.getSurname(),\r
+ this.getFamilyName(),\r
+ this.getCompanyName(),\r
+ this.getStreet(),\r
+ this.getZipCode(),\r
+ this.getCity(),\r
+ this.getCountryCode(),\r
+ this.getPhoneNumber(),\r
+ this.getFaxNumber(),\r
+ this.getCellphoneNumber(),\r
+ this.getEmailAddress(),\r
+ this.getBirthday(),\r
+ this.getComment()\r
+ );\r
+ \r
+ // Then return it\r
+ return csvString;\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
+ * Some "getter" for a translated/human-readable gender\r
+ * @return gender Human-readable gender\r
+ */\r
+ public String getTranslatedGender () {\r
+ // Default init\r
+ String translated = null;\r
+\r
+ // "Translate" it\r
+ switch (this.getGender()) {\r
+ case 'M': // Mr.\r
+ translated = "Herr";\r
+ break;\r
+\r
+ case 'F': // Mrs.\r
+ translated = "Frau";\r
+ break;\r
+\r
+ case 'C': // "Company"\r
+ translated = "Firma";\r
+ break;\r
+\r
+ default: // Unsupported\r
+ this.getLogger().error("Gender " + this.getGender() + " not supported.");\r
+ break;\r
+ }\r
+\r
+ // Return it\r
+ return translated;\r
+ }\r
+\r
+ /**\r
+ * ZIP code\r
+ *\r
+ * @return the zipCode\r
+ */\r
+ public long 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 long zipCode) {\r
+ this.zipCode = zipCode;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode () {\r
+ int hash = 7;\r
+ hash = 79 * hash + Objects.hashCode(this.getFamilyName());\r
+ hash = 79 * hash + this.getGender();\r
+ hash = 79 * hash + Objects.hashCode(this.getSurname());\r
+ return hash;\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
+ /**\r
+ * Shows this contact to the user\r
+ *\r
+ * @param client Client instance to use\r
+ */\r
+ public void show (final Client client) {\r
+ // Display name "box"\r
+ client.displayNameBox((Contact) this);\r
+\r
+ // Display address "box"\r
+ client.displayAddressBox((Contact) this);\r
+\r
+ // Display other data "box"\r
+ client.displayOtherDataBox((Contact) this);\r
+ }\r
+\r
+ /**\r
+ * Updates address data in this Contact instance\r
+ *\r
+ * @param street Street\r
+ * @param zipCode ZIP code\r
+ * @param city City\r
+ * @param countryCode Country code\r
+ */\r
+ public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {\r
+ // Set all\r
+ if (street != null) {\r
+ this.setStreet(street);\r
+ }\r
+ if (zipCode > 0) {\r
+ this.setZipCode(zipCode);\r
+ }\r
+ if (city != null) {\r
+ this.setCity(city);\r
+ }\r
+ if (countryCode != null) {\r
+ this.setCountryCode(countryCode);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates name data in this Contact instance\r
+ * @param gender Gender (M, F, C)\r
+ * @param surname Surname\r
+ * @param familyName Family name\r
+ * @param companyName Company name\r
+ */\r
+ public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {\r
+ // Set all\r
+ this.setGender(gender);\r
+ if (surname != null) {\r
+ this.setSurname(surname);\r
+ }\r
+ if (familyName != null) {\r
+ this.setFamilyName(familyName);\r
+ }\r
+ if (companyName != null) {\r
+ this.setCompanyName(companyName);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates other data in this Contact instance\r
+ * \r
+ * @param phoneNumber Phone number\r
+ * @param cellphoneNumber Cellphone number\r
+ * @param faxNumber Fax number\r
+ * @param emailAddress Email address\r
+ * @param birthday Birth day\r
+ * @param comment Comments\r
+ */\r
+ public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {\r
+ // Set all\r
+ if (phoneNumber != null) {\r
+ this.setPhoneNumber(phoneNumber);\r
+ }\r
+ if (cellphoneNumber != null) {\r
+ this.setCellphoneNumber(cellphoneNumber);\r
+ }\r
+ if (faxNumber != null) {\r
+ this.setFaxNumber(faxNumber);\r
+ }\r
+ if (emailAddress != null) {\r
+ this.setEmailAddress(emailAddress);\r
+ }\r
+ if (birthday != null) {\r
+ this.setBirthday(birthday);\r
+ }\r
+ if (comment != null) {\r
+ this.setComment(comment);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Enables the flag "own data" which signals that this contact is the user's\r
+ * own data.\r
+ */\r
+ protected void enableFlagOwnContact () {\r
+ this.ownContact = true;\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
+import org.mxchange.addressbook.client.Client;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface Contact extends FrameworkInterface {\r
+\r
+ /**\r
+ * Some "getter" for translated gender of the contact\r
+ * @return Translated / human-readable gender\r
+ */\r
+ public String getTranslatedGender();\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 long 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
+ /**\r
+ * Shows the contact to the user\r
+ *\r
+ * @param client Client instance to call back\r
+ */\r
+ public void show (final Client client);\r
+\r
+ /**\r
+ * Updates address data in this Contact instance\r
+ * \r
+ * @param street Street\r
+ * @param zipCode ZIP code\r
+ * @param city City\r
+ * @param countryCode Country code\r
+ */\r
+ public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode);\r
+\r
+ /**\r
+ * Updates name data in this Contact instance\r
+ * \r
+ * @param gender Gender (M, F, C)\r
+ * @param surname Surname\r
+ * @param familyName Family name\r
+ * @param companyName Company name\r
+ */\r
+ public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);\r
+\r
+ /**\r
+ * Updates other data in this Contact instance\r
+ * \r
+ * @param phoneNumber Phone number\r
+ * @param cellNumber Cellphone number\r
+ * @param faxNumber Fax number\r
+ * @param email Email address\r
+ * @param birthday Birthday\r
+ * @param comment Comments\r
+ */\r
+ public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String birthday, final String comment);\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
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\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, StoreableCsv {\r
+\r
+ /**\r
+ * Default constructor, may only be used from database backend\r
+ */\r
+ public BookContact () {\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.contact.user;\r
+\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.contact.book.BookContact;\r
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\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, StoreableCsv {\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
+ * @param companyName Company name\r
+ * @todo Add validation of data\r
+ */\r
+ public UserContact (final char gender, final String surname, final String familyName, final String companyName) {\r
+ // Make sure all constructors are called\r
+ this();\r
+\r
+ this.setGender(gender);\r
+ this.setSurname(surname);\r
+ this.setFamilyName(familyName);\r
+ this.setCompanyName(companyName);\r
+ }\r
+\r
+ /**\r
+ * Default constructor, may only be used from database backend\r
+ */\r
+ public UserContact () {\r
+ this.enableFlagOwnContact();\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.database.backend;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ * Generall database backend\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class BaseDatabaseBackend extends BaseFrameworkSystem {\r
+ /**\r
+ * No instances from this class\r
+ */\r
+ protected BaseDatabaseBackend () {\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.database.backend;\r
+\r
+import java.io.IOException;\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+\r
+/**\r
+ * A generic interface for database frontends\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface DatabaseBackend extends FrameworkInterface {\r
+\r
+ /**\r
+ * Shuts down this backend\r
+ */\r
+ public void doShutdown ();\r
+\r
+ /**\r
+ * Rewinds backend\r
+ */\r
+ public void rewind ();\r
+\r
+ /**\r
+ * Get length of underlaying file\r
+ *\r
+ * @return Length of underlaying file\r
+ */\r
+ public long length ();\r
+\r
+ /**\r
+ * Stores an object in the database.\r
+ * \r
+ * @param object Object to store in database\r
+ * @throws java.io.IOException From inner class\r
+ */\r
+ public void store (final Storeable object) throws IOException;\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.database.backend.csv;\r
+\r
+import java.util.Iterator;\r
+import org.mxchange.addressbook.BadTokenException;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public interface CsvBackend extends DatabaseBackend {\r
+\r
+ /**\r
+ * Gets an iterator for contacts\r
+ * \r
+ * @return Iterator for contacts\r
+ */\r
+ public Iterator<Contact> contactIterator () throws BadTokenException;\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.database.backend.csv;\r
+\r
+import java.io.DataOutput;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.RandomAccessFile;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.StringTokenizer;\r
+import org.mxchange.addressbook.BadTokenException;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.contact.book.BookContact;\r
+import org.mxchange.addressbook.contact.user.UserContact;\r
+import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\r
+\r
+/**\r
+ * A database backend with CSV file as storage implementation\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend {\r
+ /**\r
+ * Output stream for this storage engine\r
+ */\r
+ private RandomAccessFile storageFile;\r
+\r
+ /**\r
+ * Constructor with table name\r
+ * \r
+ * @param tableName Name of "table"\r
+ */\r
+ public CsvDatabaseBackend (final String tableName) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName));\r
+\r
+ // Set table name here, too\r
+ this.setTableName(tableName);\r
+\r
+ // Construct file name\r
+ String fileName = String.format("data/table_%s.csv", tableName);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));\r
+\r
+ try {\r
+ // Try to initialize the storage (file instance)\r
+ this.storageFile = new RandomAccessFile(fileName, "rw");\r
+ } catch (final FileNotFoundException ex) {\r
+ // Did not work\r
+ this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString()));\r
+ System.exit(1);\r
+ }\r
+\r
+ // Output message\r
+ this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName));\r
+ }\r
+\r
+ /**\r
+ * Gets an iterator for contacts\r
+ * \r
+ * @return Iterator for contacts\r
+ * @throws org.mxchange.addressbook.BadTokenException If the underlaying method has found an invalid token\r
+ */\r
+ @Override\r
+ public Iterator<Contact> contactIterator () throws BadTokenException {\r
+ /*\r
+ * Then read the file into RAM (yes, not perfect for >1000 entries ...)\r
+ * and get a List back.\r
+ */\r
+ List<Contact> list = this.readContactList();\r
+\r
+ // Get iterator from list and return it\r
+ return list.iterator();\r
+ }\r
+\r
+ /**\r
+ * Shuts down this backend\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ try {\r
+ // Close file\r
+ this.storageFile.close();\r
+ } catch (final IOException ex) {\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Get length of underlaying file\r
+ *\r
+ * @return Length of underlaying file\r
+ */\r
+ @Override\r
+ public long length () {\r
+ long length = 0;\r
+ \r
+ try {\r
+ length = this.storageFile.length();\r
+ this.getLogger().debug(MessageFormat.format("length={0}", length));\r
+ } catch (final IOException ex) {\r
+ // Length cannot be determined\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+ \r
+ // Return result\r
+ this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length));\r
+ return length;\r
+ }\r
+\r
+ /**\r
+ * Rewinds backend\r
+ */\r
+ @Override\r
+ public void rewind (){\r
+ this.getLogger().trace("CALLED!");\r
+\r
+ try {\r
+ // Rewind underlaying database file\r
+ this.storageFile.seek(0);\r
+ } catch (final IOException ex) {\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+\r
+ this.getLogger().trace("EXIT!");\r
+ }\r
+\r
+ /**\r
+ * Stores given object by "visiting" it\r
+ *\r
+ * @param object An object implementing Storeable\r
+ * @throws java.io.IOException From "inner" class\r
+ */\r
+ @Override\r
+ public void store (final Storeable object) throws IOException {\r
+ // Make sure the instance is there (DataOutput flawor)\r
+ assert(this.storageFile instanceof DataOutput);\r
+\r
+ // Try to cast it, this will fail if the interface is not implemented\r
+ StoreableCsv csv = (StoreableCsv) object;\r
+\r
+ // Now get a string from the object that needs to be stored\r
+ String str = csv.getCsvStringFromStoreableObject();\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));\r
+\r
+ // The string is now a valid CSV string\r
+ this.storageFile.writeBytes(str);\r
+ }\r
+\r
+ /**\r
+ * Adds given contact to list\r
+ * \r
+ * @param contact Contact instance to add\r
+ * @param list List instance\r
+ */\r
+ private void addContactToList (final Contact contact, final List<Contact> list) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("contact={0}", contact));\r
+\r
+ // Is the contact read?\r
+ if (contact instanceof Contact) {\r
+ // Then add it\r
+ boolean added = list.add(contact);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));\r
+\r
+ // Has it been added?\r
+ if (!added) {\r
+ // Not added\r
+ this.getLogger().warn("Contact object has not been added.");\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Checks whether end of file has been reached\r
+ * \r
+ * @return Whether lines are left to read\r
+ */\r
+ private boolean isEndOfFile () {\r
+ // Default is EOF\r
+ boolean isEof = true;\r
+\r
+ try {\r
+ isEof = (this.storageFile.getFilePointer() >= this.length());\r
+ } catch (final IOException ex) {\r
+ // Length cannot be determined\r
+ this.getLogger().catching(ex);\r
+ }\r
+\r
+ // Return status\r
+ this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof));\r
+ return isEof;\r
+ }\r
+\r
+ /**\r
+ * Reads the database file, if available, and adds all read lines into\r
+ * the list.\r
+ * \r
+ * @return A list with Contact instances\r
+ */\r
+ private List<Contact> readContactList () throws BadTokenException {\r
+ this.getLogger().trace("CALLED!");\r
+\r
+ // First rewind\r
+ this.rewind();\r
+\r
+ // Get file size and divide it by 140 (possible average length of one line)\r
+ int lines = Math.round(this.length() / 140 + 0.5f);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("lines={0}", lines));\r
+\r
+ // Instance list\r
+ // @TODO The maximum length could be guessed from file size?\r
+ List<Contact> list = new ArrayList<>(lines);\r
+\r
+ // Init variables\r
+ StringTokenizer tokenizer;\r
+ String line;\r
+\r
+ // Read all lines\r
+ while (!this.isEndOfFile()) {\r
+ // Then read a line\r
+ line = this.readLine();\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("line={0}", line));\r
+\r
+ // Then tokenize it\r
+ // @TODO Move this into separate method\r
+ tokenizer = new StringTokenizer(line, ";");\r
+\r
+ // Count round\r
+ int count = 0;\r
+\r
+ // Init contact object\r
+ Contact contact = null;\r
+\r
+ // The tokens are now available, so get all\r
+ while (tokenizer.hasMoreElements()) {\r
+ // Get next token\r
+ String token = tokenizer.nextToken();\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("token={0}", token));\r
+\r
+ // Verify token, it must have double-quotes on each side\r
+ if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {\r
+ // Something bad was read\r
+ throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));\r
+ }\r
+\r
+ // All fine, so remove it\r
+ String strippedToken = token.substring(1, token.length() - 1);\r
+\r
+ // Is the string's content "null"?\r
+ if (strippedToken.equals("null")) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken));\r
+\r
+ // This needs to be set to null\r
+ strippedToken = null;\r
+ }\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));\r
+\r
+ // Init number/string data values\r
+ String strData = strippedToken;\r
+ Long num = null;\r
+ Boolean bool = null;\r
+ char gender = '?';\r
+ \r
+ // Now, let's try a number check, if no null\r
+ if (strippedToken != null) {\r
+ // Okay, no null, maybe the string bears a decimal number?\r
+ try {\r
+ num = Long.valueOf(strippedToken);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken));\r
+ } catch (final NumberFormatException ex) {\r
+ // No number, then set default\r
+ num = null;\r
+ }\r
+ }\r
+ \r
+ // Now, let's try a boolean check, if no null\r
+ if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken));\r
+\r
+ // parseBoolean() is relaxed, so no exceptions\r
+ bool = Boolean.valueOf(strippedToken);\r
+ }\r
+ \r
+ // Now, let's try a boolean check, if no null\r
+ if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {\r
+ // Get first character\r
+ gender = strippedToken.charAt(0);\r
+ }\r
+\r
+ // Now it depends on the counter which position we need to check\r
+ switch (count) {\r
+ case 0: // isOwnContact\r
+ assert((bool instanceof Boolean));\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("bool={0}", bool));\r
+\r
+ // Is it own contact?\r
+ if (true == bool) {\r
+ // Debug message\r
+ this.getLogger().debug("Creating UserContact object ...");\r
+\r
+ // Own entry\r
+ contact = new UserContact();\r
+ } else {\r
+ // Debug message\r
+ this.getLogger().debug("Creating BookContact object ...");\r
+\r
+ // Other contact\r
+ contact = new BookContact();\r
+ }\r
+ break;\r
+\r
+ case 1: // Gender\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+ assert(gender != '?') : "Gender is not detected.";\r
+\r
+ // Update data\r
+ contact.updateNameData(gender, null, null, null);\r
+ break;\r
+\r
+ case 2: // Surname\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+ assert(gender != '?') : "Gender is not detected.";\r
+\r
+ // Update data\r
+ contact.updateNameData(gender, strippedToken, null, null);\r
+ break;\r
+\r
+ case 3: // Family name\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+ assert(gender != '?') : "Gender is not detected.";\r
+\r
+ // Update data\r
+ contact.updateNameData(gender, null, strippedToken, null);\r
+ break;\r
+\r
+ case 4: // Company name\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+ assert(gender != '?') : "Gender is not detected.";\r
+\r
+ // Update data\r
+ contact.updateNameData(gender, null, null, strippedToken);\r
+ break;\r
+\r
+ case 5: // Street number\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateAddressData(strippedToken, 0, null, null);\r
+ break;\r
+\r
+ case 6: // ZIP code\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateAddressData(null, num, null, null);\r
+ break;\r
+\r
+ case 7: // City name\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateAddressData(null, 0, strippedToken, null);\r
+ break;\r
+\r
+ case 8: // Country code\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateAddressData(null, 0, null, strippedToken);\r
+ break;\r
+\r
+ case 9: // Phone number\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(strippedToken, null, null, null, null, null);\r
+ break;\r
+\r
+ case 10: // Fax number\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(null, strippedToken, null, null, null, null);\r
+ break;\r
+\r
+ case 11: // Cellphone number\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(null, null, strippedToken, null, null, null);\r
+ break;\r
+\r
+ case 12: // Email address\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(null, null, null, strippedToken, null, null);\r
+ break;\r
+\r
+ case 13: // Birthday\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(null, null, null, null, strippedToken, null);\r
+ break;\r
+\r
+ case 14: // Birthday\r
+ assert(contact instanceof Contact) : "First token was not boolean";\r
+\r
+ // Update data\r
+ contact.updateOtherData(null, null, null, null, null, strippedToken);\r
+ break;\r
+\r
+ default: // New data entry\r
+ this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count));\r
+ break;\r
+ }\r
+\r
+ // Increment counter for next round\r
+ count++;\r
+ }\r
+\r
+ // Add contact\r
+ this.addContactToList(contact, list);\r
+ }\r
+\r
+ // Return finished list\r
+ this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size()));\r
+ return list;\r
+ }\r
+\r
+ /**\r
+ * Reads a line from file base\r
+ *\r
+ * @return Read line from file\r
+ */\r
+ private String readLine () {\r
+ // Init input\r
+ String input = null;\r
+\r
+ try {\r
+ input = this.storageFile.readLine();\r
+ } catch (final IOException ex) {\r
+ this.getLogger().catching(ex);\r
+ }\r
+\r
+ // Return read string or null\r
+ return input;\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.database.frontend;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
+import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend;\r
+\r
+/**\r
+ * General database frontend class\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseDatabaseFrontend extends BaseFrameworkSystem {\r
+\r
+ /**\r
+ * Instance for database backend\r
+ */\r
+ private DatabaseBackend backend;\r
+\r
+ /**\r
+ * No instances from this class\r
+ */\r
+ protected BaseDatabaseFrontend () {\r
+ }\r
+\r
+ /**\r
+ * Instance for database backend\r
+ * \r
+ * @return the backend\r
+ */\r
+ protected DatabaseBackend getBackend () {\r
+ return this.backend;\r
+ }\r
+\r
+ /**\r
+ * Instance for database backend\r
+ * \r
+ * @param backend the backend to set\r
+ */\r
+ protected void setBackend (final DatabaseBackend backend) {\r
+ this.backend = backend;\r
+ }\r
+\r
+ /**\r
+ * Initialize backend\r
+ */\r
+ protected void initBackend () {\r
+ // Instance backend\r
+ this.backend = new CsvDatabaseBackend(this.getTableName());\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.database.frontend;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ * A generic interface for database frontends\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface DatabaseWrapper 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.database.frontend.contact;\r
+\r
+import java.io.IOException;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import org.mxchange.addressbook.BadTokenException;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.backend.csv.CsvBackend;\r
+import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+import org.mxchange.addressbook.manager.contact.ContactManager;\r
+\r
+/**\r
+ * Stores and retrieves Contact instances\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {\r
+ /**\r
+ * Constructor which accepts a contact manager\r
+ * @param manager\r
+ */\r
+ public ContactDatabaseFrontend (final ContactManager manager) {\r
+ // Call own constructor\r
+ this();\r
+ \r
+ // Set contact manager\r
+ this.setContactManager(manager);\r
+ }\r
+\r
+ /**\r
+ * Basic constrcutor\r
+ */\r
+ protected ContactDatabaseFrontend () {\r
+ super();\r
+\r
+ // Set "table" name\r
+ this.setTableName("contacts");\r
+\r
+ // Initalize backend\r
+ this.initBackend();\r
+ }\r
+\r
+ /**\r
+ * Shuts down the database layer\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shutdown backend\r
+ this.getBackend().doShutdown();\r
+ }\r
+\r
+ /**\r
+ * Flushes all contact entries to database\r
+ */\r
+ @Override\r
+ public void flushAllContacts () {\r
+ // Get full list\r
+ List<Contact> contacts = this.getContactManager().getList();\r
+\r
+ // Get iterator\r
+ Iterator<Contact> iterator = contacts.iterator();\r
+\r
+ // Rewind backend\r
+ this.getBackend().rewind();\r
+\r
+ // Get all entries\r
+ while (iterator.hasNext()) {\r
+ // Get next entry\r
+ Contact contact = iterator.next();\r
+\r
+ try {\r
+ // Store this entry\r
+ this.getBackend().store((Storeable) contact);\r
+ } catch (final IOException ex) {\r
+ // Should not happen?\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Reads all contacts from database backend and handles them over to the\r
+ * contact manager\r
+ */\r
+ @Override\r
+ public void readAllContacts () {\r
+ // Get iterator and case it\r
+ CsvBackend backend = (CsvBackend) this.getBackend();\r
+ \r
+ // First rewind to beginning\r
+ this.getBackend().rewind();\r
+\r
+ // Get backend iterator\r
+ Iterator<Contact> iterator = null;\r
+ try {\r
+ iterator = backend.contactIterator();\r
+ } catch (final BadTokenException ex) {\r
+ this.getLogger().catching(ex);\r
+ System.exit(1);\r
+ }\r
+\r
+ // Read all entries\r
+ while (iterator.hasNext()) {\r
+ // Get next entry\r
+ Contact contact = iterator.next();\r
+\r
+ // Add contact instance to manager\r
+ this.getContactManager().addContact(contact);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Häder\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.database.frontend.contact;\r
+\r
+import org.mxchange.addressbook.database.frontend.DatabaseWrapper;\r
+\r
+/**\r
+ *\r
+ * @author Roland Häder\r
+ */\r
+public interface ContactWrapper extends DatabaseWrapper {\r
+\r
+ /**\r
+ * Shuts down the database layer\r
+ */\r
+ public void doShutdown ();\r
+\r
+ /**\r
+ * Flushes all contact entries to database\r
+ */\r
+ public void flushAllContacts ();\r
+\r
+ /**\r
+ * Reads all contacts from database backend and handles them over to the\r
+ * contact manager\r
+ */\r
+ public void readAllContacts ();\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.database.storage;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ *An interface for objects being stored in databases\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface Storeable extends FrameworkInterface {\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.database.storage.csv;\r
+\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+\r
+/**\r
+ *\r
+ * @author KLC\r
+ */\r
+public interface StoreableCsv extends Storeable {\r
+ /**\r
+ * Getter for a CSV-formated string from object\r
+ * @return \r
+ */\r
+ public String getCsvStringFromStoreableObject ();\r
+}\r
--- /dev/null
+# 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
+AddressbookFrame.addOwn.text=Eigene Adresse hinzuf\u00fcgen\r
+AddressbookFrame.text=Datei\r
+AddressbookFrame.statusLabel.text=Initialisiere ...\r
+AddressbookFrame.status.text=Willkommen ...\r
+AddressbookFrame.status.AccessibleContext.accessibleName=\r
+AddressbookFrame.status.AccessibleContext.accessibleDescription=\r
+AddressbookFrame.exitProgram.toolTipText=Beendet das Programm sauber\r
+AddressbookFrame.exitProgram.text=Programm beenden\r
+AddressbookFrame.addressbookMenu.text=Adressbuch\r
+AddressbookFrame.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten\r
+AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn\r
+AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription=\r
+AddressbookFrame.status.done.text=Fertig.\r
+AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1=null\r
+AddressbookFrame.addressbookMenu.text_1=null\r
+AddressbookFrame.exitProgram.text_1=null\r
+AddressbookFrame.statusLabel.text_1=null\r
--- /dev/null
+# 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
+AddressbookFrame.addOwn.text=Add own address\r
+AddressbookFrame.text=File\r
+AddressbookFrame.statusLabel.text=Initializing ...\r
+AddressbookFrame.status.text=Welcome ...\r
+AddressbookFrame.status.AccessibleContext.accessibleName=\r
+AddressbookFrame.status.AccessibleContext.accessibleDescription=\r
+AddressbookFrame.exitProgram.toolTipText=Exits the program cleanly.\r
+AddressbookFrame.exitProgram.text=Exit program\r
+AddressbookFrame.addressbookMenu.text=Addressbook\r
+AddressbookFrame.addOwnData.toolTipText=Allows the user to add own address data\r
+AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn\r
+AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription=\r
+AddressbookFrame.status.done.text=Done.\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.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend;\r
+import org.mxchange.addressbook.database.frontend.contact.ContactWrapper;\r
+import org.mxchange.addressbook.manager.BaseManager;\r
+\r
+/**\r
+ * A manager for contacts, please note that this implementation loads the whole\r
+ * list into RAM.\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
+ * A ContactWrapper instance\r
+ */\r
+ private final ContactWrapper contactDatabase;\r
+\r
+ /**\r
+ * A list of 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
+ // Init database connection\r
+ this.contactDatabase = new ContactDatabaseFrontend(this);\r
+\r
+ // Read all entries\r
+ this.contactDatabase.readAllContacts();\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 instance to list\r
+ *\r
+ * @param contact Contact instance to add\r
+ */\r
+ @Override\r
+ public void addContact (final Contact 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().outputMessage("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
+ // Display contact\r
+ contact.show(this.getClient());\r
+ \r
+ try {\r
+ // Ask user what to change\r
+ this.getClient().userChooseChangeContactData(contact);\r
+ } catch (final UnhandledUserChoiceException ex) {\r
+ this.getLogger().catching(ex);\r
+ }\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
+ * Let the user change address data\r
+ * \r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ */\r
+ @Override\r
+ public void doChangeAddressData (final Contact contact, final Client client) {\r
+ // First display it again\r
+ client.displayAddressBox(contact);\r
+\r
+ // Is it own data?\r
+ if (contact.isOwnContact()) {\r
+ // Deligate to client\r
+ this.getClient().doChangeOwnAddressData(contact);\r
+ } else {\r
+ // Other contact's address data to change\r
+ throw new UnsupportedOperationException("Changing contact entries not finished.");\r
+ }\r
+\r
+ // Flush whole list\r
+ this.flush();\r
+ }\r
+\r
+ /**\r
+ * Let the user change "name data"\r
+ * \r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ */\r
+ @Override\r
+ public void doChangeNameData (final Contact contact, final Client client) {\r
+ // First display them again\r
+ client.displayNameBox(contact);\r
+\r
+ // Is this own data?\r
+ if (contact.isOwnContact()) {\r
+ // Re-ask own data\r
+ this.getClient().doChangeOwnNameData(contact);\r
+ } else {\r
+ // Then re-ask them ...\r
+ throw new UnsupportedOperationException("Changing contact entries not finished.");\r
+ }\r
+\r
+ // Flush whole list\r
+ this.flush();\r
+ }\r
+\r
+ /**\r
+ * Let the user change other data\r
+ *\r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ * @todo Didn't handle birthday\r
+ */\r
+ @Override\r
+ public void doChangeOtherData (final Contact contact, final Client client) {\r
+ // First display them again\r
+ this.getClient().displayOtherDataBox(contact);\r
+\r
+ // Is this own data?\r
+ if (contact.isOwnContact()) {\r
+ // Re-ask own data\r
+ this.getClient().doChangeOwnOtherData(contact);\r
+ } else {\r
+ // Then re-ask them ...\r
+ throw new UnsupportedOperationException("Changing contact entries not finished.");\r
+ }\r
+\r
+ // Flush whole list\r
+ this.flush();\r
+ }\r
+\r
+ /**\r
+ * Asks user for own data\r
+ */\r
+ @Override\r
+ public void doEnterOwnData () {\r
+ // Deligate this call to the client\r
+ Contact contact = this.getClient().doEnterOwnData();\r
+\r
+ // Add it to contact "book"\r
+ this.registerContact(contact);\r
+ }\r
+\r
+ /**\r
+ * Shuts down this contact manager\r
+ */\r
+ @Override\r
+ public void doShutdown () {\r
+ // Shut down the database layer\r
+ this.contactDatabase.doShutdown();\r
+ }\r
+\r
+ /**\r
+ * Asks the user for his/her cellphone number\r
+ * \r
+ * @return User's cellphone number\r
+ */\r
+ @Override\r
+ public String enterOwnCellNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for his/her city's name\r
+ *\r
+ * @return City's name of the user\r
+ */\r
+ @Override\r
+ public String enterOwnCity () {\r
+ return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for his/her city's name\r
+ *\r
+ * @return City's name of the user\r
+ */\r
+ @Override\r
+ public String enterOwnComment () {\r
+ return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for his/her company name\r
+ * \r
+ * @return User's company name\r
+ */\r
+ @Override\r
+ public String enterOwnCompanyName () {\r
+ return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks user for his/her own country code\r
+ * \r
+ * @return User's own country code\r
+ */\r
+ @Override\r
+ public String enterOwnCountryCode () {\r
+ return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();\r
+ }\r
+\r
+ /**\r
+ * Asks user for his/her own country code\r
+ * \r
+ * @return User's own country code\r
+ */\r
+ @Override\r
+ public String enterOwnEmailAddress () {\r
+ return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for family name\r
+ * \r
+ * @return Family name of the user\r
+ */\r
+ @Override\r
+ public String enterOwnFamilyName () {\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for family name\r
+ * \r
+ * @return Family name of the user\r
+ */\r
+ @Override\r
+ public String enterOwnFaxNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for gender, until a valid has been entered\r
+ * \r
+ * @return Gender of the user\r
+ */\r
+ @Override\r
+ public 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 phone number\r
+ * \r
+ * @return Phone number of the user\r
+ */\r
+ @Override\r
+ public String enterOwnPhoneNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for own street (including number)\r
+ * @return Own street an number\r
+ */\r
+ @Override\r
+ public String enterOwnStreet () {\r
+ return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for surname\r
+ * @return Surname of the user\r
+ */\r
+ @Override\r
+ public String enterOwnSurname () {\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for own ZIP code\r
+ * @return ZIP code\r
+ */\r
+ @Override\r
+ public int enterOwnZipCode () {\r
+ return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");\r
+ }\r
+\r
+ /**\r
+ * Getter for whole contact list\r
+ *\r
+ * @return List of all contacts\r
+ */\r
+ @Override\r
+ public List<Contact> getList () {\r
+ return Collections.unmodifiableList(this.contacts);\r
+ }\r
+\r
+ /**\r
+ * Checks whether own contact is already added by checking all entries for\r
+ * isOwnContact flag\r
+ *\r
+ * @return Whether own contact is already added\r
+ */\r
+ @Override\r
+ public 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
+ @Override\r
+ public void listContacts () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
+ /**\r
+ * Adds given contact to address book and flushes all entries to database\r
+ *\r
+ * @param contact Contact being added\r
+ * @todo Add check for book size\r
+ */\r
+ @Override\r
+ public void registerContact (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(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size()));\r
+ \r
+ // Add contact to internal list\r
+ this.addContact(contact);\r
+ \r
+ // Flush whole list\r
+ this.flush();\r
+ }\r
+\r
+ @Override\r
+ public void searchContacts () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\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
+ * Flushes all entries by calling database backend\r
+ */\r
+ private void flush () {\r
+ // Flusgh all\r
+ this.getContactDatabase().flushAllContacts();\r
+ }\r
+\r
+ /**\r
+ * A ContactWrapper instance\r
+ *\r
+ * @return the database\r
+ */\r
+ private ContactWrapper getContactDatabase () {\r
+ return this.contactDatabase;\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
--- /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.List;\r
+import org.mxchange.addressbook.client.Client;\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
+ /**\r
+ * Shuts down this contact manager\r
+ */\r
+ public void doShutdown ();\r
+\r
+ /**\r
+ * Allows the user to enter own cellphone number.\r
+ * \r
+ * @return Cellphone number\r
+ */\r
+ public String enterOwnCellNumber ();\r
+\r
+ /**\r
+ * Allows the user to enter own city name.\r
+ * \r
+ * @return City name\r
+ */\r
+ public String enterOwnCity ();\r
+\r
+ /**\r
+ * Allows the user to enter comment for own entry.\r
+ * \r
+ * @return Comment\r
+ */\r
+ public String enterOwnComment ();\r
+\r
+ /**\r
+ * Allows the user to enter own company name.\r
+ * \r
+ * @return Company name\r
+ */\r
+ public String enterOwnCompanyName ();\r
+\r
+ /**\r
+ * Allows the user to enter own country code.\r
+ * \r
+ * @return Country code\r
+ */\r
+ public String enterOwnCountryCode ();\r
+\r
+ /**\r
+ * Allows the user to enter own email address.\r
+ * \r
+ * @return Email address\r
+ */\r
+ public String enterOwnEmailAddress ();\r
+\r
+ /**\r
+ * Allows the user to enter own family name.\r
+ * \r
+ * @return Family name\r
+ */\r
+ public String enterOwnFamilyName ();\r
+\r
+ /**\r
+ * Allows the user to enter own fax number.\r
+ * \r
+ * @return Fax number\r
+ */\r
+ public String enterOwnFaxNumber ();\r
+\r
+ /**\r
+ * Allows the user to enter own gender.\r
+ * \r
+ * @return Gender\r
+ */\r
+ public char enterOwnGender ();\r
+\r
+ /**\r
+ * Allows the user to enter own phone number.\r
+ * \r
+ * @return Phone number\r
+ */\r
+ public String enterOwnPhoneNumber ();\r
+\r
+ /**\r
+ * Allows the user to enter own street and house number.\r
+ * \r
+ * @return Street and house number\r
+ */\r
+ public String enterOwnStreet ();\r
+\r
+ /**\r
+ * Allows the user to enter own surname.\r
+ * \r
+ * @return Surname\r
+ */\r
+ public String enterOwnSurname ();\r
+\r
+ /**\r
+ * Allows the user to enter own ZIP code.\r
+ * \r
+ * @return ZIP code\r
+ */\r
+ public int enterOwnZipCode ();\r
+\r
+ /**\r
+ * List all contacts\r
+ */\r
+ public void listContacts ();\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
+ public void registerContact (final Contact contact);\r
+\r
+ /**\r
+ * Adds given Contact instance to list\r
+ * \r
+ * @param contact Contact instance to add\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
+ * The user can change address data, like street, ZIP code, city and country\r
+ * of given Contact instance.\r
+ * \r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ */\r
+ public void doChangeAddressData (final Contact contact, final Client client);\r
+\r
+ /**\r
+ * The user can change name data, like gender, surname, family name and\r
+ * company name (if business contact).\r
+ * \r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ */\r
+ public void doChangeNameData (final Contact contact, final Client client);\r
+\r
+ /**\r
+ * Let the user change other address\r
+ */\r
+ public void changeOtherAddress();\r
+\r
+ /**\r
+ * The user can change other data, like phone numbers or comments.\r
+ * \r
+ * @param contact Instance to change data\r
+ * @param client Client instance to call back\r
+ */\r
+ public void doChangeOtherData (final Contact contact, final Client client);\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 doEnterOwnData();\r
+\r
+ /**\r
+ * Getter for whole list\r
+ * @return List of all contacts\r
+ */\r
+ public List<Contact> getList ();\r
+\r
+ /**\r
+ * Searches address book for a contact\r
+ */\r
+ public void searchContacts ();\r
+\r
+ /**\r
+ * Checks whether own contact is already added by checking all entries for\r
+ * isOwnContact flag\r
+ * \r
+ * @return Whether own contact is already added\r
+ */\r
+ public boolean isOwnContactAdded ();\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
+ // List entries\r
+ menuList.add(client.getMenuItem('4', "Adressbuch anzeigen"));\r
+\r
+ // Address search\r
+ menuList.add(client.getMenuItem('5', "Adresse suchen"));\r
+\r
+ // Change other address\r
+ menuList.add(client.getMenuItem('6', "Adresse ändern"));\r
+\r
+ // Delete other address\r
+ menuList.add(client.getMenuItem('7', "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.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.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
+ * Size of menu items\r
+ * @return Count of menu items\r
+ */\r
+ public int getMenuItemsCount () {\r
+ return this.menuList.size();\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
+ * 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
+ * Getter for menu list\r
+ *\r
+ * @return menuList List of menu entries\r
+ */\r
+ protected final List<SelectableMenuItem> getMenuList () {\r
+ return this.menuList;\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
+}\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 org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.AddressbookMenu;\r
+import org.mxchange.addressbook.menu.BaseMenu;\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
+ // Add all items\r
+ AddressbookMenu.addItemsToList(this.getMenuList(), 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
+ * Access key\r
+ * @param accessKey the accessKey to set\r
+ */\r
+ private void setAccessKey (char accessKey) {\r
+ this.accessKey = 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
+ /**\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
+ @Override\r
+ public void show (final Client client) {\r
+ // Call-back client over menu\r
+ client.showEntry(this);\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.model.address;\r
+\r
+import javax.swing.table.TableModel;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.model.BaseModel;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class AddressTableModel extends BaseModel implements TableModel {\r
+\r
+ /**\r
+ * Constructor with Client instance which holds the contact manager\r
+ *\r
+ * @param client Client instance\r
+ */\r
+ public AddressTableModel (final Client client) {\r
+ // Parent super constructor\r
+ super();\r
+\r
+ // Set client\r
+ this.setClient(client);\r
+ }\r
+\r
+ @Override\r
+ public Class<?> getColumnClass (final int columnIndex) {\r
+ throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public int getColumnCount () {\r
+ // Deligate this call to the contact manager\r
+ return this.getClient().getContactManager().size();\r
+ }\r
+\r
+ @Override\r
+ public String getColumnName (final int columnIndex) {\r
+ throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public int getRowCount () {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public Object getValueAt (final int rowIndex, final int columnIndex) {\r
+ throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public boolean isCellEditable (final int rowIndex, final int columnIndex) {\r
+ throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void setValueAt (final Object value, final int rowIndex, final int columnIndex) {\r
+ throw new UnsupportedOperationException("Not supported yet. value=" + value + ",rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+}\r