]> git.mxchange.org Git - addressbook-lib.git/commitdiff
Global commit: Changed spaces to tabs, because all Java files have tabs for indenting
authorRoland Haeder <roland@mxchange.org>
Fri, 24 Jul 2015 11:18:38 +0000 (13:18 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 24 Jul 2015 11:18:38 +0000 (13:18 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

43 files changed:
Addressbook/src/log4j2.xml
Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java
Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java
Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Addressbook/src/org/mxchange/addressbook/application/Application.java
Addressbook/src/org/mxchange/addressbook/client/BaseClient.java
Addressbook/src/org/mxchange/addressbook/client/Client.java
Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java
Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java
Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java
Addressbook/src/org/mxchange/addressbook/contact/Contact.java
Addressbook/src/org/mxchange/addressbook/contact/book/BookContact.java
Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java
Addressbook/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java
Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java
Addressbook/src/org/mxchange/addressbook/database/storage/Storeable.java
Addressbook/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java
Addressbook/src/org/mxchange/addressbook/exceptions/BadTokenException.java
Addressbook/src/org/mxchange/addressbook/exceptions/FrameAlreadyInitializedException.java
Addressbook/src/org/mxchange/addressbook/exceptions/UnhandledUserChoiceException.java
Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java
Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java
Addressbook/src/org/mxchange/addressbook/manager/application/ManageableApplication.java
Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java
Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java
Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java
Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java
Addressbook/src/org/mxchange/addressbook/menu/Menu.java
Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java
Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java
Addressbook/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java
Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java
Addressbook/src/org/mxchange/addressbook/model/BaseModel.java
Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java [deleted file]
Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java [new file with mode: 0644]

index 65614c6ca0710f613f6ffe8b25447e04057ce324..cafb433353391a258d13b974d7d0d5c9b1992b20 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-Copyright (C) 2015 Roland Häder
+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
index 49ac02e968a1ed103fb7c2cda3cfdfe1997d8c12..431aeb456a8e49677e56f1aba655014fd1dc7f92 100644 (file)
-/*\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
-     * Bundle instance\r
-     */\r
-    private final ResourceBundle bundle;\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
-    /**\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
-    /**\r
-     * Getter for bundle instance\r
-     * \r
-     * @return Resource bundle\r
-     */\r
-    protected final ResourceBundle getBundle () {\r
-       return this.bundle;\r
-    }\r
-}\r
+/*
+ * 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;
+
+import java.util.ResourceBundle;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.application.Application;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.manager.contact.ManageableContact;
+
+/**
+ * General class
+ *
+ * @author Roland Haeder
+ */
+public class BaseFrameworkSystem implements FrameworkInterface {
+
+       /**
+        * Class' logger
+        */
+       private final Logger LOG;
+
+       /**
+        * Application instance
+        */
+       private Application application;
+
+       /**
+        * Bundle instance
+        */
+       private final ResourceBundle bundle;
+
+       /**
+        * Client instance
+        */
+       private Client client;
+
+       /**
+        * Contact manager instance
+        */
+       private ManageableContact contactManager;
+
+       /**
+        * Name of used database table, handled over to backend
+        */
+       private String tableName;
+
+       /**
+        * Initialize object
+        */
+       {
+               LOG = LogManager.getLogger(this);
+               bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N
+       }
+
+       /**
+        * No instances can be created of this class
+        */
+       protected BaseFrameworkSystem () {
+       }
+
+       /**
+        * Application instance
+        *
+        * @return the application
+        */
+       @Override
+       public final Application getApplication () {
+               return this.application;
+       }
+
+       /**
+        * Client instance
+        *
+        * @return the client
+        */
+       @Override
+       public final Client getClient () {
+               return this.client;
+       }
+
+       /**
+        * Contact manager instance
+        *
+        * @return the contactManager
+        */
+       @Override
+       public final ManageableContact getContactManager () {
+               return this.contactManager;
+       }
+
+       /**
+        * Contact manager instance
+        *
+        * @param contactManager the contactManager to set
+        */
+       protected final void setContactManager (final ManageableContact contactManager) {
+               this.contactManager = contactManager;
+       }
+
+       /**
+        * Client instance
+        *
+        * @param client the client to set
+        */
+       protected final void setClient (final Client client) {
+               this.client = client;
+       }
+
+       /**
+        * Application instance
+        *
+        * @param application the application to set
+        */
+       protected final void setApplication (final Application application) {
+               this.application = application;
+       }
+
+       /**
+        * Getter for logger
+        *
+        * @return Logger
+        */
+       protected final Logger getLogger () {
+               return this.LOG;
+       }
+
+       /**
+        * Name of used database table, handled over to backend
+        *
+        * @return the tableName
+        */
+       protected final String getTableName () {
+               return this.tableName;
+       }
+
+       /**
+        * Name of used database table, handled over to backend
+        *
+        * @param tableName the tableName to set
+        */
+       protected final void setTableName (final String tableName) {
+               this.tableName = tableName;
+       }
+
+       /**
+        * Getter for bundle instance
+        *
+        * @return Resource bundle
+        */
+       protected final ResourceBundle getBundle () {
+               return this.bundle;
+       }
+}
index 5236877890177bf661c51483c5f88ec50ec1fe2a..7d9f6c744e1fac2b5e43c93d861c8ab79d9af13f 100644 (file)
@@ -1,49 +1,50 @@
-/*\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.mxchange.addressbook.application.Application;\r
-import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.manager.contact.ManageableContact;\r
-\r
-/**\r
- * A general interface which should be always expanded\r
- *\r
- * @author Roland Haeder\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
+/*
+ * 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;
+
+import org.mxchange.addressbook.application.Application;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.manager.contact.ManageableContact;
+
+/**
+ * A general interface which should be always expanded
+ *
+ * @author Roland Haeder
+ */
+public interface FrameworkInterface {
+
+       /**
+        * Getter for contact manager
+        *
+        * @return Contact manager instance
+        */
+       public ManageableContact getContactManager ();
+
+       /**
+        * Client instance
+        *
+        * @return the client
+        */
+       public Client getClient ();
+
+       /**
+        * Application instance
+        *
+        * @return the application
+        */
+       public Application getApplication ();
+}
index a7842b0cf8135ff95c8f8489d00acf67bf7d6c1f..78efb043b54a1454ae310a142c57faeeb83c7c91 100644 (file)
@@ -116,222 +116,222 @@ import org.mxchange.addressbook.manager.application.ApplicationManager;
  * @since 0.0
  */
 public class AddressbookApplication extends BaseFrameworkSystem implements Application {
-    /**
-     * Application title
-     */
-    public static final String APP_TITLE = "Adressbuch";
-
-    /**
-     * Application version
-     */
-    public static final String APP_VERSION = "0.0";
-
-    /**
-     * Console client is enabled by default
-     */
-    private boolean consoleClient = true;
-
-    /**
-     * GUI client is disabled by default
-     */
-    private boolean guiClient = false;
-
-    /**
-     * Getter for printable application name
-     * 
-     * @return A printable name
-     */
-    public static String printableTitle () {
-       return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);
-    }
-
-    /**
-     * Bootstraps application
-     */
-    @Override
-    public void doBootstrap () {
-       this.getLogger().debug("Initializing application ...");
-
-       // Init client variable
-       Client client = null;
-
-       // Is console or Swing choosen?
-       if (this.isConsole()) {
-           // Debug message
-           this.getLogger().debug("Initializing console client ...");
-
-           // Init console client instance
-           client = new ConsoleClient(this);
-       } else if (this.isGui()) {
-           // Debug message
-           this.getLogger().debug("Initializing GUI (Swing) client ...");
-
-           // Init console instance
-           client = new SwingClient(this);
-       } else {
-           // Not client choosen
-           this.getLogger().error("No client choosen. Cannot launch.");
-           System.exit(1);
-       }
 
-       // Init client
-       client.init();
+       /**
+        * Application title
+        */
+       public static final String APP_TITLE = "Adressbuch";
+
+       /**
+        * Application version
+        */
+       public static final String APP_VERSION = "0.0";
+
+       /**
+        * Console client is enabled by default
+        */
+       private boolean consoleClient = true;
+
+       /**
+        * GUI client is disabled by default
+        */
+       private boolean guiClient = false;
+
+       /**
+        * Getter for printable application name
+        *
+        * @return A printable name
+        */
+       public static String printableTitle () {
+               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);
+       }
 
-       // Set client instance
-       this.setClient(client);
-       
-       // The application is running at this point
-       this.getClient().enableIsRunning();
-    }
+       /**
+        * Bootstraps application
+        */
+       @Override
+       public void doBootstrap () {
+               this.getLogger().debug("Initializing application ...");
+
+               // Init client variable
+               Client client = null;
+
+               // Is console or Swing choosen?
+               if (this.isConsole()) {
+                       // Debug message
+                       this.getLogger().debug("Initializing console client ...");
+
+                       // Init console client instance
+                       client = new ConsoleClient(this);
+               } else if (this.isGui()) {
+                       // Debug message
+                       this.getLogger().debug("Initializing GUI (Swing) client ...");
+
+                       // Init console instance
+                       client = new SwingClient(this);
+               } else {
+                       // Not client choosen
+                       this.getLogger().error("No client choosen. Cannot launch.");
+                       System.exit(1);
+               }
+
+               // Init client
+               client.init();
+
+               // Set client instance
+               this.setClient(client);
+
+               // The application is running at this point
+               this.getClient().enableIsRunning();
+       }
 
-    /**
-     * Main loop of the application
-     */
-    @Override
-    public void doMainLoop () {
-       // Debug message
-       this.getLogger().trace("CALLED!");
+       /**
+        * Main loop of the application
+        */
+       @Override
+       public void doMainLoop () {
+               // Debug message
+               this.getLogger().trace("CALLED!");
 
        // @TODO The application should be running now
-       
-       // Output introduction
-       this.showIntro();
-
-       // Set current menu to main
-       this.getClient().setCurrentMenu("main");
-
-       // --- Main loop starts here ---
-       while (this.getClient().isRunning()) {
-           // The application is still active, show menu selection
-           this.getClient().showCurrentMenu();
-
-           try {
-               // Ask for user input and run proper method
-               this.getClient().doUserMenuChoice();
-           } catch (final UnhandledUserChoiceException ex) {
-               this.getLogger().catching(ex);
-           }
-
-           try {
-               // Sleep a little to reduce system load
-               Thread.sleep(100);
-           } catch (final InterruptedException ex) {
-               // Ignore it
-           }
-       }
+               // Output introduction
+               this.showIntro();
+
+               // Set current menu to main
+               this.getClient().setCurrentMenu("main");
+
+               // --- Main loop starts here ---
+               while (this.getClient().isRunning()) {
+                       // The application is still active, show menu selection
+                       this.getClient().showCurrentMenu();
+
+                       try {
+                               // Ask for user input and run proper method
+                               this.getClient().doUserMenuChoice();
+                       } catch (final UnhandledUserChoiceException ex) {
+                               this.getLogger().catching(ex);
+                       }
+
+                       try {
+                               // Sleep a little to reduce system load
+                               Thread.sleep(100);
+                       } catch (final InterruptedException ex) {
+                               // Ignore it
+                       }
+               }
        // --- Main loop ends here ---
 
-       // Debug message
-       this.getLogger().debug("Main loop exit - shutting down ...");
-    }
-
-    /**
-     * Enables console client by setting propper flag
-     */
-    private void enableConsoleClient () {
-       this.getLogger().debug("Enabling console client (may become optional client) ...");
-       this.consoleClient = true;
-       this.guiClient = false;
-    }
-
-    /**
-     * Enables GUI client by setting propper flag
-     */
-    private void enableGuiClient () {
-       this.getLogger().debug("Enabling GUI client (may become new default client) ...");
-       this.consoleClient = false;
-       this.guiClient = true;
-    }
-
-    /**
-     * Checks whether the client shoule be console client should be launched by
-     * checking if -console is set.
-     * 
-     * @return Whether console client should be taken
-     */
-    private boolean isConsole () {
-       return this.consoleClient;
-    }
-
-    /**
-     * Checks whether the client shoule be GUI client should be launched by
-     * checking if -gui is set.
-     * 
-     * @return Whether GUI client should be taken
-     */
-    private boolean isGui () {
-       return this.guiClient;
-    }
-
-    /**
-     * Parses all given arguments
-     *
-     * @param args Arguments from program launch
-     */
-    private void parseArguments (final String[] args) {
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));
-       
-       for (final String arg : args) {
-           // Switch on it
-           switch (arg) {
-               case "-console":
-                   enableConsoleClient();
-                   break;
-                   
-               case "-gui":
-                   enableGuiClient();
-                   break;
-}
+               // Debug message
+               this.getLogger().debug("Main loop exit - shutting down ...");
+       }
+
+       /**
+        * Enables console client by setting propper flag
+        */
+       private void enableConsoleClient () {
+               this.getLogger().debug("Enabling console client (may become optional client) ...");
+               this.consoleClient = true;
+               this.guiClient = false;
+       }
+
+       /**
+        * Enables GUI client by setting propper flag
+        */
+       private void enableGuiClient () {
+               this.getLogger().debug("Enabling GUI client (may become new default client) ...");
+               this.consoleClient = false;
+               this.guiClient = true;
+       }
+
+       /**
+        * Checks whether the client shoule be console client should be launched by
+        * checking if -console is set.
+        *
+        * @return Whether console client should be taken
+        */
+       private boolean isConsole () {
+               return this.consoleClient;
+       }
+
+       /**
+        * Checks whether the client shoule be GUI client should be launched by
+        * checking if -gui is set.
+        *
+        * @return Whether GUI client should be taken
+        */
+       private boolean isGui () {
+               return this.guiClient;
+       }
+
+       /**
+        * Parses all given arguments
+        *
+        * @param args Arguments from program launch
+        */
+       private void parseArguments (final String[] args) {
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));
+
+               for (final String arg : args) {
+                       // Switch on it
+                       switch (arg) {
+                               case "-console":
+                                       enableConsoleClient();
+                                       break;
+
+                               case "-gui":
+                                       enableGuiClient();
+                                       break;
+                       }
+               }
+       }
+
+       /**
+        * Show introduction which depends on client
+        */
+       private void showIntro () {
+               // Let the client show it
+               this.getClient().showWelcome();
+       }
+
+       /**
+        * Launches the application
+        *
+        * @param args Arguments handled to program
+        */
+       private void start (final String args[]) {
+               this.getLogger().info("Program is started.");
+
+               // Parse arguments
+               this.parseArguments(args);
+
+               // Launch application
+               ApplicationManager.getManager(this).start();
+
+               // Good bye, but this should not be reached ...
+               this.getLogger().warn("Unusual exit reached.");
+               this.doShutdown();
+       }
+
+       /**
+        * Main method (entry point)
+        *
+        * @param args the command line arguments
+        */
+       public static void main (String[] args) {
+               // Start application
+               new AddressbookApplication().start(args);
+       }
+
+       /**
+        * Shuts down the application.
+        */
+       @Override
+       public void doShutdown () {
+               // Shutdown client
+               this.getClient().doShutdown();
+
+               this.getLogger().info("End of program (last line)");
+               System.exit(0);
        }
-    }
-
-    /**
-     * Show introduction which depends on client
-     */
-    private void showIntro () {
-       // Let the client show it
-       this.getClient().showWelcome();
-    }
-
-    /**
-     * Launches the application
-     * 
-     * @param args Arguments handled to program
-     */
-    private void start (final String args[]) {
-       this.getLogger().info("Program is started.");
-
-       // Parse arguments
-       this.parseArguments(args);
-
-       // Launch application
-       ApplicationManager.getManager(this).start();
-
-       // Good bye, but this should not be reached ...
-       this.getLogger().warn("Unusual exit reached.");
-       this.doShutdown();
-    }
-
-    /**
-     * Main method (entry point)
-     *
-     * @param args the command line arguments
-     */
-    public static void main (String[] args) {
-       // Start application
-       new AddressbookApplication().start(args);
-    }
-
-    /**
-     * Shuts down the application.
-     */
-    @Override
-    public void doShutdown () {
-       // Shutdown client
-       this.getClient().doShutdown();
-
-       this.getLogger().info("End of program (last line)");
-       System.exit(0);
-    }
 }
index aa773e53709be30b91e8c508cbb883a62b9a2e4f..5aa4a2344bdd5c7e174aa4e5666474877faf9a7a 100644 (file)
@@ -1,40 +1,41 @@
-/*\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
+/*
+ * 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.application;
+
+import org.mxchange.addressbook.FrameworkInterface;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public interface Application extends FrameworkInterface {
+
+       /**
+        * Bootstraps the application
+        */
+       public void doBootstrap ();
+
+       /**
+        * Run the main loop
+        */
+       public void doMainLoop ();
+
+       /**
+        * Shutdown the application
+        */
+       public void doShutdown ();
+}
index 0c8bba50c4b12c8f373ca36acb97b7c9d74e22e5..54d8bc32aad56c692a561fb867d766e523829b07 100644 (file)
@@ -30,151 +30,153 @@ import org.mxchange.addressbook.menu.Menu;
  */
 public abstract class BaseClient extends BaseFrameworkSystem {
 
-    /**
-     * Current menu choice
-     */
-    private String currentMenu;
-
-    /**
-     * Application is not running by default
-     */
-    private boolean isRunning;
-
-    /**
-     * Menu system
-     */
-    private final Map<String, Menu> menus;
-
-    /**
-     * No instances can be created of this class
-     */
-    protected BaseClient () {
-       super();
-
-       // Init menu map
-       this.menus = new HashMap<>(10);
-    }
-
-    /**
-     * Shutdown method for all clients
-     */
-    public void doShutdown () {
-       // Disable client
-       this.disableIsRunning();
-
-       // Shuts down contact manager
-       this.getContactManager().doShutdown();
-    }
-
-    /**
-     * Enables the client
-     */
-    public final void enableIsRunning () {
-       this.isRunning = true;
-    }
-
-    /**
-     * Current menu choice
-     * 
-     * @return the currentMenu
-     */
-    public final String getCurrentMenu () {
-       return this.currentMenu;
-    }
-
-    /**
-     * Current menu choice
-     * @param currentMenu the currentMenu to set
-     */
-    public final void setCurrentMenu (final String currentMenu) {
-       this.currentMenu = currentMenu;
-    }
-
-    /**
-     * "Getter" for given menu type
-     *
-     * @param menuType Menu type instance to return
-     * @return Menu or null if not found
-     */
-    public Menu getMenu (final String menuType) {
-       // Default is not found
-       Menu menu = null;
-       
-       // Check array
-       if (this.getMenus().containsKey(menuType)) {
-           // Found!
-           menu = this.getMenus().get(menuType);
+       /**
+        * Current menu choice
+        */
+       private String currentMenu;
+
+       /**
+        * Application is not running by default
+        */
+       private boolean isRunning;
+
+       /**
+        * Menu system
+        */
+       private final Map<String, Menu> menus;
+
+       /**
+        * No instances can be created of this class
+        */
+       protected BaseClient () {
+               super();
+
+               // Init menu map
+               this.menus = new HashMap<>(10);
        }
-       
-       // Return it
-       return menu;
-    }
-
-    /**
-     * Determines whether the application is still active by checking some
-     * conditions
-     * 
-     * @return Whether the application is still active
-     */
-    public final boolean isRunning () {
-       // In console client, 0 may have been used
-       return this.isRunning;
-    }
-
-    /**
-     * Disables the client
-     */
-    protected final void disableIsRunning () {
-       this.isRunning = false;
-    }
-
-    /**
-     * Fills menu map with swing menus
-     */
-    protected abstract void fillMenuMap ();
-
-    /**
-     * Getter for menus map
-     * @return Map of all menus
-     */
-    protected final Map<String, Menu> getMenus () {
-       return this.menus;
-    }
-
-    /**
-     * Initializes contact manager
-     */
-    protected void initContactManager () {
-       // Debug message
-       this.getLogger().debug("Initializing contact manager ...");
-       
-       // Init contact manager with console client
-       // @TODO Static initial amount of contacts
-       ManageableContact manager = new ContactManager (100, (Client) this);
-       
-       // Set it here
-       this.setContactManager(manager);
-       
-       // Debug message
-       this.getLogger().debug("Contact manager has been initialized.");
-    }
-
-    /**
-     * Shows given menu
-     *
-     * @param menuType Given menu to show
-     */
-    protected void showMenu (final String menuType) {
-       Menu menu = this.getMenu(menuType);
-       
-       // Is the menu set?
-       if (!(menu instanceof Menu)) {
-           // Not found
-           // @todo Own exception?
-           throw new NullPointerException("Menu '" + menuType + "' not found.");
+
+       /**
+        * Shutdown method for all clients
+        */
+       public void doShutdown () {
+               // Disable client
+               this.disableIsRunning();
+
+               // Shuts down contact manager
+               this.getContactManager().doShutdown();
+       }
+
+       /**
+        * Enables the client
+        */
+       public final void enableIsRunning () {
+               this.isRunning = true;
+       }
+
+       /**
+        * Current menu choice
+        *
+        * @return the currentMenu
+        */
+       public final String getCurrentMenu () {
+               return this.currentMenu;
+       }
+
+       /**
+        * Current menu choice
+        *
+        * @param currentMenu the currentMenu to set
+        */
+       public final void setCurrentMenu (final String currentMenu) {
+               this.currentMenu = currentMenu;
+       }
+
+       /**
+        * "Getter" for given menu type
+        *
+        * @param menuType Menu type instance to return
+        * @return Menu or null if not found
+        */
+       public Menu getMenu (final String menuType) {
+               // Default is not found
+               Menu menu = null;
+
+               // Check array
+               if (this.getMenus().containsKey(menuType)) {
+                       // Found!
+                       menu = this.getMenus().get(menuType);
+               }
+
+               // Return it
+               return menu;
+       }
+
+       /**
+        * Determines whether the application is still active by checking some
+        * conditions
+        *
+        * @return Whether the application is still active
+        */
+       public final boolean isRunning () {
+               // In console client, 0 may have been used
+               return this.isRunning;
+       }
+
+       /**
+        * Disables the client
+        */
+       protected final void disableIsRunning () {
+               this.isRunning = false;
+       }
+
+       /**
+        * Fills menu map with swing menus
+        */
+       protected abstract void fillMenuMap ();
+
+       /**
+        * Getter for menus map
+        *
+        * @return Map of all menus
+        */
+       protected final Map<String, Menu> getMenus () {
+               return this.menus;
+       }
+
+       /**
+        * Initializes contact manager
+        */
+       protected void initContactManager () {
+               // Debug message
+               this.getLogger().debug("Initializing contact manager ...");
+
+               // Init contact manager with console client
+               // @TODO Static initial amount of contacts
+               ManageableContact manager = new ContactManager(100, (Client) this);
+
+               // Set it here
+               this.setContactManager(manager);
+
+               // Debug message
+               this.getLogger().debug("Contact manager has been initialized.");
+       }
+
+       /**
+        * Shows given menu
+        *
+        * @param menuType Given menu to show
+        */
+       protected void showMenu (final String menuType) {
+               Menu menu = this.getMenu(menuType);
+
+               // Is the menu set?
+               if (!(menu instanceof Menu)) {
+                       // Not found
+                       // @todo Own exception?
+                       throw new NullPointerException("Menu '" + menuType + "' not found.");
+               }
+
+               // Show menu
+               menu.show((Client) this);
        }
-       
-       // Show menu
-       menu.show((Client) this);
-    }
 }
index 42b7b7cd262730fdcbd9a37812aebc482588f8cc..7dcbdfe4a629889f6b6b696653fa7120a6a1a5d8 100644 (file)
@@ -23,167 +23,167 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem;
 
 /**
  * An interface for application clients
- * 
+ *
  * @author Roland Haeder
  */
 public interface Client extends FrameworkInterface {
 
-    /**
-     * Displays a "box" for the address
-     *
-     * @param contact Contact to show address from
-     */
-    public void displayAddressBox (final Contact contact);
-
-    /**
-     * The user changes own name data
-     * @param contact 
-     */
-    public void doChangeOwnNameData (final Contact contact);
-
-    /**
-     * The user changes own address data
-     *
-     * @param contact Contact instance to change
-     */
-    public void doChangeOwnAddressData (final Contact contact);
-
-    /**
-     * The user changes own other data
-     * 
-     * @param contact Constact instance to change
-     */
-    public void doChangeOwnOtherData (final Contact contact);
-
-    /**
-     * Allows the user to enter own data
-     * 
-     * @return Finished Contact instance
-     */
-    public Contact doEnterOwnData ();
-
-    /**
-     * Shuts down the client and therefore whole application
-     */
-    public void doShutdown ();
-
-    /**
-     * Displays a message to the user
-     *
-     * @param message Message to show to the user
-     */
-    public void outputMessage (final String message);
-
-    /**
-     * Displays a "box" for the name
-     *
-     * @param contact Contact to show name from
-     */
-    public void displayNameBox (final Contact contact);
-
-    /**
-     * Displays a "box" for other data
-     *
-     * @param contact Contact to show other data from
-     */
-    public void displayOtherDataBox (final Contact contact);
-
-    /**
-     * Let the user choose what to change on the address: [n]ame, [a]ddress,
-     * [o]ther
-     * 
-     * @param contact Contact instance to let the user change data
-     * @throws UnhandledUserChoiceException If choice is not supported
-     */
-    public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException;
-
-    /**
-     * Asks the user for a choice and proceeds accordingly
-     * 
-     * @throws UnhandledUserChoiceException If choice is not supported
-     */
-    public void doUserMenuChoice () throws UnhandledUserChoiceException ;
-
-    /**
-     * Enables isRunning attribute which singals that the client is running
-     */
-    public void enableIsRunning();
-
-    /**
-     * Asks the the user to enter a single character which must match validChars
-     * 
-     * @param  validChars  Valid chars that are accepted
-     * @param  message     Message to user
-     * @return Allowed character
-     */
-    public char enterChar (final char[] validChars, final String message);
-
-    /**
-     * Reads a string of minimum and maximum length from the user. An empty
-     * string should be generally not allowed, but might be okay for e.g.
-     * company name.
-     * 
-     * @param minLength        Minimum length of the string to read
-     * @param maxLength        Maximum length of the string to read
-     * @param message  Message to user
-     * @param allowEmpty Whether empty strings are allowed
-     * @return Entered string by user or null if empty string is allowed
-     */
-    public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty);
-
-    /**
-     * Reads an integer (int) from the user
-     * 
-     * @param minimum Minimum allowed number
-     * @param maximum Maximum allowed number
-     * @param message  Message to user
-     * @return Entered string by user or null if empty string is allowed
-     */
-    public int enterInt (final int minimum, final int maximum, final String message);
-
-    /**
-     * Setter for current menu choice
-     * 
-     * @param currentMenu Current menu choice
-     */
-    public void setCurrentMenu (final String currentMenu);
-
-    /**
-     * Some "Getter" for menu item
-     * 
-     * @param accessKey Key to press to access this menu
-     * @param text Text to show to user
-     * @return 
-     */
-    public SelectableMenuItem getMenuItem (final char accessKey, final String text);
-
-    /**
-     * Determines whether the client is still active by checking some
-     * conditions
-     * 
-     * @return Whether the client is still active
-     */
-    public boolean isRunning();
-
-    /**
-     * Shows given menu entry in client
-     * 
-     * @param item Menu item to show
-     */
-    public void showEntry (final SelectableMenuItem item);
-
-    /**
-     * Shows introduction to user
-     */
-    public void showWelcome();
-
-    /**
-     * Shows current menu selection to the user
-     */
-    public void showCurrentMenu();
-
-    /**
-     * Inizializes this client
-     */
-    public void init ();
+       /**
+        * Displays a "box" for the address
+        *
+        * @param contact Contact to show address from
+        */
+       public void displayAddressBox (final Contact contact);
+
+       /**
+        * The user changes own name data
+        *
+        * @param contact
+        */
+       public void doChangeOwnNameData (final Contact contact);
+
+       /**
+        * The user changes own address data
+        *
+        * @param contact Contact instance to change
+        */
+       public void doChangeOwnAddressData (final Contact contact);
+
+       /**
+        * The user changes own other data
+        *
+        * @param contact Constact instance to change
+        */
+       public void doChangeOwnOtherData (final Contact contact);
+
+       /**
+        * Allows the user to enter own data
+        *
+        * @return Finished Contact instance
+        */
+       public Contact doEnterOwnData ();
+
+       /**
+        * Shuts down the client and therefore whole application
+        */
+       public void doShutdown ();
+
+       /**
+        * Displays a message to the user
+        *
+        * @param message Message to show to the user
+        */
+       public void outputMessage (final String message);
+
+       /**
+        * Displays a "box" for the name
+        *
+        * @param contact Contact to show name from
+        */
+       public void displayNameBox (final Contact contact);
+
+       /**
+        * Displays a "box" for other data
+        *
+        * @param contact Contact to show other data from
+        */
+       public void displayOtherDataBox (final Contact contact);
+
+       /**
+        * Let the user choose what to change on the address: [n]ame, [a]ddress,
+        * [o]ther
+        *
+        * @param contact Contact instance to let the user change data
+        * @throws UnhandledUserChoiceException If choice is not supported
+        */
+       public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException;
+
+       /**
+        * Asks the user for a choice and proceeds accordingly
+        *
+        * @throws UnhandledUserChoiceException If choice is not supported
+        */
+       public void doUserMenuChoice () throws UnhandledUserChoiceException;
+
+       /**
+        * Enables isRunning attribute which singals that the client is running
+        */
+       public void enableIsRunning ();
+
+       /**
+        * Asks the the user to enter a single character which must match validChars
+        *
+        * @param       validChars Valid chars that are accepted
+        * @param       message Message to user
+        * @return      Allowed character
+        */
+       public char enterChar (final char[] validChars, final String message);
+
+       /**
+        * Reads a string of minimum and maximum length from the user. An empty
+        * string should be generally not allowed, but might be okay for e.g.
+        * company name.
+        *
+        * @param minLength     Minimum length of the string to read
+        * @param maxLength     Maximum length of the string to read
+        * @param message       Message to user
+        * @param allowEmpty Whether empty strings are allowed
+        * @return Entered string by user or null if empty string is allowed
+        */
+       public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty);
+
+       /**
+        * Reads an integer (int) from the user
+        *
+        * @param minimum Minimum allowed number
+        * @param maximum Maximum allowed number
+        * @param message       Message to user
+        * @return Entered string by user or null if empty string is allowed
+        */
+       public int enterInt (final int minimum, final int maximum, final String message);
+
+       /**
+        * Setter for current menu choice
+        *
+        * @param currentMenu Current menu choice
+        */
+       public void setCurrentMenu (final String currentMenu);
+
+       /**
+        * Some "Getter" for menu item
+        *
+        * @param accessKey Key to press to access this menu
+        * @param text Text to show to user
+        * @return
+        */
+       public SelectableMenuItem getMenuItem (final char accessKey, final String text);
+
+       /**
+        * Determines whether the client is still active by checking some conditions
+        *
+        * @return Whether the client is still active
+        */
+       public boolean isRunning ();
+
+       /**
+        * Shows given menu entry in client
+        *
+        * @param item Menu item to show
+        */
+       public void showEntry (final SelectableMenuItem item);
+
+       /**
+        * Shows introduction to user
+        */
+       public void showWelcome ();
+
+       /**
+        * Shows current menu selection to the user
+        */
+       public void showCurrentMenu ();
+
+       /**
+        * Inizializes this client
+        */
+       public void init ();
 }
index 3f5889922f2d335ce2f82d6b0ee9406af437cf6c..94818f13d145b60ef3f2520a3a0d2e68fe0f85c8 100644 (file)
@@ -38,468 +38,472 @@ import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem;
  * @author Roland Haeder
  */
 public class ConsoleClient extends BaseClient implements Client {
-    /**
-     * Scanner instance for reading data from console input
-     */
-    private final Scanner scanner;
-
-    /**
-     * Parameterless constructor
-     * @param application An instance of an Application class
-     */
-    public ConsoleClient (final Application application) {
-       super();
-
-       // Set application instance
-       this.setApplication(application);
-
-       // Init scanner instance
-       this.scanner = new Scanner(System.in);
-    }
-
-    /**
-     * Displays a textual address "box" of given contact
-     *
-     * @param contact Contact to show address for
-     */
-    @Override
-    public void displayAddressBox (final Contact contact) {
-       // Simple display ...
-       this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode()));
-    }
-
-    /**
-     * Displays a textual name "box" of given contact
-     *
-     * @param contact Contact to show name for
-     */
-    @Override
-    public void displayNameBox (final Contact contact) {
-       // Get translated gender as the user may want to see "Mr.", "Mrs."
-       String gender = contact.getTranslatedGender();
-
-       // Get company name
-       String companyName = contact.getCompanyName();
-
-       // If it is empty/null, then assume private contact
-       if ((companyName == null) || (companyName.isEmpty())) {
-           // Now put all together: gender, surname, family name
-           // @todo Use mask
-           this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName()));
-       } else {
-           // Company contact
-           this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName()));
+
+       /**
+        * Scanner instance for reading data from console input
+        */
+       private final Scanner scanner;
+
+       /**
+        * Parameterless constructor
+        *
+        * @param application An instance of an Application class
+        */
+       public ConsoleClient (final Application application) {
+               super();
+
+               // Set application instance
+               this.setApplication(application);
+
+               // Init scanner instance
+               this.scanner = new Scanner(System.in);
+       }
+
+       /**
+        * Displays a textual address "box" of given contact
+        *
+        * @param contact Contact to show address for
+        */
+       @Override
+       public void displayAddressBox (final Contact contact) {
+               // Simple display ...
+               this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode()));
+       }
+
+       /**
+        * Displays a textual name "box" of given contact
+        *
+        * @param contact Contact to show name for
+        */
+       @Override
+       public void displayNameBox (final Contact contact) {
+               // Get translated gender as the user may want to see "Mr.", "Mrs."
+               String gender = contact.getTranslatedGender();
+
+               // Get company name
+               String companyName = contact.getCompanyName();
+
+               // If it is empty/null, then assume private contact
+               if ((companyName == null) || (companyName.isEmpty())) {
+                       // Now put all together: gender, surname, family name
+                       // @todo Use mask
+                       this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName()));
+               } else {
+                       // Company contact
+                       this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName()));
+               }
+       }
+
+       /**
+        * Displays a textual other data "box" of given contact
+        *
+        * @param contact Contact to show other data for
+        */
+       @Override
+       public void displayOtherDataBox (final Contact contact) {
+               // Cellphone and such ...
+               this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));
+       }
+
+       @Override
+       public void doChangeOwnAddressData (final Contact contact) {
+               // Make sure it is own contact
+               if (!contact.isOwnContact()) {
+                       // Not own contact
+                       throw new IllegalArgumentException("Contact is not own data.");
+               }
+
+               // Own address data
+               String street = this.getContactManager().enterOwnStreet();
+
+               // Get zip code
+               int zipCode = this.getContactManager().enterOwnZipCode();
+
+               // Get city name
+               String city = this.getContactManager().enterOwnCity();
+
+               // Get country code
+               String countryCode = this.getContactManager().enterOwnCountryCode();
+
+               // Update address data
+               contact.updateAddressData(street, zipCode, city, countryCode);
+       }
+
+       @Override
+       public void doChangeOwnNameData (final Contact contact) {
+               // Make sure it is own contact
+               if (!contact.isOwnContact()) {
+                       // Not own contact
+                       throw new IllegalArgumentException("Contact is not own data.");
+               }
+
+               // Gender:
+               char gender = this.getContactManager().enterOwnGender();
+
+               // Surname
+               String surname = this.getContactManager().enterOwnSurname();
+
+               // Family name
+               String familyName = this.getContactManager().enterOwnFamilyName();
+
+               // And company
+               String companyName = this.getContactManager().enterOwnCompanyName();
+
+               // Update contact instance
+               contact.updateNameData(gender, surname, familyName, companyName);
+       }
+
+       @Override
+       public void doChangeOwnOtherData (final Contact contact) {
+               // Make sure it is own contact
+               if (!contact.isOwnContact()) {
+                       // Not own contact
+                       throw new IllegalArgumentException("Contact is not own data.");
+               }
+
+               // Phone number
+               String phoneNumber = this.getContactManager().enterOwnPhoneNumber();
+
+               // Phone number
+               String cellNumber = this.getContactManager().enterOwnCellNumber();
+
+               // Fax number
+               String faxNumber = this.getContactManager().enterOwnFaxNumber();
+
+               // Email address
+               String email = this.getContactManager().enterOwnEmailAddress();
+
+               // Comment
+               String comment = this.getContactManager().enterOwnComment();
+
+               // Update contact instance
+               contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment);
+       }
+
+       @Override
+       public Contact doEnterOwnData () {
+               // First ask for gender
+               char gender = this.getContactManager().enterOwnGender();
+
+               // 2nd for surname
+               String surname = this.getContactManager().enterOwnSurname();
+
+               // And 3rd for family name
+               String familyName = this.getContactManager().enterOwnFamilyName();
+
+               // Company name ...
+               String companyName = this.getContactManager().enterOwnCompanyName();
+
+               // Construct UserContact instance
+               Contact contact = new UserContact(gender, surname, familyName, companyName);
+
+               // And return object
+               return contact;
        }
-    }
-
-    /**
-     * Displays a textual other data "box" of given contact
-     *
-     * @param contact Contact to show other data for
-     */
-    @Override
-    public void displayOtherDataBox (final Contact contact) {
-       // Cellphone and such ...
-       this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));
-    }
-
-    @Override
-    public void doChangeOwnAddressData (final Contact contact) {
-       // Make sure it is own contact
-       if (!contact.isOwnContact()) {
-           // Not own contact
-           throw new IllegalArgumentException("Contact is not own data.");
+
+       /**
+        * Shutdown this client
+        */
+       @Override
+       public void doShutdown () {
+               // Parent call
+               super.doShutdown();
+
+               // @TODO Add other shutdown stuff
        }
 
-       // Own address data
-       String street = this.getContactManager().enterOwnStreet();
+       @Override
+       public void doUserMenuChoice () throws UnhandledUserChoiceException {
+               // Get all access keys from menu
+               char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());
+
+               // Output textural message and ask for a char as input
+               char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");
 
-       // Get zip code
-       int zipCode = this.getContactManager().enterOwnZipCode();
+               // @TODO Rewrite this ugly switch() block
+               switch (choice) {
+                       case '1': // Enter/add own data
+                               this.getContactManager().doEnterOwnData();
+                               break;
 
-       // Get city name
-       String city = this.getContactManager().enterOwnCity();
+                       case '2': // Change own data
+                               this.getContactManager().doChangeOwnData();
+                               break;
 
-       // Get country code
-       String countryCode = this.getContactManager().enterOwnCountryCode();
+                       case '3': // Add new addess
+                               this.getContactManager().doAddOtherAddress();
+                               break;
 
-       // Update address data
-       contact.updateAddressData(street, zipCode, city, countryCode);
-    }
+                       case '4': // List contacts
+                               this.getContactManager().doListContacts();
+                               break;
 
-    @Override
-    public void doChangeOwnNameData (final Contact contact) {
-       // Make sure it is own contact
-       if (!contact.isOwnContact()) {
-           // Not own contact
-           throw new IllegalArgumentException("Contact is not own data.");
+                       case '5': // Search addresses
+                               this.getContactManager().doSearchContacts();
+                               break;
+
+                       case '6': // Change other addess
+                               this.getContactManager().doChangeOtherAddress();
+                               break;
+
+                       case '7': // Delete other address
+                               this.getContactManager().doDeleteOtherAddress();
+                               break;
+
+                       case '0': // Program exit
+                               this.getApplication().doShutdown();
+                               break;
+
+                       default:
+                               // @TODO throw own exception
+                               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));
+               }
        }
 
-       // Gender:
-       char gender = this.getContactManager().enterOwnGender();
+       /**
+        * Asks the the user to enter a single character which must match validChars
+        *
+        * @param       validChars Valid chars that are accepted
+        * @param       message Message to user
+        * @return      Allowed character
+        */
+       @Override
+       public char enterChar (final char[] validChars, final String message) {
+               char input = 0;
+
+               // Sort array, else binarySearch() won't work
+               Arrays.sort(validChars);
+
+               // Keep asking until valid char has been entered
+               while (Arrays.binarySearch(validChars, input) < 0) {
+                       // Output message
+                       System.out.print(message);
+
+                       // Read char
+                       input = this.readChar();
+               }
+
+               // Return read char
+               return input;
+       }
+
+       /**
+        * Reads an integer (int) with a textural message from the user
+        *
+        * @param minimum Minimum allowed number
+        * @param maximum Maximum allowed number
+        * @param message Messager to display in console
+        * @return
+        */
+       @Override
+       public int enterInt (final int minimum, final int maximum, final String message) {
+               // Minimum should not be below zero
+               assert (minimum >= 0);
+               assert (maximum > minimum);
+
+               // Init input
+               int input = -1;
+
+               while ((input < minimum) || (input > maximum)) {
+                       // Output message
+                       System.out.print(message);
+
+                       // Read integer from user
+                       input = this.readInt();
+               }
+
+               // Return it
+               return input;
+       }
 
-       // Surname
-       String surname = this.getContactManager().enterOwnSurname();
+       /**
+        * Reads a string of minimum and maximum length from the user
+        *
+        * @param minLength     Minimum length of the string to read
+        * @param maxLength     Maximum length of the string to read
+        * @param message       Message to user
+        * @param allowEmpty Whether to allow empty string
+        * @return Entered string by user or null for empty strings
+        */
+       @Override
+       public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {
+               // Check on length, e.g. country codes are excactly 2 chars long
+               assert (maxLength >= minLength);
+
+               // Init input
+               String input = null;
+
+               // Check if it is to short or to long
+               while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) {
+                       // Output message
+                       System.out.print(message);
+
+                       // Read line
+                       input = this.readString();
+               }
+
+               // Return it
+               return input;
+       }
 
-       // Family name
-       String familyName = this.getContactManager().enterOwnFamilyName();
+       /**
+        * Returns a console menu item
+        *
+        * @param accessKey Key to access the menu
+        * @param text Text to show to user
+        * @return A SelectableMenuItem
+        * @todo Make sure the access key is unique
+        */
+       @Override
+       public SelectableMenuItem getMenuItem (final char accessKey, final String text) {
+               // Return a new console menu item
+               return new ConsoleMenuItem(accessKey, text);
+       }
 
-       // And company
-       String companyName = this.getContactManager().enterOwnCompanyName();
+       /**
+        * Inizializes this client
+        */
+       @Override
+       public void init () {
+               // Init contact manager here
+               this.initContactManager();
 
-       // Update contact instance
-       contact.updateNameData(gender, surname, familyName, companyName);
-    }
+               // Fill menu map
+               this.fillMenuMap();
+       }
 
-    @Override
-    public void doChangeOwnOtherData (final Contact contact) {
-       // Make sure it is own contact
-       if (!contact.isOwnContact()) {
-           // Not own contact
-           throw new IllegalArgumentException("Contact is not own data.");
+       /**
+        * Displays textural message to the user
+        *
+        * @param message
+        */
+       @Override
+       public void outputMessage (final String message) {
+               System.out.println(message);
        }
 
-       // Phone number
-       String phoneNumber = this.getContactManager().enterOwnPhoneNumber();
-
-       // Phone number
-       String cellNumber = this.getContactManager().enterOwnCellNumber();
-
-       // Fax number
-       String faxNumber = this.getContactManager().enterOwnFaxNumber();
-
-       // Email address
-       String email = this.getContactManager().enterOwnEmailAddress();
-
-       // Comment
-       String comment = this.getContactManager().enterOwnComment();
-
-       // Update contact instance
-       contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment);
-    }
-
-    @Override
-    public Contact doEnterOwnData () {
-       // First ask for gender
-       char gender = this.getContactManager().enterOwnGender();
-
-       // 2nd for surname
-       String surname = this.getContactManager().enterOwnSurname();
-       
-       // And 3rd for family name
-       String familyName = this.getContactManager().enterOwnFamilyName();
-
-       // Company name ...
-       String companyName = this.getContactManager().enterOwnCompanyName();
-
-       // Construct UserContact instance
-       Contact contact = new UserContact(gender, surname, familyName, companyName);
-
-       // And return object
-       return contact;
-    }
-
-    /**
-     * Shutdown this client
-     */
-    @Override
-    public void doShutdown () {
-       // Parent call
-       super.doShutdown();
-
-       // @TODO Add other shutdown stuff
-    }
-
-    @Override
-    public void doUserMenuChoice () throws UnhandledUserChoiceException {
-       // Get all access keys from menu
-       char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());
-
-       // Output textural message and ask for a char as input
-       char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");
-
-       // @TODO Rewrite this ugly switch() block
-       switch (choice) {
-           case '1': // Enter/add own data
-               this.getContactManager().doEnterOwnData();
-               break;
-       
-           case '2': // Change own data
-               this.getContactManager().doChangeOwnData();
-               break;
-       
-           case '3': // Add new addess
-               this.getContactManager().doAddOtherAddress();
-               break;
-       
-           case '4': // List contacts
-               this.getContactManager().doListContacts();
-               break;
-       
-           case '5': // Search addresses
-               this.getContactManager().doSearchContacts();
-               break;
-
-           case '6': // Change other addess
-               this.getContactManager().doChangeOtherAddress();
-               break;
-       
-           case '7': // Delete other address
-               this.getContactManager().doDeleteOtherAddress();
-               break;
-
-           case '0': // Program exit
-               this.getApplication().doShutdown();
-               break;
-       
-           default:
-               // @TODO throw own exception
-               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));
+       /**
+        * Shows textural menu on console
+        */
+       @Override
+       public void showCurrentMenu () {
+               this.showMenu(this.getCurrentMenu());
        }
-    }
-
-    /**
-     * Asks the the user to enter a single character which must match validChars
-     * @param  validChars  Valid chars that are accepted
-     * @param  message     Message to user
-     * @return Allowed character
-     */
-    @Override
-    public char enterChar (final char[] validChars, final String message) {
-       char input = 0;
-
-       // Sort array, else binarySearch() won't work
-       Arrays.sort(validChars);
-
-       // Keep asking until valid char has been entered
-       while (Arrays.binarySearch(validChars, input) < 0) {
-           // Output message
-           System.out.print(message);
-
-           // Read char
-           input = this.readChar();
+
+       /**
+        * Shows given menu entry to user
+        *
+        * @param item Menu entry
+        */
+       @Override
+       public void showEntry (final SelectableMenuItem item) {
+               // Access key then text
+               this.outputMessage("[" + item.getAccessKey() + "] " + item.getText());
        }
 
-       // Return read char
-       return input;
-    }
-
-    /**
-     * Reads an integer (int) with a textural message from the user
-     * 
-     * @param minimum Minimum allowed number
-     * @param maximum Maximum allowed number
-     * @param message Messager to display in console
-     * @return 
-     */
-    @Override
-    public int enterInt (final int minimum, final int maximum, final String message) {
-       // Minimum should not be below zero
-       assert(minimum >= 0);
-       assert(maximum > minimum);
-
-       // Init input
-       int input = -1;
-
-       while ((input < minimum) || (input > maximum)) {
-           // Output message
-           System.out.print(message);
-
-           // Read integer from user
-           input = this.readInt();
+       /**
+        * Shows a textural message to the user
+        */
+       @Override
+       public void showWelcome () {
+               this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle()));
+               this.outputMessage("");
+               this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");
+
+               // Debug message
+               this.getLogger().debug("Intro shown to user");
        }
 
-       // Return it
-       return input;
-    }
-
-    /**
-     * Reads a string of minimum and maximum length from the user
-     * 
-     * @param minLength        Minimum length of the string to read
-     * @param maxLength        Maximum length of the string to read
-     * @param message  Message to user
-     * @param allowEmpty Whether to allow empty string
-     * @return Entered string by user or null for empty strings
-     */
-    @Override
-    public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {
-       // Check on length, e.g. country codes are excactly 2 chars long
-       assert(maxLength >= minLength);
-
-       // Init input
-       String input = null;
-
-       // Check if it is to short or to long
-       while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) {
-           // Output message
-           System.out.print(message);
-
-           // Read line
-           input = this.readString();
+       @Override
+       public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {
+               // Ask the user for editing [name], [a]ddress or [other] data
+               char choice = this.enterChar(new char[] {'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) ");
+
+               // @TODO Get rid of this ugly switch block, too
+               switch (choice) {
+                       case 'n': // Name data
+                               this.getContactManager().doChangeNameData(contact, this);
+                               break;
+
+                       case 'a': // Address data
+                               this.getContactManager().doChangeAddressData(contact, this);
+                               break;
+
+                       case 'o': // Other data
+                               this.getContactManager().doChangeOtherData(contact, this);
+                               break;
+
+                       case 'x': // Exit this menu
+                               // Ignored as it should go back
+                               break;
+
+                       default:
+                               // @TODO throw own exception
+                               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));
+               }
        }
 
-       // Return it
-       return input;
-    }
-
-    /**
-     * Returns a console menu item
-     * 
-     * @param accessKey Key to access the menu
-     * @param text Text to show to user
-     * @return A SelectableMenuItem
-     * @todo Make sure the access key is unique
-     */
-    @Override
-    public SelectableMenuItem getMenuItem (final char accessKey, final String text) {
-       // Return a new console menu item
-       return new ConsoleMenuItem(accessKey,text);
-    }
-
-    /**
-     * Inizializes this client
-     */
-    @Override
-    public void init () {
-       // Init contact manager here
-       this.initContactManager();
-
-       // Fill menu map
-       this.fillMenuMap();
-    }
-
-    /**
-     * Displays textural message to the user
-     * @param message
-     */
-    @Override
-    public void outputMessage (final String message) {
-       System.out.println(message);
-    }
-
-    /**
-     * Shows textural menu on console
-     */
-    @Override
-    public void showCurrentMenu () {
-       this.showMenu(this.getCurrentMenu());
-    }
-
-    /**
-     * Shows given menu entry to user
-     * 
-     * @param item Menu entry
-     */
-    @Override
-    public void showEntry (final SelectableMenuItem item) {
-       // Access key then text
-       this.outputMessage("[" + item.getAccessKey() + "] " + item.getText());
-    }
-
-    /**
-     * Shows a textural message to the user
-     */
-    @Override
-    public void showWelcome () {
-       this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle()));
-       this.outputMessage("");
-       this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");
-       
-       // Debug message
-       this.getLogger().debug("Intro shown to user");
-    }
-
-    @Override
-    public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {
-       // Ask the user for editing [name], [a]ddress or [other] data
-       char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) ");
-
-       // @TODO Get rid of this ugly switch block, too
-       switch (choice) {
-           case 'n': // Name data
-               this.getContactManager().doChangeNameData(contact, this);
-               break;
-
-           case 'a': // Address data
-               this.getContactManager().doChangeAddressData(contact, this);
-               break;
-
-           case 'o': // Other data
-               this.getContactManager().doChangeOtherData(contact, this);
-               break;
-
-           case 'x': // Exit this menu
-               // Ignored as it should go back
-               break;
-
-           default:
-               // @TODO throw own exception
-               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));
+       /**
+        * Reads one character
+        *
+        * @return A single character
+        */
+       private char readChar () {
+               // Read line
+               String input = this.scanner.nextLine();
+
+               // This must be only one character
+               if (input.length() != 1) {
+                       // Return zero
+                       return 0;
+               }
+
+               // Get char from first (and only) position
+               return input.charAt(0);
        }
-    }
-
-    /**
-     * Reads one character
-     * 
-     * @return A single character
-     */
-    private char readChar () {
-       // Read line
-       String input = this.scanner.nextLine();
-
-       // This must be only one character
-       if (input.length() != 1) {
-           // Return zero
-           return 0;
+
+       /**
+        * Reads an integer (int) from user
+        *
+        * @return An integer number
+        */
+       private int readInt () {
+               // First read a string
+               String input = this.readString();
+
+               // Init number with invalid value
+               int num = -1;
+
+               // Parse number, this can be risky
+               try {
+                       num = Integer.parseInt(input);
+               } catch (final NumberFormatException e) {
+                       this.outputMessage("Bitte geben Sie nur Zahlen ein!");
+                       this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage()));
+               }
+
+               // Return read number
+               return num;
        }
 
-       // Get char from first (and only) position
-       return input.charAt(0);
-    }
-
-    /**
-     * Reads an integer (int) from user
-     * 
-     * @return An integer number
-     */
-    private int readInt () {
-       // First read a string
-       String input = this.readString();
-
-       // Init number with invalid value
-       int num = -1;
-
-       // Parse number, this can be risky
-       try {
-           num = Integer.parseInt(input);
-       } catch (final NumberFormatException e) {
-           this.outputMessage("Bitte geben Sie nur Zahlen ein!");
-           this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage()));
+       /**
+        * Reads a string from a scanner until RETURN is pressed
+        *
+        * @return Read string from scanner
+        */
+       private String readString () {
+               return this.scanner.nextLine();
        }
 
-       // Return read number
-       return num;
-    }
-
-    /**
-     * Reads a string from a scanner until RETURN is pressed
-     * 
-     * @return Read string from scanner
-     */
-    private String readString () {
-       return this.scanner.nextLine();
-    }
-
-    /**
-     * Fills menu map with menu entries
-     */
-    @Override
-    protected final void fillMenuMap () {
-       // Initialize first (main) menu
-       Menu menu = new ConsoleMenu("main", this);
-       
-       // Add it
-       this.getMenus().put("main", menu);
-    }
+       /**
+        * Fills menu map with menu entries
+        */
+       @Override
+       protected final void fillMenuMap () {
+               // Initialize first (main) menu
+               Menu menu = new ConsoleMenu("main", this);
+
+               // Add it
+               this.getMenus().put("main", menu);
+       }
 }
index 35d94965e7b1452405a54f7135bc5a5a76b832ee..8f8cee6d1795935fd7a8789188676fa8aa760e47 100644 (file)
@@ -38,7 +38,7 @@ import org.mxchange.addressbook.BaseFrameworkSystem;
 import org.mxchange.addressbook.application.AddressbookApplication;
 import org.mxchange.addressbook.client.Client;
 import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException;
-import org.mxchange.addressbook.model.address.AddressTableModel;
+import org.mxchange.addressbook.model.contact.ContactTableModel;
 
 /**
  *
@@ -46,356 +46,359 @@ import org.mxchange.addressbook.model.address.AddressTableModel;
  */
 public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame {
 
-    /**
-     * Own instance
-     */
-    private static ClientFrame self;
-
-    /**
-     * 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);
+       /**
+        * Own instance
+        */
+       private static ClientFrame self;
+
+       /**
+        * 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;
        }
-       
-       // Return instance
-       return self;
-    }
-    /**
-     * Frame instance for "add own data"
-     */
-    private JMenuItem addOwnItem;
-
-    /**
-     * Instance to table model
-     */
-    private TableModel dataModel;
-
-    /**
-     * Table instance
-     */
-    private JTable dataTable;
-
-    /**
-     * Frame instance for "edit own data"
-     */
-    private JMenuItem editOwnItem;
-
-    /**
-     * Frame instance
-     */
-    private final JFrame frame;
-
-    /**
-     * Whether this frame has been initialized
-     */
-    private boolean isInitialized;
-
-    /**
-     * Status label needs to be updated
-     */
-    private JLabel statusLabel;
-
-    /**
-     * Creates an instance of this frame with a client instance
-     * 
-     * @param client
-     */
-    private AddressbookFrame (final Client client) {
-       // Debug line
-       this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client));
-
-       // Set frame instance
-       this.frame = new JFrame(AddressbookApplication.printableTitle());
-
-       // Set client here
-       this.setClient(client);
-    }
-
-    /**
-     * Shutdown this frame
-     */
-    @Override
-    public void doShutdown () {
-       // First only show shutdown status
-       this.updateStatus("shutdown");
-    }
-
-    /**
-     * Setups the frame, do not set isInitialized here
-     * 
-     * @param client Client instance
-     */
-    @Override
-    public void setupFrame (final Client client) {
-       // Debug line
-       this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", 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 disable "add" menu
-           this.addOwnItem.setEnabled(false);
-       } else {
-           // Disable "edit"
-           this.editOwnItem.setEnabled(false);
+       /**
+        * Frame instance for "add own data"
+        */
+       private JMenuItem addOwnItem;
+
+       /**
+        * Instance to table model
+        */
+       private TableModel dataModel;
+
+       /**
+        * Table instance
+        */
+       private JTable dataTable;
+
+       /**
+        * Frame instance for "edit own data"
+        */
+       private JMenuItem editOwnItem;
+
+       /**
+        * Frame instance
+        */
+       private final JFrame frame;
+
+       /**
+        * Whether this frame has been initialized
+        */
+       private boolean isInitialized;
+
+       /**
+        * Status label needs to be updated
+        */
+       private JLabel statusLabel;
+
+       /**
+        * Creates an instance of this frame with a client instance
+        *
+        * @param client
+        */
+       private AddressbookFrame (final Client client) {
+               // Debug line
+               this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client));
+
+               // Set frame instance
+               this.frame = new JFrame(AddressbookApplication.printableTitle());
+
+               // Set client here
+               this.setClient(client);
        }
 
-       // Make the frame visible
-       this.frame.setVisible(true);
-
-       // All done here
-       this.updateStatus("done");
-    }
-
-    /**
-     * Initalizes this frame. Having initComponents() exposed (publicly
-     * accessible) means that any other object can initialize components which
-     * you may not want.
-     * 
-     * @throws org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If this method has been called twice
-     */
-    @Override
-    public void init () throws FrameAlreadyInitializedException {
-       // Debug line
-       this.getLogger().trace("CALLED!");
-
-       // Has this frame been initialized?
-       if (this.isInitialized()) {
-           // Throw exception
-           throw new FrameAlreadyInitializedException();
+       /**
+        * Shutdown this frame
+        */
+       @Override
+       public void doShutdown () {
+               // First only show shutdown status
+               this.updateStatus("shutdown");
        }
 
-       // Init components
-       this.initComponents();
-
-       // Set flag
-       this.isInitialized = true;
-    }
-
-    /**
-     * Returns field isInitialized. This flag indicates whether this frame has been initialized or not.
-     * 
-     * @return Field isInitialized
-     */
-    @Override
-    public final boolean isInitialized () {
-       return this.isInitialized;
-    }
-
-    /**
-     * Shuts down the application.
-     */
-    @Override
-    public void shutdownApplication () {
-       // To do this, the frame must be initialized
-       if (!this.isInitialized()) {
-           // Not initalized, so bad call
-           this.getLogger().fatal("Bad call of shutdownApplication(). Please report this.");
-           return;
+       /**
+        * Setups the frame, do not set isInitialized here
+        *
+        * @param client Client instance
+        */
+       @Override
+       public void setupFrame (final Client client) {
+               // Debug line
+               this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", 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 disable "add" menu
+                       this.addOwnItem.setEnabled(false);
+               } else {
+                       // Disable "edit"
+                       this.editOwnItem.setEnabled(false);
+               }
+
+               // Make the frame visible
+               this.frame.setVisible(true);
+
+               // All done here
+               this.updateStatus("done");
        }
-       this.getClient().getApplication().doShutdown();
-    }
-
-    /**
-     * Initialize components
-     */
-    private void initComponents () {
-       // Debug line
-       this.getLogger().trace("CALLED!");
-
-       // Set default close operation
-       this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-       // Register shutdown listener
-       this.frame.addWindowListener(new WindowAdapter() {
-           /**
-            * Invoked when a window has been closed.
-            */
-           @Override
-           public void windowClosed(final WindowEvent e) {
-               // Shutdown application cleanly
-               self.shutdownApplication();
-           }
-
-           /**
-            * Invoked when a window is in the process of being closed.
-            * The close operation can be overridden at this point.
-            */
-           @Override
-           public void windowClosing(final WindowEvent e) {
-               // Also shutdown cleanly here
-               self.shutdownApplication();
-           }
-       });
-
-       // Setup layout manager
-       this.frame.setLayout(new BorderLayout(2, 2));
-
-       // Set window size
-       this.frame.setSize(700, 400);
-
-       // Center window in middle of screen, instead of top-left corner
-       this.frame.setLocationRelativeTo(null);
-
-       // Init menu system
-       initMenuSystem();
-
-       // Init table
-       initTable();
-
-       // Init status panel
-       initStatusPanel();
-    }
-
-    /**
-     * Initializes the menu system
-     */
-    private void initMenuSystem () {
-       // Init menu bar, menu and item instances
-       JMenuBar menuBar = new JMenuBar();
-       JMenu menu;
-       JMenuItem item;
+
+       /**
+        * Initalizes this frame. Having initComponents() exposed (publicly
+        * accessible) means that any other object can initialize components which
+        * you may not want.
+        *
+        * @throws
+        * org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If
+        * this method has been called twice
+        */
+       @Override
+       public void init () throws FrameAlreadyInitializedException {
+               // Debug line
+               this.getLogger().trace("CALLED!");
+
+               // Has this frame been initialized?
+               if (this.isInitialized()) {
+                       // Throw exception
+                       throw new FrameAlreadyInitializedException();
+               }
+
+               // Init components
+               this.initComponents();
+
+               // Set flag
+               this.isInitialized = true;
+       }
+
+       /**
+        * Returns field isInitialized. This flag indicates whether this frame has
+        * been initialized or not.
+        *
+        * @return Field isInitialized
+        */
+       @Override
+       public final boolean isInitialized () {
+               return this.isInitialized;
+       }
+
+       /**
+        * Shuts down the application.
+        */
+       @Override
+       public void shutdownApplication () {
+               // To do this, the frame must be initialized
+               if (!this.isInitialized()) {
+                       // Not initalized, so bad call
+                       this.getLogger().fatal("Bad call of shutdownApplication(). Please report this.");
+                       return;
+               }
+               this.getClient().getApplication().doShutdown();
+       }
+
+       /**
+        * Initialize components
+        */
+       private void initComponents () {
+               // Debug line
+               this.getLogger().trace("CALLED!");
+
+               // Set default close operation
+               this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+               // Register shutdown listener
+               this.frame.addWindowListener(new WindowAdapter() {
+                       /**
+                        * Invoked when a window has been closed.
+                        */
+                       @Override
+                       public void windowClosed (final WindowEvent e) {
+                               // Shutdown application cleanly
+                               self.shutdownApplication();
+                       }
+
+                       /**
+                        * Invoked when a window is in the process of being closed. The
+                        * close operation can be overridden at this point.
+                        */
+                       @Override
+                       public void windowClosing (final WindowEvent e) {
+                               // Also shutdown cleanly here
+                               self.shutdownApplication();
+                       }
+               });
+
+               // Setup layout manager
+               this.frame.setLayout(new BorderLayout(2, 2));
+
+               // Set window size
+               this.frame.setSize(700, 400);
+
+               // Center window in middle of screen, instead of top-left corner
+               this.frame.setLocationRelativeTo(null);
+
+               // Init menu system
+               initMenuSystem();
+
+               // Init table
+               initTable();
+
+               // Init status panel
+               initStatusPanel();
+       }
+
+       /**
+        * Initializes the menu system
+        */
+       private void initMenuSystem () {
+               // Init menu bar, menu and item instances
+               JMenuBar menuBar = new JMenuBar();
+               JMenu menu;
+               JMenuItem item;
 
        // Init some menus:
-       // 1) File menu
-       menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
+               // 1) File menu
+               menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text"));
 
        // Add menu items:
-       // 1.x) Exit program (should be last)
-       item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text"));
-       item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText"));
-
-       // Add listener to exit menu
-       item.addActionListener(new ActionListener() {
-           /**
-            * If the user has performed this action
-            *
-            * @param e An instance of an ActionEvent class
-            */
-           @Override
-           public void actionPerformed (final ActionEvent e) {
-               self.shutdownApplication();
-           }
-       });
-
-       // Add item -> menu
-       menu.add(item);
-
-       // Add menu -> menu bar
-       menuBar.add(menu);
+               // 1.x) Exit program (should be last)
+               item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text"));
+               item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText"));
+
+               // Add listener to exit menu
+               item.addActionListener(new ActionListener() {
+                       /**
+                        * If the user has performed this action
+                        *
+                        * @param e An instance of an ActionEvent class
+                        */
+                       @Override
+                       public void actionPerformed (final ActionEvent e) {
+                               self.shutdownApplication();
+                       }
+               });
+
+               // Add item -> menu
+               menu.add(item);
+
+               // Add menu -> menu bar
+               menuBar.add(menu);
 
        // Init some menus:
-       // 2) Addressbook menu
-       menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
-
-       // 2.1) Add own data
-       this.addOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.text"));
-       this.addOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.toolTipText"));
-
-       // Add listener to exit menu
-       this.addOwnItem.addActionListener(new ActionListener() {
-           /**
-            * If the user has performed this action
-            *
-            * @param e An instance of an ActionEvent class
-            */
-           @Override
-           public void actionPerformed (final ActionEvent e) {
-               self.getClient().getContactManager().doEnterOwnData();
-           }
-       });
-
-       // Add item -> menu
-       menu.add(this.addOwnItem);
-
-       // 2.2) Edit own data
-       this.editOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.text"));
-       this.editOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.toolTipText"));
-
-       // Add listener to exit menu
-       this.editOwnItem.addActionListener(new ActionListener() {
-           /**
-            * If the user has performed this action
-            *
-            * @param e An instance of an ActionEvent class
-            */
-           @Override
-           public void actionPerformed (final ActionEvent e) {
-               self.getClient().getContactManager().doChangeOwnData();
-           }
-       });
-
-       // Add item -> menu
-       menu.add(this.editOwnItem);
-
-       // Add menu -> menu bar
-       menuBar.add(menu);
-
-       // Add menu bar -> frame
-       this.frame.add(menuBar, BorderLayout.NORTH);
-    }
-
-    /**
-     * Initializes status panel
-     */
-    private void initStatusPanel () {
-       // Init status label (which needs to be updated
-       this.statusLabel = new JLabel();
-       this.updateStatus("initializing");
-
-       // Init status bar in south
-       JPanel panel = new JPanel();
-       panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
-       panel.add(this.statusLabel);
-       panel.setBorder(BorderFactory.createEtchedBorder());
-       
-       // Add panel to frame
-       this.frame.add(panel, BorderLayout.SOUTH);
-    }
-
-    /**
-     * Initializes the table which will show all contacts
-     */
-    private void initTable () {
-       // Instance table model
-       this.dataModel = new AddressTableModel(this.getClient());
-
-       // Instance table
-       this.dataTable = new JTable(this.dataModel);
-
-       // Add mouse listener
-       this.dataTable.addMouseListener(new MouseAdapter() {
-           /**
-            * If the user peformed a click on a cell
-            * 
-            * @param e Mouse event instance
-            */
-           @Override
-           public void mouseClicked(final MouseEvent e) {
-               throw new UnsupportedOperationException("Unfinished.");
-           }
-       });
-
-       // Add table to frame
-       this.frame.add(this.dataTable, BorderLayout.CENTER);
-    }
-
-    /**
-     * Updates status to given type
-     * 
-     * @param type Status type
-     */
-    private void updateStatus (final String type) {
-       // Set status message
-       this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel." + type + ".text"));
-    }
+               // 2) Addressbook menu
+               menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
+
+               // 2.1) Add own data
+               this.addOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.text"));
+               this.addOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.toolTipText"));
+
+               // Add listener to exit menu
+               this.addOwnItem.addActionListener(new ActionListener() {
+                       /**
+                        * If the user has performed this action
+                        *
+                        * @param e An instance of an ActionEvent class
+                        */
+                       @Override
+                       public void actionPerformed (final ActionEvent e) {
+                               self.getClient().getContactManager().doEnterOwnData();
+                       }
+               });
+
+               // Add item -> menu
+               menu.add(this.addOwnItem);
+
+               // 2.2) Edit own data
+               this.editOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.text"));
+               this.editOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.toolTipText"));
+
+               // Add listener to exit menu
+               this.editOwnItem.addActionListener(new ActionListener() {
+                       /**
+                        * If the user has performed this action
+                        *
+                        * @param e An instance of an ActionEvent class
+                        */
+                       @Override
+                       public void actionPerformed (final ActionEvent e) {
+                               self.getClient().getContactManager().doChangeOwnData();
+                       }
+               });
+
+               // Add item -> menu
+               menu.add(this.editOwnItem);
+
+               // Add menu -> menu bar
+               menuBar.add(menu);
+
+               // Add menu bar -> frame
+               this.frame.add(menuBar, BorderLayout.NORTH);
+       }
+
+       /**
+        * Initializes status panel
+        */
+       private void initStatusPanel () {
+               // Init status label (which needs to be updated
+               this.statusLabel = new JLabel();
+               this.updateStatus("initializing");
+
+               // Init status bar in south
+               JPanel panel = new JPanel();
+               panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
+               panel.add(this.statusLabel);
+               panel.setBorder(BorderFactory.createEtchedBorder());
+
+               // Add panel to frame
+               this.frame.add(panel, BorderLayout.SOUTH);
+       }
+
+       /**
+        * Initializes the table which will show all contacts
+        */
+       private void initTable () {
+               // Instance table model
+               this.dataModel = new ContactTableModel(this.getClient());
+
+               // Instance table
+               this.dataTable = new JTable(this.dataModel);
+
+               // Add mouse listener
+               this.dataTable.addMouseListener(new MouseAdapter() {
+                       /**
+                        * If the user peformed a click on a cell
+                        *
+                        * @param e Mouse event instance
+                        */
+                       @Override
+                       public void mouseClicked (final MouseEvent e) {
+                               throw new UnsupportedOperationException("Unfinished.");
+                       }
+               });
+
+               // Add table to frame
+               this.frame.add(this.dataTable, BorderLayout.CENTER);
+       }
+
+       /**
+        * Updates status to given type
+        *
+        * @param type Status type
+        */
+       private void updateStatus (final String type) {
+               // Set status message
+               this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel." + type + ".text"));
+       }
 }
index 24bec9870cb0ac279e49ffbfd955efbad4fe2abd..6a7d6b0b6b232df76c59b6952e3668e30031ab35 100644 (file)
@@ -27,32 +27,35 @@ import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException;
  */
 public interface ClientFrame extends FrameworkInterface {
 
-    /**
-     * Shutdown this frame
-     */
-    public void doShutdown ();
+       /**
+        * Shutdown this frame
+        */
+       public void doShutdown ();
 
-    /**
-     * Setups the frame (and starts it). You have to call init() before you
can call this method.
-     * 
-     * @param client Client instance
-     */
-    public void setupFrame (final Client client);
+       /**
+        * Setups the frame (and starts it). You have to call init() before you can
       * call this method.
+        *
+        * @param client Client instance
+        */
+       public void setupFrame (final Client client);
 
-    /**
-     * Initializes frame
-     * 
-     * @throws org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If this method has been called twice
-     */
-    public void init () throws FrameAlreadyInitializedException;
+       /**
+        * Initializes frame
+        *
+        * @throws
+        * org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If
+        * this method has been called twice
+        */
+       public void init () throws FrameAlreadyInitializedException;
 
-    /**
-     * Returns field isInitialized. This flag indicates whether this frame has been initialized or not.
-     * 
-     * @return Field isInitialized
-     */
-    public boolean isInitialized ();
+       /**
+        * Returns field isInitialized. This flag indicates whether this frame has
+        * been initialized or not.
+        *
+        * @return Field isInitialized
+        */
+       public boolean isInitialized ();
 
-    public void shutdownApplication ();
+       public void shutdownApplication ();
 }
index 0914828179e3844ca20acb1e5cb488afc82990b6..c9ed4f6d674f15346223e935c43caaa1bec6eda8 100644 (file)
@@ -30,188 +30,188 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem;
  * @author Roland Haeder
  */
 public class SwingClient extends BaseClient implements Client {
-    /**
-     * Swing frame instance
-     */
-    private final ClientFrame frame;
-
-    /**
-     * Constructor with an Application instance.
-     * 
-     * @param application Application instance
-     */
-    public SwingClient (final Application application) {
-       super();
 
-       // Debug message
-       this.getLogger().trace("CALLED!");
-
-       // Set application instance
-       this.setApplication(application);
-
-       // Init frame instance
-       this.frame = AddressbookFrame.getSelfInstance(this);
-    }
-
-    @Override
-    public void displayAddressBox (final Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void displayNameBox (final Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void displayOtherDataBox (final Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void doChangeOwnAddressData (Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void doChangeOwnNameData (Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void doChangeOwnOtherData (Contact contact) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public Contact doEnterOwnData () {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void doShutdown () {
-       // Debug message
-       this.getLogger().trace("CALLED!");
+       /**
+        * Swing frame instance
+        */
+       private final ClientFrame frame;
+
+       /**
+        * Constructor with an Application instance.
+        *
+        * @param application Application instance
+        */
+       public SwingClient (final Application application) {
+               super();
+
+               // Debug message
+               this.getLogger().trace("CALLED!");
+
+               // Set application instance
+               this.setApplication(application);
+
+               // Init frame instance
+               this.frame = AddressbookFrame.getSelfInstance(this);
+       }
+
+       @Override
+       public void displayAddressBox (final Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void displayNameBox (final Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void displayOtherDataBox (final Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void doChangeOwnAddressData (Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void doChangeOwnNameData (Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void doChangeOwnOtherData (Contact contact) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public Contact doEnterOwnData () {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void doShutdown () {
+               // Debug message
+               this.getLogger().trace("CALLED!");
 
-       // Parent call
-       super.doShutdown();
+               // Parent call
+               super.doShutdown();
 
-       // Shutdown frame
-       this.frame.doShutdown();
+               // Shutdown frame
+               this.frame.doShutdown();
 
        // @TODO Add other shutdown stuff
+               // Debug message
+               this.getLogger().trace("EXIT!");
+       }
 
+       @Override
+       public void doUserMenuChoice () throws UnhandledUserChoiceException {
        // Debug message
-       this.getLogger().trace("EXIT!");
-    }
+               //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
 
-    @Override
-    public void doUserMenuChoice () throws UnhandledUserChoiceException {
-       // Debug message
-       //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
-
-       // Not implemented here
-    }
-
-    @Override
-    public char enterChar (final char[] validChars, String message) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public int enterInt (final int minimum, final int maximum, final String message) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public Menu getMenu (final String menuType) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    /**
-     * Returns a Swing menu item
-     * 
-     * @param accessKey Key to access the menu
-     * @param text Text to show to user
-     * @return A SelectableMenuItem
-     */
-    @Override
-    public SelectableMenuItem getMenuItem (final char accessKey, final String text) {
-       // Debug message
-       this.getLogger().trace("CALLED!");
+               // Not implemented here
+       }
 
-       // Returns null as the menu is now no longer controlled here.
-       return null;
-    }
+       @Override
+       public char enterChar (final char[] validChars, String message) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
-    /**
-     * Inizializes this client
-     */
-    @Override
-    public void init () {
-       // Debug message
-       this.getLogger().trace("CALLED!");
+       @Override
+       public int enterInt (final int minimum, final int maximum, final String message) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
-       // Init contact manager here
-       this.initContactManager();
+       @Override
+       public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
-       try {
-           // Init frame
-           this.frame.init();
-       } catch (final FrameAlreadyInitializedException ex) {
-           this.getLogger().catching(ex);
-           System.exit(1);
+       @Override
+       public Menu getMenu (final String menuType) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
-       // Now start the frame
-       this.frame.setupFrame(this);
+       /**
+        * Returns a Swing menu item
+        *
+        * @param accessKey Key to access the menu
+        * @param text Text to show to user
+        * @return A SelectableMenuItem
+        */
+       @Override
+       public SelectableMenuItem getMenuItem (final char accessKey, final String text) {
+               // Debug message
+               this.getLogger().trace("CALLED!");
+
+               // Returns null as the menu is now no longer controlled here.
+               return null;
+       }
 
-       // Debug message
-       this.getLogger().trace("EXIT!");
-    }
+       /**
+        * Inizializes this client
+        */
+       @Override
+       public void init () {
+               // Debug message
+               this.getLogger().trace("CALLED!");
+
+               // Init contact manager here
+               this.initContactManager();
+
+               try {
+                       // Init frame
+                       this.frame.init();
+               } catch (final FrameAlreadyInitializedException ex) {
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
+
+               // Now start the frame
+               this.frame.setupFrame(this);
+
+               // Debug message
+               this.getLogger().trace("EXIT!");
+       }
 
-    @Override
-    public void outputMessage (final String message) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
+       @Override
+       public void outputMessage (final String message) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
-    @Override
-    public void showCurrentMenu () {
+       @Override
+       public void showCurrentMenu () {
        // Debug message
-       //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
+               //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
 
-       // Not implemented here
-    }
+               // Not implemented here
+       }
 
-    @Override
-    public void showEntry (final SelectableMenuItem item) {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
+       @Override
+       public void showEntry (final SelectableMenuItem item) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
-    @Override
-    public void showWelcome () {
-       // Debug message
-       this.getLogger().trace("CALLED!");
-
-       // Not implemented here
-    }
-
-    @Override
-    public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {
-       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    /**
-     * Fills menu map with swing menus
-     */
-    @Override
-    protected final void fillMenuMap () {
-       // Nothing to fill here as the Swing frame is handling this all
-       throw new UnsupportedOperationException("Not implemented.");
-    }
+       @Override
+       public void showWelcome () {
+               // Debug message
+               this.getLogger().trace("CALLED!");
+
+               // Not implemented here
+       }
+
+       @Override
+       public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       /**
+        * Fills menu map with swing menus
+        */
+       @Override
+       protected final void fillMenuMap () {
+               // Nothing to fill here as the Swing frame is handling this all
+               throw new UnsupportedOperationException("Not implemented.");
+       }
 }
index 975ce3f516826741bba66a66cc95f308fde2de96..f03a3c1bdf20c1ded94ccacfb5eb68ceeefbb4d0 100644 (file)
-/*\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
-     * Cellphone number\r
-     *\r
-     * @return the cellphoneNumber\r
-     */\r
-    public String getCellphoneNumber () {\r
-       return this.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
-    private 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
-    private 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
-    private 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
-    private 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
-    private 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
-    private 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
-    private 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
-    private 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
-     * Phone number\r
-     *\r
-     * @return the phoneNumber\r
-     */\r
-    public String getPhoneNumber () {\r
-       return this.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
-    protected final void setStreet (final String street) {\r
-       this.street = street;\r
-    }\r
-\r
-    /**\r
-     * Surname\r
-     *\r
-     * @return the surname\r
-     */\r
-    public final String getSurname () {\r
-       return this.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 final long getZipCode () {\r
-       return this.zipCode;\r
-    }\r
-\r
-    /**\r
-     * ZIP code\r
-     *\r
-     * @param zipCode the zipCode to set\r
-     */\r
-    protected final 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 final 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 final void enableFlagOwnContact () {\r
-       this.ownContact = true;\r
-    }\r
-\r
-    /**\r
-     * Surname\r
-     *\r
-     * @param surname the surname to set\r
-     */\r
-    protected final void setSurname (final String surname) {\r
-       this.surname = surname;\r
-    }\r
-\r
-    /**\r
-     * Phone number\r
-     *\r
-     * @param phoneNumber the phoneNumber to set\r
-     */\r
-    protected final void setPhoneNumber (final String phoneNumber) {\r
-       this.phoneNumber = phoneNumber;\r
-    }\r
-\r
-    /**\r
-     * House number\r
-     *\r
-     * @param houseNumber the houseNumber to set\r
-     */\r
-    protected final void setHouseNumber (final int houseNumber) {\r
-       this.houseNumber = houseNumber;\r
-    }\r
-\r
-    /**\r
-     * Cellphone number\r
-     *\r
-     * @param cellphoneNumber the cellphoneNumber to set\r
-     */\r
-    protected final void setCellphoneNumber (final String cellphoneNumber) {\r
-       this.cellphoneNumber = cellphoneNumber;\r
-    }\r
-\r
-    /**\r
-     * Birth day\r
-     *\r
-     * @param birthday the birthday to set\r
-     */\r
-    protected final void setBirthday (final String birthday) {\r
-       this.birthday = birthday;\r
-    }\r
-}\r
+/*
+ * 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.contact;
+
+import java.util.Objects;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.client.Client;
+
+/**
+ * A general contact
+ *
+ * @author Roland Haeder
+ * @version 0.0
+ * @since 0.0
+ */
+public class BaseContact extends BaseFrameworkSystem {
+
+       /**
+        * Birth day
+        */
+       private String birthday;
+
+       /**
+        * Cellphone number
+        */
+       private String cellphoneNumber;
+
+       /**
+        * City
+        */
+       private String city;
+
+       /**
+        * Optional comments
+        */
+       private String comment;
+
+       /**
+        * Companyname
+        */
+       private String companyName;
+
+       /**
+        * Country code
+        */
+       private String countryCode;
+
+       /**
+        * Email address
+        */
+       private String emailAddress;
+
+       /**
+        * Family name
+        */
+       private String familyName;
+
+       /**
+        * Fax number
+        */
+       private String faxNumber;
+
+       /**
+        * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
+        * Company
+        */
+       private char gender;
+
+       /**
+        * House number
+        */
+       private int houseNumber;
+
+       /**
+        * Marker whether this contact is user's own data
+        */
+       private boolean ownContact;
+
+       /**
+        * Phone number
+        */
+       private String phoneNumber;
+
+       /**
+        * Street
+        */
+       private String street;
+
+       /**
+        * Surname
+        */
+       private String surname;
+
+       /**
+        * ZIP code
+        */
+       private long zipCode;
+
+       /**
+        * No instances can be created of this class
+        */
+       protected BaseContact () {
+               super();
+       }
+
+       /**
+        * Check if contacts are same or throw an exception
+        *
+        * @param object Other possible contact class
+        * @return Whether both contacts are same
+        * @todo Needs a lot improvements
+        */
+       @Override
+       public boolean equals (Object object) {
+               // Is it same type?
+               if (!(object instanceof BaseContact)) {
+                       // Not equal types
+                       return false;
+               } else if (!(object instanceof Contact)) {
+                       // Not correct interface
+                       return false;
+               }
+
+               // Try to cast
+               Contact contact = (Contact) object;
+
+               // Now test some data @todo Definedly needs improvement
+               return ((this.getGender() == contact.getGender())
+                               && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
+                               && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
+       }
+
+       /**
+        * Birth day
+        *
+        * @return the birthday
+        */
+       public String getBirthday () {
+               return this.birthday;
+       }
+
+       /**
+        * Cellphone number
+        *
+        * @return the cellphoneNumber
+        */
+       public String getCellphoneNumber () {
+               return this.cellphoneNumber;
+       }
+
+       /**
+        * City
+        *
+        * @return the city
+        */
+       public String getCity () {
+               return this.city;
+       }
+
+       /**
+        * City
+        *
+        * @param city the city to set
+        */
+       private void setCity (final String city) {
+               this.city = city;
+       }
+
+       /**
+        * Comments
+        *
+        * @return the comment
+        */
+       public String getComment () {
+               return this.comment;
+       }
+
+       /**
+        * Comments
+        *
+        * @param comment the comment to set
+        */
+       private void setComment (final String comment) {
+               this.comment = comment;
+       }
+
+       /**
+        * Companyname
+        *
+        * @return the companyName
+        */
+       public String getCompanyName () {
+               return this.companyName;
+       }
+
+       /**
+        * Companyname
+        *
+        * @param companyName the companyName to set
+        */
+       private void setCompanyName (final String companyName) {
+               this.companyName = companyName;
+       }
+
+       /**
+        * Country code
+        *
+        * @return the countryCode
+        */
+       public String getCountryCode () {
+               return this.countryCode;
+       }
+
+       /**
+        * Country code
+        *
+        * @param countryCode the countryCode to set
+        */
+       private void setCountryCode (final String countryCode) {
+               this.countryCode = countryCode;
+       }
+
+       /**
+        * "Serializes" this object into a CSV string (this time with semicolons)
+        *
+        * @return "CSV-serialized" version of the stored data
+        */
+       public String getCsvStringFromStoreableObject () {
+               // Get all together
+               String csvString = String.format(
+                               "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
+                               this.isOwnContact(),
+                               this.getGender(),
+                               this.getSurname(),
+                               this.getFamilyName(),
+                               this.getCompanyName(),
+                               this.getStreet(),
+                               this.getZipCode(),
+                               this.getCity(),
+                               this.getCountryCode(),
+                               this.getPhoneNumber(),
+                               this.getFaxNumber(),
+                               this.getCellphoneNumber(),
+                               this.getEmailAddress(),
+                               this.getBirthday(),
+                               this.getComment()
+               );
+
+               // Then return it
+               return csvString;
+       }
+
+       /**
+        * Email address
+        *
+        * @return the emailAddress
+        */
+       public String getEmailAddress () {
+               return this.emailAddress;
+       }
+
+       /**
+        * Email address
+        *
+        * @param emailAddress the emailAddress to set
+        */
+       private void setEmailAddress (final String emailAddress) {
+               this.emailAddress = emailAddress;
+       }
+
+       /**
+        * Family name
+        *
+        * @return the familyName
+        */
+       public String getFamilyName () {
+               return this.familyName;
+       }
+
+       /**
+        * Family name
+        *
+        * @param familyName the familyName to set
+        */
+       private void setFamilyName (final String familyName) {
+               this.familyName = familyName;
+       }
+
+       /**
+        * Fax number
+        *
+        * @return the faxNumber
+        */
+       public String getFaxNumber () {
+               return this.faxNumber;
+       }
+
+       /**
+        * Fax number
+        *
+        * @param faxNumber the faxNumber to set
+        */
+       private void setFaxNumber (final String faxNumber) {
+               this.faxNumber = faxNumber;
+       }
+
+       /**
+        * Gender of the contact
+        *
+        * @return the gender
+        */
+       public char getGender () {
+               return this.gender;
+       }
+
+       /**
+        * Gender of the contact
+        *
+        * @param gender the gender to set
+        */
+       private void setGender (final char gender) {
+               this.gender = gender;
+       }
+
+       /**
+        * House number
+        *
+        * @return the houseNumber
+        */
+       public int getHouseNumber () {
+               return this.houseNumber;
+       }
+
+       /**
+        * Phone number
+        *
+        * @return the phoneNumber
+        */
+       public String getPhoneNumber () {
+               return this.phoneNumber;
+       }
+
+       /**
+        * Street
+        *
+        * @return the street
+        */
+       public String getStreet () {
+               return this.street;
+       }
+
+       /**
+        * Street
+        *
+        * @param street the street to set
+        */
+       protected final void setStreet (final String street) {
+               this.street = street;
+       }
+
+       /**
+        * Surname
+        *
+        * @return the surname
+        */
+       public final String getSurname () {
+               return this.surname;
+       }
+
+       /**
+        * Some "getter" for a translated/human-readable gender
+        *
+        * @return gender Human-readable gender
+        */
+       public String getTranslatedGender () {
+               // Default init
+               String translated = null;
+
+               // "Translate" it
+               switch (this.getGender()) {
+                       case 'M': // Mr.
+                               translated = "Herr";
+                               break;
+
+                       case 'F': // Mrs.
+                               translated = "Frau";
+                               break;
+
+                       case 'C': // "Company"
+                               translated = "Firma";
+                               break;
+
+                       default: // Unsupported
+                               this.getLogger().error("Gender " + this.getGender() + " not supported.");
+                               break;
+               }
+
+               // Return it
+               return translated;
+       }
+
+       /**
+        * ZIP code
+        *
+        * @return the zipCode
+        */
+       public final long getZipCode () {
+               return this.zipCode;
+       }
+
+       /**
+        * ZIP code
+        *
+        * @param zipCode the zipCode to set
+        */
+       protected final void setZipCode (final long zipCode) {
+               this.zipCode = zipCode;
+       }
+
+       @Override
+       public int hashCode () {
+               int hash = 7;
+               hash = 79 * hash + Objects.hashCode(this.getFamilyName());
+               hash = 79 * hash + this.getGender();
+               hash = 79 * hash + Objects.hashCode(this.getSurname());
+               return hash;
+       }
+
+       /**
+        * Checks whether the contact is user's own data
+        *
+        * @return Own data?
+        */
+       public final boolean isOwnContact () {
+               return this.ownContact;
+       }
+
+       /**
+        * Shows this contact to the user
+        *
+        * @param client Client instance to use
+        */
+       public void show (final Client client) {
+               // Display name "box"
+               client.displayNameBox((Contact) this);
+
+               // Display address "box"
+               client.displayAddressBox((Contact) this);
+
+               // Display other data "box"
+               client.displayOtherDataBox((Contact) this);
+       }
+
+       /**
+        * Updates address data in this Contact instance
+        *
+        * @param street Street
+        * @param zipCode ZIP code
+        * @param city City
+        * @param countryCode Country code
+        */
+       public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
+               // Set all
+               if (street != null) {
+                       this.setStreet(street);
+               }
+               if (zipCode > 0) {
+                       this.setZipCode(zipCode);
+               }
+               if (city != null) {
+                       this.setCity(city);
+               }
+               if (countryCode != null) {
+                       this.setCountryCode(countryCode);
+               }
+       }
+
+       /**
+        * Updates name data in this Contact instance
+        *
+        * @param gender Gender (M, F, C)
+        * @param surname Surname
+        * @param familyName Family name
+        * @param companyName Company name
+        */
+       public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
+               // Set all
+               this.setGender(gender);
+               if (surname != null) {
+                       this.setSurname(surname);
+               }
+               if (familyName != null) {
+                       this.setFamilyName(familyName);
+               }
+               if (companyName != null) {
+                       this.setCompanyName(companyName);
+               }
+       }
+
+       /**
+        * Updates other data in this Contact instance
+        *
+        * @param phoneNumber Phone number
+        * @param cellphoneNumber Cellphone number
+        * @param faxNumber Fax number
+        * @param emailAddress Email address
+        * @param birthday Birth day
+        * @param comment Comments
+        */
+       public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
+               // Set all
+               if (phoneNumber != null) {
+                       this.setPhoneNumber(phoneNumber);
+               }
+               if (cellphoneNumber != null) {
+                       this.setCellphoneNumber(cellphoneNumber);
+               }
+               if (faxNumber != null) {
+                       this.setFaxNumber(faxNumber);
+               }
+               if (emailAddress != null) {
+                       this.setEmailAddress(emailAddress);
+               }
+               if (birthday != null) {
+                       this.setBirthday(birthday);
+               }
+               if (comment != null) {
+                       this.setComment(comment);
+               }
+       }
+
+       /**
+        * Enables the flag "own data" which signals that this contact is the user's
+        * own data.
+        */
+       protected final void enableFlagOwnContact () {
+               this.ownContact = true;
+       }
+
+       /**
+        * Surname
+        *
+        * @param surname the surname to set
+        */
+       protected final void setSurname (final String surname) {
+               this.surname = surname;
+       }
+
+       /**
+        * Phone number
+        *
+        * @param phoneNumber the phoneNumber to set
+        */
+       protected final void setPhoneNumber (final String phoneNumber) {
+               this.phoneNumber = phoneNumber;
+       }
+
+       /**
+        * House number
+        *
+        * @param houseNumber the houseNumber to set
+        */
+       protected final void setHouseNumber (final int houseNumber) {
+               this.houseNumber = houseNumber;
+       }
+
+       /**
+        * Cellphone number
+        *
+        * @param cellphoneNumber the cellphoneNumber to set
+        */
+       protected final void setCellphoneNumber (final String cellphoneNumber) {
+               this.cellphoneNumber = cellphoneNumber;
+       }
+
+       /**
+        * Birth day
+        *
+        * @param birthday the birthday to set
+        */
+       protected final void setBirthday (final String birthday) {
+               this.birthday = birthday;
+       }
+}
index 2860ee209332ae0a29b5cf7876eca6d458a3b8b3..76230fbdd5b2124bdbad18e89ca3bb902bf53c4d 100644 (file)
-/*\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
+/*
+ * 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.contact;
+
+import org.mxchange.addressbook.FrameworkInterface;
+import org.mxchange.addressbook.client.Client;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public interface Contact extends FrameworkInterface {
+
+       /**
+        * Some "getter" for translated gender of the contact
+        *
+        * @return Translated / human-readable gender
+        */
+       public String getTranslatedGender ();
+
+       /**
+        * Checks whether the contact is user's own data
+        *
+        * @return Own data?
+        */
+       public boolean isOwnContact ();
+
+       /**
+        * Gender of the contact
+        *
+        * @return the gender
+        */
+       public char getGender ();
+
+       /**
+        * Surname
+        *
+        * @return the surname
+        */
+       public String getSurname ();
+
+       /**
+        * Family name
+        *
+        * @return the familyName
+        */
+       public String getFamilyName ();
+
+       /**
+        * Companyname
+        *
+        * @return the companyName
+        */
+       public String getCompanyName ();
+
+       /**
+        * Street
+        *
+        * @return the street
+        */
+       public String getStreet ();
+
+       /**
+        * House number
+        *
+        * @return the houseNumber
+        */
+       public int getHouseNumber ();
+
+       /**
+        * ZIP code
+        *
+        * @return the zipCode
+        */
+       public long getZipCode ();
+
+       /**
+        * City
+        *
+        * @return the city
+        */
+       public String getCity ();
+
+       /**
+        * Country code
+        *
+        * @return the countryCode
+        */
+       public String getCountryCode ();
+
+       /**
+        * Email address
+        *
+        * @return the emailAddress
+        */
+       public String getEmailAddress ();
+
+       /**
+        * Phone number
+        *
+        * @return the phoneNumber
+        */
+       public String getPhoneNumber ();
+
+       /**
+        * Fax number
+        *
+        * @return the faxNumber
+        */
+       public String getFaxNumber ();
+
+       /**
+        * Cellphone number
+        *
+        * @return the cellphoneNumber
+        */
+       public String getCellphoneNumber ();
+
+       /**
+        * Birth day
+        *
+        * @return the birthday
+        */
+       public String getBirthday ();
+
+       /**
+        * Comments
+        *
+        * @return the comment
+        */
+       public String getComment ();
+
+       /**
+        * Shows the contact to the user
+        *
+        * @param client Client instance to call back
+        */
+       public void show (final Client client);
+
+       /**
+        * Updates address data in this Contact instance
+        *
+        * @param street Street
+        * @param zipCode ZIP code
+        * @param city City
+        * @param countryCode Country code
+        */
+       public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode);
+
+       /**
+        * Updates name data in this Contact instance
+        *
+        * @param gender Gender (M, F, C)
+        * @param surname Surname
+        * @param familyName Family name
+        * @param companyName Company name
+        */
+       public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);
+
+       /**
+        * Updates other data in this Contact instance
+        *
+        * @param phoneNumber Phone number
+        * @param cellNumber Cellphone number
+        * @param faxNumber Fax number
+        * @param email Email address
+        * @param birthday Birthday
+        * @param comment Comments
+        */
+       public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String birthday, final String comment);
+}
index 02d42183b22ba5f5556723948201c981183a6e79..2acc7750cbba64d779b908b73a1dd4a786efff25 100644 (file)
@@ -1,38 +1,38 @@
-/*\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
+/*
+ * 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.contact.book;
+
+import org.mxchange.addressbook.contact.BaseContact;
+import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;
+
+/**
+ * A contact that can be placed into "contact books"
+ *
+ * @author Roland Haeder
+ * @version 0.0
+ * @since 0.0
+ */
+public class BookContact extends BaseContact implements Contact, StoreableCsv {
+
+       /**
+        * Default constructor, may only be used from database backend
+        */
+       public BookContact () {
+       }
+
+}
index bf0e5228f9102318bcc0b1e42c6e1d0bfe4b1e6e..5a530b0bfe9b40b87c77e1e0c54e4a7a2fccd552 100644 (file)
@@ -1,53 +1,54 @@
-/*\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
-       // Update all data\r
-       this.updateNameData(gender, surname, familyName, companyName);\r
-    }\r
-\r
-    /**\r
-     * Default constructor, may only be used from database backend\r
-     */\r
-    public UserContact () {\r
-       this.enableFlagOwnContact();\r
-    }\r
-}\r
+/*
+ * 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.contact.user;
+
+import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.book.BookContact;
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;
+
+/**
+ *
+ * @author Roland Haeder
+ * @todo After a Collection has been used in ContactManager, change to
+ * BaseContact
+ */
+public class UserContact extends BookContact implements Contact, StoreableCsv {
+
+       /**
+        * Creates own contact entry
+        *
+        * @param gender Gender to be set
+        * @param surname Surname to be set
+        * @param familyName Family name to be set
+        * @param companyName Company name
+        * @todo Add validation of data
+        */
+       public UserContact (final char gender, final String surname, final String familyName, final String companyName) {
+               // Make sure all constructors are called
+               this();
+
+               // Update all data
+               this.updateNameData(gender, surname, familyName, companyName);
+       }
+
+       /**
+        * Default constructor, may only be used from database backend
+        */
+       public UserContact () {
+               this.enableFlagOwnContact();
+       }
+}
index 539f6d2c43528defe79a6538a8d95795aaa82ec8..b992e61370e66e2756989aa7a85f191199682b63 100644 (file)
@@ -1,32 +1,33 @@
-/*\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
+/*
+ * 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.database.backend;
+
+import org.mxchange.addressbook.BaseFrameworkSystem;
+
+/**
+ * Generall database backend
+ *
+ * @author Roland Haeder
+ */
+public class BaseDatabaseBackend extends BaseFrameworkSystem {
+
+       /**
+        * No instances from this class
+        */
+       protected BaseDatabaseBackend () {
+       }
+}
index 5b2d42d1844baf395fb320591e9c8f06e16c470f..1298c76cdefe81960f75eeec87c7fa8e53e6c2bb 100644 (file)
@@ -1,54 +1,54 @@
-/*\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
+/*
+ * 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.database.backend;
+
+import java.io.IOException;
+import org.mxchange.addressbook.FrameworkInterface;
+import org.mxchange.addressbook.database.storage.Storeable;
+
+/**
+ * A generic interface for database frontends
+ *
+ * @author Roland Haeder
+ */
+public interface DatabaseBackend extends FrameworkInterface {
+
+       /**
+        * Shuts down this backend
+        */
+       public void doShutdown ();
+
+       /**
+        * Rewinds backend
+        */
+       public void rewind ();
+
+       /**
+        * Get length of underlaying file
+        *
+        * @return Length of underlaying file
+        */
+       public long length ();
+
+       /**
+        * Stores an object in the database.
+        *
+        * @param object Object to store in database
+        * @throws java.io.IOException From inner class
+        */
+       public void store (final Storeable object) throws IOException;
+}
index 525f624ac13593f81aa21dde2212e0bfc293bde3..ada432eadb191336f7ea48c33cbd6db45ffe1262 100644 (file)
@@ -27,11 +27,12 @@ import org.mxchange.addressbook.exceptions.BadTokenException;
  */
 public interface CsvBackend extends DatabaseBackend {
 
-    /**
-     * Gets an iterator for contacts
-     * 
-     * @return Iterator for contacts
-     * @throws org.mxchange.addressbook.exceptions.BadTokenException If the CSV token is badly formulated
-     */
-    public Iterator<Contact> contactIterator () throws BadTokenException;
+       /**
+        * Gets an iterator for contacts
+        *
+        * @return Iterator for contacts
+        * @throws org.mxchange.addressbook.exceptions.BadTokenException If the CSV
+        * token is badly formulated
+        */
+       public Iterator<Contact> contactIterator () throws BadTokenException;
 }
index 7540254ee2c7c193ecea5265600d76f2e22aff04..bc7e001eb44ee7f6201d2ae17c8dbccb72ba3923 100644 (file)
@@ -35,467 +35,469 @@ import org.mxchange.addressbook.exceptions.BadTokenException;
 
 /**
  * A database backend with CSV file as storage implementation
- * 
+ *
  * @author Roland Haeder
  */
 public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend {
-    /**
-     * Output stream for this storage engine
-     */
-    private RandomAccessFile storageFile;
-
-    /**
-     * Constructor with table name
-     * 
-     * @param tableName Name of "table"
-     */
-    public CsvDatabaseBackend (final String tableName) {
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName));
-
-       // Set table name here, too
-       this.setTableName(tableName);
-
-       // Construct file name
-       String fileName = String.format("data/table_%s.csv", tableName);
-
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));
-
-       try {
-           // Try to initialize the storage (file instance)
-           this.storageFile = new RandomAccessFile(fileName, "rw");
-       } catch (final FileNotFoundException ex) {
-           // Did not work
-           this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString()));
-           System.exit(1);
-       }
 
-       // Output message
-       this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName));
-    }
-
-    /**
-     * Gets an iterator for contacts
-     * 
-     * @return Iterator for contacts
-     * @throws org.mxchange.addressbook.exceptions.BadTokenException If the underlaying method has found an invalid token
-     */
-    @Override
-    public Iterator<Contact> contactIterator () throws BadTokenException {
-       /*
-        * Then read the file into RAM (yes, not perfect for >1000 entries ...)
-        * and get a List back.
+       /**
+        * Output stream for this storage engine
         */
-       List<Contact> list = this.readContactList();
-
-       // Get iterator from list and return it
-       return list.iterator();
-    }
-
-    /**
-     * Shuts down this backend
-     */
-    @Override
-    public void doShutdown () {
-       try {
-           // Close file
-           this.getStorageFile().close();
-       } catch (final IOException ex) {
-           this.getLogger().catching(ex);
-           System.exit(1);
-       }
-    }
-
-    /**
-     * Get length of underlaying file
-     *
-     * @return Length of underlaying file
-     */
-    @Override
-    public long length () {
-       long length = 0;
-       
-       try {
-           length = this.getStorageFile().length();
-           this.getLogger().debug(MessageFormat.format("length={0}", length));
-       } catch (final IOException ex) {
-           // Length cannot be determined
-           this.getLogger().catching(ex);
-           System.exit(1);
-       }
-       
-       // Return result
-        this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length));
-       return length;
-    }
-
-    /**
-     * Rewinds backend
-     */
-    @Override
-    public void rewind (){
-        this.getLogger().trace("CALLED!");
-
-       try {
-           // Rewind underlaying database file
-           this.getStorageFile().seek(0);
-       } catch (final IOException ex) {
-           this.getLogger().catching(ex);
-           System.exit(1);
-       }
+       private RandomAccessFile storageFile;
 
-       this.getLogger().trace("EXIT!");
-    }
-
-    /**
-     * Stores given object by "visiting" it
-     *
-     * @param object An object implementing Storeable
-     * @throws java.io.IOException From "inner" class
-     */
-    @Override
-    public void store (final Storeable object) throws IOException {
-       // Make sure the instance is there (DataOutput flawor)
-       assert(this.storageFile instanceof DataOutput);
-
-       // Try to cast it, this will fail if the interface is not implemented
-       StoreableCsv csv = (StoreableCsv) object;
-
-       // Now get a string from the object that needs to be stored
-       String str = csv.getCsvStringFromStoreableObject();
-
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));
-
-       // The string is now a valid CSV string
-       this.getStorageFile().writeBytes(str);
-    }
-
-    /**
-     * Adds given contact to list
-     * 
-     * @param contact Contact instance to add
-     * @param list List instance
-     */
-    private void addContactToList (final Contact contact, final List<Contact> list) {
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("contact={0}", contact));
-
-       // Is the contact read?
-       if (contact instanceof Contact) {
-           // Then add it
-           boolean added = list.add(contact);
-
-           // Debug message
-           this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));
-
-           // Has it been added?
-           if (!added) {
-               // Not added
-               this.getLogger().warn("Contact object has not been added.");
-           }
-       }
-    }
-
-    /**
-     * Returns storage file
-     * 
-     * @return Storage file instance
-     */
-    private RandomAccessFile getStorageFile () {
-       return this.storageFile;
-    }
-
-    /**
-     * Checks whether end of file has been reached
-     * 
-     * @return Whether lines are left to read
-     */
-    private boolean isEndOfFile () {
-       // Default is EOF
-       boolean isEof = true;
-
-       try {
-           isEof = (this.getStorageFile().getFilePointer() >= this.length());
-       } catch (final IOException ex) {
-           // Length cannot be determined
-           this.getLogger().catching(ex);
-       }
+       /**
+        * Constructor with table name
+        *
+        * @param tableName Name of "table"
+        */
+       public CsvDatabaseBackend (final String tableName) {
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName));
 
-       // Return status
-       this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof));
-       return isEof;
-    }
+               // Set table name here, too
+               this.setTableName(tableName);
 
-    /**
-     * Reads the database file, if available, and adds all read lines into
-     * the list.
-     * 
-     * @return A list with Contact instances
-     */
-    private List<Contact> readContactList () throws BadTokenException {
-       this.getLogger().trace("CALLED!");
+               // Construct file name
+               String fileName = String.format("data/table_%s.csv", tableName);
 
-       // First rewind
-       this.rewind();
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));
+
+               try {
+                       // Try to initialize the storage (file instance)
+                       this.storageFile = new RandomAccessFile(fileName, "rw");
+               } catch (final FileNotFoundException ex) {
+                       // Did not work
+                       this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString()));
+                       System.exit(1);
+               }
 
-       // Get file size and divide it by 140 (possible average length of one line)
-       int lines = Math.round(this.length() / 140 + 0.5f);
+               // Output message
+               this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName));
+       }
 
-       // Debug message
-       this.getLogger().debug(MessageFormat.format("lines={0}", lines));
+       /**
+        * Gets an iterator for contacts
+        *
+        * @return Iterator for contacts
+        * @throws org.mxchange.addressbook.exceptions.BadTokenException If the
+        * underlaying method has found an invalid token
+        */
+       @Override
+       public Iterator<Contact> contactIterator () throws BadTokenException {
+               /*
+                * Then read the file into RAM (yes, not perfect for >1000 entries ...)
+                * and get a List back.
+                */
+               List<Contact> list = this.readContactList();
+
+               // Get iterator from list and return it
+               return list.iterator();
+       }
 
-       // Instance list
-       // @TODO The maximum length could be guessed from file size?
-       List<Contact> list = new ArrayList<>(lines);
+       /**
+        * Shuts down this backend
+        */
+       @Override
+       public void doShutdown () {
+               try {
+                       // Close file
+                       this.getStorageFile().close();
+               } catch (final IOException ex) {
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
+       }
 
-       // Init variables
-       StringTokenizer tokenizer;
-       String line;
+       /**
+        * Get length of underlaying file
+        *
+        * @return Length of underlaying file
+        */
+       @Override
+       public long length () {
+               long length = 0;
+
+               try {
+                       length = this.getStorageFile().length();
+                       this.getLogger().debug(MessageFormat.format("length={0}", length));
+               } catch (final IOException ex) {
+                       // Length cannot be determined
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
 
-       // Read all lines
-       while (!this.isEndOfFile()) {
-           // Then read a line
-           line = this.readLine();
+               // Return result
+               this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length));
+               return length;
+       }
 
-           // Debug message
-           this.getLogger().debug(MessageFormat.format("line={0}", line));
+       /**
+        * Rewinds backend
+        */
+       @Override
+       public void rewind () {
+               this.getLogger().trace("CALLED!");
+
+               try {
+                       // Rewind underlaying database file
+                       this.getStorageFile().seek(0);
+               } catch (final IOException ex) {
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
 
-           // Then tokenize it
-           // @TODO Move this into separate method
-           tokenizer = new StringTokenizer(line, ";");
+               this.getLogger().trace("EXIT!");
+       }
 
-           // Count round
-           int count = 0;
+       /**
+        * Stores given object by "visiting" it
+        *
+        * @param object An object implementing Storeable
+        * @throws java.io.IOException From "inner" class
+        */
+       @Override
+       public void store (final Storeable object) throws IOException {
+               // Make sure the instance is there (DataOutput flawor)
+               assert (this.storageFile instanceof DataOutput);
 
-           // Init contact object
-           Contact contact = null;
+               // Try to cast it, this will fail if the interface is not implemented
+               StoreableCsv csv = (StoreableCsv) object;
 
-           // The tokens are now available, so get all
-           while (tokenizer.hasMoreElements()) {
-               // Get next token
-               String token = tokenizer.nextToken();
+               // Now get a string from the object that needs to be stored
+               String str = csv.getCsvStringFromStoreableObject();
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("token={0}", token));
-
-               // Verify token, it must have double-quotes on each side
-               if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {
-                   // Something bad was read
-                   throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));
-               }
-
-               // All fine, so remove it
-               String strippedToken = token.substring(1, token.length() - 1);
+               this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));
 
-               // Is the string's content "null"?
-               if (strippedToken.equals("null")) {
-                   // Debug message
-                   this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken));
-
-                   // This needs to be set to null
-                   strippedToken = null;
-               }
+               // The string is now a valid CSV string
+               this.getStorageFile().writeBytes(str);
+       }
 
+       /**
+        * Adds given contact to list
+        *
+        * @param contact Contact instance to add
+        * @param list List instance
+        */
+       private void addContactToList (final Contact contact, final List<Contact> list) {
                // Debug message
-               this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));
-
-               // Init number/string data values
-               String strData = strippedToken;
-               Long num = null;
-               Boolean bool = null;
-               char gender = '?';
-               
-               // Now, let's try a number check, if no null
-               if (strippedToken != null) {
-                   // Okay, no null, maybe the string bears a decimal number?
-                   try {
-                       num = Long.valueOf(strippedToken);
+               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
 
-                       // Debug message
-                       this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken));
-                   } catch (final NumberFormatException ex) {
-                       // No number, then set default
-                       num = null;
-                   }
-               }
-               
-               // Now, let's try a boolean check, if no null
-               if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) {
-                   // Debug message
-                   this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken));
-
-                   // parseBoolean() is relaxed, so no exceptions
-                   bool = Boolean.valueOf(strippedToken);
-               }
-               
-               // Now, let's try a boolean check, if no null
-               if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {
-                   // Get first character
-                   gender = strippedToken.charAt(0);
-               }
-
-               // Now it depends on the counter which position we need to check
-               switch (count) {
-                   case 0: // isOwnContact
-                       assert((bool instanceof Boolean));
+               // Is the contact read?
+               if (contact instanceof Contact) {
+                       // Then add it
+                       boolean added = list.add(contact);
 
                        // Debug message
-                       this.getLogger().debug(MessageFormat.format("bool={0}", bool));
-
-                       // Is it own contact?
-                       if (true == bool) {
-                           // Debug message
-                           this.getLogger().debug("Creating UserContact object ...");
+                       this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));
 
-                           // Own entry
-                           contact = new UserContact();
-                       } else {
-                           // Debug message
-                           this.getLogger().debug("Creating BookContact object ...");
-
-                           // Other contact
-                           contact = new BookContact();
+                       // Has it been added?
+                       if (!added) {
+                               // Not added
+                               this.getLogger().warn("Contact object has not been added.");
                        }
-                       break;
+               }
+       }
 
-                   case 1: // Gender
-                       assert(contact instanceof Contact) : "First token was not boolean";
-                       assert(gender != '?') : "Gender is not detected.";
+       /**
+        * Returns storage file
+        *
+        * @return Storage file instance
+        */
+       private RandomAccessFile getStorageFile () {
+               return this.storageFile;
+       }
 
-                       // Update data
-                       contact.updateNameData(gender, null, null, null);
-                       break;
+       /**
+        * Checks whether end of file has been reached
+        *
+        * @return Whether lines are left to read
+        */
+       private boolean isEndOfFile () {
+               // Default is EOF
+               boolean isEof = true;
+
+               try {
+                       isEof = (this.getStorageFile().getFilePointer() >= this.length());
+               } catch (final IOException ex) {
+                       // Length cannot be determined
+                       this.getLogger().catching(ex);
+               }
 
-                   case 2: // Surname
-                       assert(contact instanceof Contact) : "First token was not boolean";
-                       assert(gender != '?') : "Gender is not detected.";
+               // Return status
+               this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof));
+               return isEof;
+       }
 
-                       // Update data
-                       contact.updateNameData(gender, strippedToken, null, null);
-                       break;
+       /**
+        * Reads the database file, if available, and adds all read lines into the
+        * list.
+        *
+        * @return A list with Contact instances
+        */
+       private List<Contact> readContactList () throws BadTokenException {
+               this.getLogger().trace("CALLED!");
 
-                   case 3: // Family name
-                       assert(contact instanceof Contact) : "First token was not boolean";
-                       assert(gender != '?') : "Gender is not detected.";
+               // First rewind
+               this.rewind();
 
-                       // Update data
-                       contact.updateNameData(gender, null, strippedToken, null);
-                       break;
+               // Get file size and divide it by 140 (possible average length of one line)
+               int lines = Math.round(this.length() / 140 + 0.5f);
 
-                   case 4: // Company name
-                       assert(contact instanceof Contact) : "First token was not boolean";
-                       assert(gender != '?') : "Gender is not detected.";
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("lines={0}", lines));
 
-                       // Update data
-                       contact.updateNameData(gender, null, null, strippedToken);
-                       break;
+       // Instance list
+               // @TODO The maximum length could be guessed from file size?
+               List<Contact> list = new ArrayList<>(lines);
 
-                   case 5: // Street number
-                       assert(contact instanceof Contact) : "First token was not boolean";
+               // Init variables
+               StringTokenizer tokenizer;
+               String line;
 
-                       // Update data
-                       contact.updateAddressData(strippedToken, 0, null, null);
-                       break;
+               // Read all lines
+               while (!this.isEndOfFile()) {
+                       // Then read a line
+                       line = this.readLine();
 
-                   case 6: // ZIP code
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("line={0}", line));
 
-                       // Update data
-                       contact.updateAddressData(null, num, null, null);
-                       break;
+           // Then tokenize it
+                       // @TODO Move this into separate method
+                       tokenizer = new StringTokenizer(line, ";");
+
+                       // Count round
+                       int count = 0;
+
+                       // Init contact object
+                       Contact contact = null;
+
+                       // The tokens are now available, so get all
+                       while (tokenizer.hasMoreElements()) {
+                               // Get next token
+                               String token = tokenizer.nextToken();
+
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("token={0}", token));
+
+                               // Verify token, it must have double-quotes on each side
+                               if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {
+                                       // Something bad was read
+                                       throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));
+                               }
+
+                               // All fine, so remove it
+                               String strippedToken = token.substring(1, token.length() - 1);
+
+                               // Is the string's content "null"?
+                               if (strippedToken.equals("null")) {
+                                       // Debug message
+                                       this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken));
+
+                                       // This needs to be set to null
+                                       strippedToken = null;
+                               }
+
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));
+
+                               // Init number/string data values
+                               String strData = strippedToken;
+                               Long num = null;
+                               Boolean bool = null;
+                               char gender = '?';
+
+                               // Now, let's try a number check, if no null
+                               if (strippedToken != null) {
+                                       // Okay, no null, maybe the string bears a decimal number?
+                                       try {
+                                               num = Long.valueOf(strippedToken);
+
+                                               // Debug message
+                                               this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken));
+                                       } catch (final NumberFormatException ex) {
+                                               // No number, then set default
+                                               num = null;
+                                       }
+                               }
+
+                               // Now, let's try a boolean check, if no null
+                               if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) {
+                                       // Debug message
+                                       this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken));
+
+                                       // parseBoolean() is relaxed, so no exceptions
+                                       bool = Boolean.valueOf(strippedToken);
+                               }
+
+                               // Now, let's try a boolean check, if no null
+                               if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {
+                                       // Get first character
+                                       gender = strippedToken.charAt(0);
+                               }
+
+                               // Now it depends on the counter which position we need to check
+                               switch (count) {
+                                       case 0: // isOwnContact
+                                               assert ((bool instanceof Boolean));
+
+                                               // Debug message
+                                               this.getLogger().debug(MessageFormat.format("bool={0}", bool));
+
+                                               // Is it own contact?
+                                               if (true == bool) {
+                                                       // Debug message
+                                                       this.getLogger().debug("Creating UserContact object ...");
+
+                                                       // Own entry
+                                                       contact = new UserContact();
+                                               } else {
+                                                       // Debug message
+                                                       this.getLogger().debug("Creating BookContact object ...");
+
+                                                       // Other contact
+                                                       contact = new BookContact();
+                                               }
+                                               break;
+
+                                       case 1: // Gender
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+                                               assert (gender != '?') : "Gender is not detected.";
+
+                                               // Update data
+                                               contact.updateNameData(gender, null, null, null);
+                                               break;
+
+                                       case 2: // Surname
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+                                               assert (gender != '?') : "Gender is not detected.";
+
+                                               // Update data
+                                               contact.updateNameData(gender, strippedToken, null, null);
+                                               break;
+
+                                       case 3: // Family name
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+                                               assert (gender != '?') : "Gender is not detected.";
+
+                                               // Update data
+                                               contact.updateNameData(gender, null, strippedToken, null);
+                                               break;
+
+                                       case 4: // Company name
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+                                               assert (gender != '?') : "Gender is not detected.";
+
+                                               // Update data
+                                               contact.updateNameData(gender, null, null, strippedToken);
+                                               break;
+
+                                       case 5: // Street number
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+
+                                               // Update data
+                                               contact.updateAddressData(strippedToken, 0, null, null);
+                                               break;
+
+                                       case 6: // ZIP code
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+
+                                               // Update data
+                                               contact.updateAddressData(null, num, null, null);
+                                               break;
+
+                                       case 7: // City name
+                                               assert (contact instanceof Contact) : "First token was not boolean";
+
+                                               // Update data
+                                               contact.updateAddressData(null, 0, strippedToken, null);
+                                               break;
 
-                   case 7: // City name
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 8: // Country code
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateAddressData(null, 0, strippedToken, null);
-                       break;
+                                               // Update data
+                                               contact.updateAddressData(null, 0, null, strippedToken);
+                                               break;
 
-                   case 8: // Country code
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 9: // Phone number
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateAddressData(null, 0, null, strippedToken);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(strippedToken, null, null, null, null, null);
+                                               break;
 
-                   case 9: // Phone number
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 10: // Fax number
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateOtherData(strippedToken, null, null, null, null, null);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(null, strippedToken, null, null, null, null);
+                                               break;
 
-                   case 10: // Fax number
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 11: // Cellphone number
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateOtherData(null, strippedToken, null, null, null, null);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(null, null, strippedToken, null, null, null);
+                                               break;
 
-                   case 11: // Cellphone number
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 12: // Email address
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateOtherData(null, null, strippedToken, null, null, null);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(null, null, null, strippedToken, null, null);
+                                               break;
 
-                   case 12: // Email address
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 13: // Birthday
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateOtherData(null, null, null, strippedToken, null, null);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(null, null, null, null, strippedToken, null);
+                                               break;
 
-                   case 13: // Birthday
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       case 14: // Birthday
+                                               assert (contact instanceof Contact) : "First token was not boolean";
 
-                       // Update data
-                       contact.updateOtherData(null, null, null, null, strippedToken, null);
-                       break;
+                                               // Update data
+                                               contact.updateOtherData(null, null, null, null, null, strippedToken);
+                                               break;
 
-                   case 14: // Birthday
-                       assert(contact instanceof Contact) : "First token was not boolean";
+                                       default: // New data entry
+                                               this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count));
+                                               break;
+                               }
 
-                       // Update data
-                       contact.updateOtherData(null, null, null, null, null, strippedToken);
-                       break;
+                               // Increment counter for next round
+                               count++;
+                       }
 
-                   default: // New data entry
-                       this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count));
-                       break;
+                       // Add contact
+                       this.addContactToList(contact, list);
                }
 
-               // Increment counter for next round
-               count++;
-           }
-
-           // Add contact
-           this.addContactToList(contact, list);
+               // Return finished list
+               this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size()));
+               return list;
        }
 
-       // Return finished list
-       this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size()));
-       return list;
-    }
-
-    /**
-     * Reads a line from file base
-     *
-     * @return Read line from file
-     */
-    private String readLine () {
-       // Init input
-       String input = null;
-
-       try {
-           input = this.getStorageFile().readLine();
-       } catch (final IOException ex) {
-           this.getLogger().catching(ex);
-       }
+       /**
+        * Reads a line from file base
+        *
+        * @return Read line from file
+        */
+       private String readLine () {
+               // Init input
+               String input = null;
+
+               try {
+                       input = this.getStorageFile().readLine();
+               } catch (final IOException ex) {
+                       this.getLogger().catching(ex);
+               }
 
-       // Return read string or null
-       return input;
-    }
+               // Return read string or null
+               return input;
+       }
 }
index 509dd66a2e4f10bfe558b65d9a8e8690cbd9aa12..9884a77f8d036d08931c9e2d9b82d3a52cbb0c79 100644 (file)
@@ -1,66 +1,66 @@
-/*\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 final 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 final 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
+/*
+ * 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.database.frontend;
+
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.database.backend.DatabaseBackend;
+import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend;
+
+/**
+ * General database frontend class
+ *
+ * @author Roland Haeder
+ */
+public class BaseDatabaseFrontend extends BaseFrameworkSystem {
+
+       /**
+        * Instance for database backend
+        */
+       private DatabaseBackend backend;
+
+       /**
+        * No instances from this class
+        */
+       protected BaseDatabaseFrontend () {
+       }
+
+       /**
+        * Instance for database backend
+        *
+        * @return the backend
+        */
+       protected final DatabaseBackend getBackend () {
+               return this.backend;
+       }
+
+       /**
+        * Instance for database backend
+        *
+        * @param backend the backend to set
+        */
+       protected final void setBackend (final DatabaseBackend backend) {
+               this.backend = backend;
+       }
+
+       /**
+        * Initialize backend
+        */
+       protected void initBackend () {
+               // Instance backend
+               this.backend = new CsvDatabaseBackend(this.getTableName());
+       }
+}
index 0bf6cc329688e4b28bbf76e908f01fca01c54007..ad50bffa5785864d535cb5a24566fc6b15837f13 100644 (file)
@@ -1,27 +1,27 @@
-/*\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
+/*
+ * 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.database.frontend;
+
+import org.mxchange.addressbook.FrameworkInterface;
+
+/**
+ * A generic interface for database frontends
+ *
+ * @author Roland Haeder
+ */
+public interface DatabaseWrapper extends FrameworkInterface {
+}
index c181b8816995b3620e8d9481a125a24fdbb40f8f..cfd7ec1a7caa959419e3907187a8af6a20375e67 100644 (file)
@@ -32,98 +32,100 @@ import org.mxchange.addressbook.manager.contact.ContactManager;
  * @author Roland Haeder
  */
 public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {
-    /**
-     * Constructor which accepts a contact manager
-     * @param manager
-     */
-    public ContactDatabaseFrontend (final ContactManager manager) {
-       // Call own constructor
-       this();
-       
-       // Set contact manager
-       this.setContactManager(manager);
-    }
-
-    /**
-     * Basic constrcutor
-     */
-    protected ContactDatabaseFrontend () {
-       super();
-
-       // Set "table" name
-       this.setTableName("contacts");
-
-       // Initalize backend
-       this.initBackend();
-    }
-
-    /**
-     * Shuts down the database layer
-     */
-    @Override
-    public void doShutdown () {
-       // Shutdown backend
-       this.getBackend().doShutdown();
-    }
-
-    /**
-     * Flushes all contact entries to database
-     */
-    @Override
-    public void flushAllContacts () {
-       // Get full list
-       List<Contact> contacts = this.getContactManager().getList();
-
-       // Get iterator
-       Iterator<Contact> iterator = contacts.iterator();
-
-       // Rewind backend
-       this.getBackend().rewind();
-
-       // Get all entries
-       while (iterator.hasNext()) {
-           // Get next entry
-           Contact contact = iterator.next();
-
-           try {
-               // Store this entry
-               this.getBackend().store((Storeable) contact);
-           } catch (final IOException ex) {
-               // Should not happen?
-               this.getLogger().catching(ex);
-               System.exit(1);
-           }
+
+       /**
+        * Constructor which accepts a contact manager
+        *
+        * @param manager
+        */
+       public ContactDatabaseFrontend (final ContactManager manager) {
+               // Call own constructor
+               this();
+
+               // Set contact manager
+               this.setContactManager(manager);
+       }
+
+       /**
+        * Basic constrcutor
+        */
+       protected ContactDatabaseFrontend () {
+               super();
+
+               // Set "table" name
+               this.setTableName("contacts");
+
+               // Initalize backend
+               this.initBackend();
+       }
+
+       /**
+        * Shuts down the database layer
+        */
+       @Override
+       public void doShutdown () {
+               // Shutdown backend
+               this.getBackend().doShutdown();
        }
-    }
-
-    /**
-     * Reads all contacts from database backend and handles them over to the
-     * contact manager
-     */
-    @Override
-    public void readAllContacts () {
-       // Get iterator and case it
-       CsvBackend backend = (CsvBackend) this.getBackend();
-       
-       // First rewind to beginning
-       this.getBackend().rewind();
-
-       // Get backend iterator
-       Iterator<Contact> iterator = null;
-       try {
-           iterator = backend.contactIterator();
-       } catch (final BadTokenException ex) {
-           this.getLogger().catching(ex);
-           System.exit(1);
+
+       /**
+        * Flushes all contact entries to database
+        */
+       @Override
+       public void flushAllContacts () {
+               // Get full list
+               List<Contact> contacts = this.getContactManager().getList();
+
+               // Get iterator
+               Iterator<Contact> iterator = contacts.iterator();
+
+               // Rewind backend
+               this.getBackend().rewind();
+
+               // Get all entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
+
+                       try {
+                               // Store this entry
+                               this.getBackend().store((Storeable) contact);
+                       } catch (final IOException ex) {
+                               // Should not happen?
+                               this.getLogger().catching(ex);
+                               System.exit(1);
+                       }
+               }
        }
 
-       // Read all entries
-       while (iterator.hasNext()) {
-           // Get next entry
-           Contact contact = iterator.next();
+       /**
+        * Reads all contacts from database backend and handles them over to the
+        * contact manager
+        */
+       @Override
+       public void readAllContacts () {
+               // Get iterator and case it
+               CsvBackend backend = (CsvBackend) this.getBackend();
+
+               // First rewind to beginning
+               this.getBackend().rewind();
+
+               // Get backend iterator
+               Iterator<Contact> iterator = null;
+               try {
+                       iterator = backend.contactIterator();
+               } catch (final BadTokenException ex) {
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
+
+               // Read all entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
 
-           // Add contact instance to manager
-           this.getContactManager().addContact(contact);
+                       // Add contact instance to manager
+                       this.getContactManager().addContact(contact);
+               }
        }
-    }
 }
index c14a3c33259dae6a0f920a5bc1e3c6728a539e61..86538a6fcbeb45fbbacc586512163910b524446b 100644 (file)
@@ -1,42 +1,42 @@
-/*\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
+/*
+ * 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/>.
+ */
+package org.mxchange.addressbook.database.frontend.contact;
+
+import org.mxchange.addressbook.database.frontend.DatabaseWrapper;
+
+/**
+ *
+ * @author Roland Häder
+ */
+public interface ContactWrapper extends DatabaseWrapper {
+
+       /**
+        * Shuts down the database layer
+        */
+       public void doShutdown ();
+
+       /**
+        * Flushes all contact entries to database
+        */
+       public void flushAllContacts ();
+
+       /**
+        * Reads all contacts from database backend and handles them over to the
+        * contact manager
+        */
+       public void readAllContacts ();
+}
index cd68048923d678c47ccd33b9ce067f22a04c52d2..ee97da3f72b1c91abba626aa54eeaecf6aa6a41b 100644 (file)
@@ -1,27 +1,27 @@
-/*\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
+/*
+ * 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.database.storage;
+
+import org.mxchange.addressbook.FrameworkInterface;
+
+/**
+ * An interface for objects being stored in databases
+ *
+ * @author Roland Haeder
+ */
+public interface Storeable extends FrameworkInterface {
+}
index 8901213c89723a0f830cbd4d3466ccae2e9a8228..31df57a430f6cca350aae418000e151dfb6b64fc 100644 (file)
@@ -20,13 +20,15 @@ import org.mxchange.addressbook.database.storage.Storeable;
 
 /**
  * An interface for classes which should be storeable as a CSV string
- * 
+ *
  * @author Roland Haeder
  */
 public interface StoreableCsv extends Storeable {
-    /**
-     * Getter for a CSV-formated string from object
-     * @return 
-     */
-    public String getCsvStringFromStoreableObject ();
+
+       /**
+        * Getter for a CSV-formated string from object
+        *
+        * @return
+        */
+       public String getCsvStringFromStoreableObject ();
 }
index ed37c2c81fda56ed822c94065ead64144d5db3ef..0c3bcb81f95c5a00b83c4f61807d93ce6bbfc3e4 100644 (file)
@@ -24,8 +24,8 @@ package org.mxchange.addressbook.exceptions;
  */
 public class BadTokenException extends Exception {
 
-    public BadTokenException (final String str) {
-       super(str);
-    }
-    
+       public BadTokenException (final String str) {
+               super(str);
+       }
+
 }
index 693ccc2cfc4c83d478acac8e9443d72a54373c11..db2c3e459881e47fc6b1ba73e049051237828d2b 100644 (file)
@@ -18,15 +18,15 @@ package org.mxchange.addressbook.exceptions;
 
 /**
  * This exception is thrown when initFrame() is called twice.
- * 
+ *
  * @author Roland Haeder
  */
 public class FrameAlreadyInitializedException extends Exception {
 
-    /**
-     * Default constructor
-     */
-    public FrameAlreadyInitializedException () {
-    }
-    
+       /**
+        * Default constructor
+        */
+       public FrameAlreadyInitializedException () {
+       }
+
 }
index b2149bb44b55b59a28a18afc34f1a2efdce743da..c14b9c4994dae805c8daf6787c204674b326b17d 100644 (file)
@@ -19,12 +19,12 @@ package org.mxchange.addressbook.exceptions;
 /**
  * This exception is thrown when the user made a valid choice but it was not
  * handled by the program.
- * 
+ *
  * @author Roland Haeder
  */
 public class UnhandledUserChoiceException extends Exception {
 
-    public UnhandledUserChoiceException (final String message) {
-       super(message);
-    }
+       public UnhandledUserChoiceException (final String message) {
+               super(message);
+       }
 }
index d845d92a36fb1d73ce95c0e8980062ad62bf070e..8be7407a60015d0ef7e58643c508ddd9dc3a2174 100644 (file)
@@ -1,36 +1,37 @@
-/*\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 implements Manageable {\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
+/*
+ * 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.manager;
+
+import org.mxchange.addressbook.BaseFrameworkSystem;
+
+/**
+ * A general manager
+ *
+ * @author Roland Haeder
+ * @version 0.0
+ * @since 0.0
+ */
+public class BaseManager extends BaseFrameworkSystem implements Manageable {
+
+       /**
+        * No instances can be created of this class
+        */
+       protected BaseManager () {
+               // Call any other super constructors
+               super();
+       }
+}
index 9afad3a739b4204aec042f2a18573d88a26d5c7e..16ec145ecfb4f6ff52647ff0b831c6a183c48153 100644 (file)
@@ -1,60 +1,62 @@
-/*\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
+/*
+ * 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.manager.application;
+
+import org.mxchange.addressbook.application.Application;
+import org.mxchange.addressbook.manager.BaseManager;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class ApplicationManager extends BaseManager implements ManageableApplication {
+
+       /**
+        * Getter for application manager
+        *
+        * @param application An instance of a Application class
+        * @return
+        */
+       public static final ManageableApplication getManager (final Application application) {
+               // Get manager
+               ManageableApplication manager = new ApplicationManager(application);
+
+               // Return manager
+               return manager;
+       }
+
+       /**
+        * Constructor for this manager
+        *
+        * @param application An instance of an Application class
+        */
+       private ApplicationManager (final Application application) {
+               super();
+
+               // Set application instance
+               this.setApplication(application);
+       }
+
+       @Override
+       public void start () {
+               // Bootstrap application
+               this.getApplication().doBootstrap();
+
+               // Run the main loop
+               this.getApplication().doMainLoop();
+       }
+}
index 325f83c30a6147fb89faa17441b5e17442ac08b6..8e732e7dffa9b3faddb15a42f970dd1eee8f4cc9 100644 (file)
@@ -1,30 +1,31 @@
-/*\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
+/*
+ * 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.manager.application;
+
+import org.mxchange.addressbook.manager.Manageable;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public interface ManageableApplication extends Manageable {
+
+       /**
+        * Launches application
+        */
+       public void start ();
+}
index 038d370d7ac27cd328d8dc65528e1404bc60613e..f14525f6c08a783730767dc3fb6030d50fddd70b 100644 (file)
@@ -36,585 +36,588 @@ import org.mxchange.addressbook.manager.BaseManager;
  * @version 0.0
  */
 public class ContactManager extends BaseManager implements ManageableContact {
-    /**
-     * Column name list
-     */
-    private final List<String> columnNames;
-
-    /**
-     * A ContactWrapper instance
-     */
-    private final ContactWrapper contactDatabase;
-
-    /**
-     * A list of all contacts
-     */
-    private final List<Contact> contacts;
-
-    /**
-     * Constructor which accepts maxContacts for maximum (initial) contacts and
-     * a client instance.
-     * 
-     * @param maxContacts Maximum allowed contacts
-     * @param client Client instance to use
-     */
-    public ContactManager (final int maxContacts, final Client client) {
-       // Always call super constructor first
-       super();
-
-       // Set client instance
-       this.setClient(client);
-
-       // Init contacts
-       this.contacts = new ArrayList<>(maxContacts);
-
-       // Init database connection
-       this.contactDatabase = new ContactDatabaseFrontend(this);
-
-       // Initialize list
-       this.columnNames = new ArrayList<>(15);
-
-       // And fill it
-       this.fillColumnNamesFromBundle();
-
-       // Read all entries
-       this.contactDatabase.readAllContacts();
+
+       /**
+        * Column name list
+        */
+       private final List<String> columnNames;
+
+       /**
+        * A ContactWrapper instance
+        */
+       private final ContactWrapper contactDatabase;
+
+       /**
+        * A list of all contacts
+        */
+       private final List<Contact> contacts;
+
+       /**
+        * Constructor which accepts maxContacts for maximum (initial) contacts and
+        * a client instance.
+        *
+        * @param maxContacts Maximum allowed contacts
+        * @param client Client instance to use
+        */
+       public ContactManager (final int maxContacts, final Client client) {
+               // Always call super constructor first
+               super();
+
+               // Set client instance
+               this.setClient(client);
+
+               // Init contacts
+               this.contacts = new ArrayList<>(maxContacts);
+
+               // Init database connection
+               this.contactDatabase = new ContactDatabaseFrontend(this);
+
+               // Initialize list
+               this.columnNames = new ArrayList<>(15);
+
+               // And fill it
+               this.fillColumnNamesFromBundle();
+
+               // Read all entries
+               this.contactDatabase.readAllContacts();
 
        // Debug message
-       //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
-    }
-
-    /**
-     * Adds given Contact instance to list
-     *
-     * @param contact Contact instance to add
-     */
-    @Override
-    public void addContact (final Contact contact) {
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-
-       this.contacts.add(contact);
-    }
-
-    /**
-     * Let the user add a new other address
-     */
-    @Override
-    public void doAddOtherAddress () {
-       throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    /**
-     * Let the user change address data
-     * 
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     */
-    @Override
-    public void doChangeAddressData (final Contact contact, final Client client) {
-       // First display it again
-       client.displayAddressBox(contact);
-
-       // Is it own data?
-       if (contact.isOwnContact()) {
-           // Deligate to client
-           this.getClient().doChangeOwnAddressData(contact);
-       } else {
-           // Other contact's address data to change
-           throw new UnsupportedOperationException("Changing contact entries not finished.");
-       }
-
-       // Flush whole list
-       this.flush();
-    }
-
-    /**
-     * Let the user change "name data"
-     * 
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     */
-    @Override
-    public void doChangeNameData (final Contact contact, final Client client) {
-       // First display them again
-       client.displayNameBox(contact);
-
-       // Is this own data?
-       if (contact.isOwnContact()) {
-           // Re-ask own data
-           this.getClient().doChangeOwnNameData(contact);
-       } else {
-           // Then re-ask them ...
-           throw new UnsupportedOperationException("Changing contact entries not finished.");
-       }
-
-       // Flush whole list
-       this.flush();
-    }
-
-    /**
-     * Let the user change other address
-     */
-    @Override
-    public void doChangeOtherAddress () {
-       throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    /**
-     * Let the user change other data
-     *
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     * @todo Didn't handle birthday
-     */
-    @Override
-    public void doChangeOtherData (final Contact contact, final Client client) {
-       // First display them again
-       this.getClient().displayOtherDataBox(contact);
-
-       // Is this own data?
-       if (contact.isOwnContact()) {
-           // Re-ask own data
-           this.getClient().doChangeOwnOtherData(contact);
-       } else {
-           // Then re-ask them ...
-           throw new UnsupportedOperationException("Changing contact entries not finished.");
-       }
-
-       // Flush whole list
-       this.flush();
-    }
-
-    /**
-     * Allows the user to change his/her own data
-     */
-    @Override
-    public void doChangeOwnData () {
-       /*
-        * First check if the user has registered own contact, before that
-        * nothing can be changed.
-        */
-       if (!this.isOwnContactAdded()) {
-           // Not added
-           this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben.");
-           
-           // Skip any below code
-           return;
-       }
-       
-       // Instance
-       Contact contact = this.getOwnContact();
-       
-       // It must be found
-       assert(contact instanceof Contact);
-       
-       // Display contact
-       contact.show(this.getClient());
-       
-       try {
-           // Ask user what to change
-           this.getClient().userChooseChangeContactData(contact);
-       } catch (final UnhandledUserChoiceException ex) {
-           this.getLogger().catching(ex);
-       }
-    }
-
-    /**
-     * Let the user delete other address
-     */
-    @Override
-    public void doDeleteOtherAddress () {
-       throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    /**
-     * Asks user for own data
-     */
-    @Override
-    public void doEnterOwnData () {
-       // Deligate this call to the client
-       Contact contact = this.getClient().doEnterOwnData();
-
-       // Add it to contact "book"
-       this.registerContact(contact);
-    }
-
-    @Override
-    public void doListContacts () {
-       throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    @Override
-    public void doSearchContacts () {
-       throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    /**
-     * Shuts down this contact manager
-     */
-    @Override
-    public void doShutdown () {
-       // Shut down the database layer
-       this.getContactDatabase().doShutdown();
-    }
-
-    /**
-     * Asks the user for his/her cellphone number
-     * 
-     * @return User's cellphone number
-     */
-    @Override
-    public String enterOwnCellNumber () {
-       return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);
-    }
-
-    /**
-     * Asks the user for his/her city's name
-     *
-     * @return City's name of the user
-     */
-    @Override
-    public String enterOwnCity () {
-       return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
-    }
-
-    /**
-     * Asks the user for his/her city's name
-     *
-     * @return City's name of the user
-     */
-    @Override
-    public String enterOwnComment () {
-       return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);
-    }
-
-    /**
-     * Asks the user for his/her company name
-     * 
-     * @return User's company name
-     */
-    @Override
-    public String enterOwnCompanyName () {
-       return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);
-    }
-
-    /**
-     * Asks user for his/her own country code
-     * 
-     * @return User's own country code
-     */
-    @Override
-    public String enterOwnCountryCode () {
-       return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();
-    }
-
-    /**
-     * Asks user for his/her own country code
-     * 
-     * @return User's own country code
-     */
-    @Override
-    public String enterOwnEmailAddress () {
-       return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);
-    }
-
-    /**
-     * Asks the user for family name
-     * 
-     * @return Family name of the user
-     */
-    @Override
-    public String enterOwnFamilyName () {
-       return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);
-    }
-
-    /**
-     * Asks the user for family name
-     * 
-     * @return Family name of the user
-     */
-    @Override
-    public String enterOwnFaxNumber () {
-       return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
-    }
-
-    /**
-     * Asks the user for gender, until a valid has been entered
-     * 
-     * @return Gender of the user
-     */
-    @Override
-    public char enterOwnGender () {
-       return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
-    }
-
-    /**
-     * Asks the user for phone number
-     * 
-     * @return Phone number of the user
-     */
-    @Override
-    public String enterOwnPhoneNumber () {
-       return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);
-    }
-
-    /**
-     * Asks the user for own street (including number)
-     * @return Own street an number
-     */
-    @Override
-    public String enterOwnStreet () {
-       return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
-    }
-
-    /**
-     * Asks the user for surname
-     * @return Surname of the user
-     */
-    @Override
-    public String enterOwnSurname () {
-       return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
-    }
-
-    /**
-     * Asks the user for own ZIP code
-     * 
-     * @return ZIP code
-     */
-    @Override
-    public int enterOwnZipCode () {
-       return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");
-    }
-
-    @Override
-    public final int getColumnCount () {
-       assert(this.columnNames instanceof List) : "this.columnNames is not initialized";
-
-       return this.columnNames.size();
-    }
-
-    /**
-     * Getter for column name at given index.
-     *
-     * @param columnIndex Column index
-     * @return Human-readable column name
-     */
-    @Override
-    public String getColumnName (final int columnIndex) {
-       assert(this.columnNames instanceof List) : "this.columnNames is not initialized";
-
-       // Get column name at index
-       return this.columnNames.get(columnIndex);
-    }
-
-    /**
-     * Getter for whole contact list
-     *
-     * @return List of all contacts
-     */
-    @Override
-    public List<Contact> getList () {
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-       return Collections.unmodifiableList(this.contacts);
-    }
-
-    /**
-     * Checks whether own contact is already added by checking all entries for
-     * isOwnContact flag
-     *
-     * @return Whether own contact is already added
-     */
-    @Override
-    public boolean isOwnContactAdded () {
-       // Trace message
-       this.getLogger().trace("CALLED!");
-
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-
-       // Default is not added
-       boolean isAdded = false;
-       
-       // Now get it back from address book, first get an iterator
-       Iterator<Contact> iterator = this.contacts.iterator();
-       
-       // Check entries
-       while (iterator.hasNext()) {
-           // Get next entry
-           Contact contact = iterator.next();
-           
-           // Is it valid?
-           if (contact instanceof Contact) {
-               // Get flag
-               isAdded = contact.isOwnContact();
-               
-               // Is this own contact?
-               if (isAdded) {
-                   // Then abort loop
-                   break;
+               //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
+       }
+
+       /**
+        * Adds given Contact instance to list
+        *
+        * @param contact Contact instance to add
+        */
+       @Override
+       public void addContact (final Contact contact) {
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
+
+               this.contacts.add(contact);
+       }
+
+       /**
+        * Let the user add a new other address
+        */
+       @Override
+       public void doAddOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       /**
+        * Let the user change address data
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        */
+       @Override
+       public void doChangeAddressData (final Contact contact, final Client client) {
+               // First display it again
+               client.displayAddressBox(contact);
+
+               // Is it own data?
+               if (contact.isOwnContact()) {
+                       // Deligate to client
+                       this.getClient().doChangeOwnAddressData(contact);
+               } else {
+                       // Other contact's address data to change
+                       throw new UnsupportedOperationException("Changing contact entries not finished.");
+               }
+
+               // Flush whole list
+               this.flush();
+       }
+
+       /**
+        * Let the user change "name data"
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        */
+       @Override
+       public void doChangeNameData (final Contact contact, final Client client) {
+               // First display them again
+               client.displayNameBox(contact);
+
+               // Is this own data?
+               if (contact.isOwnContact()) {
+                       // Re-ask own data
+                       this.getClient().doChangeOwnNameData(contact);
+               } else {
+                       // Then re-ask them ...
+                       throw new UnsupportedOperationException("Changing contact entries not finished.");
+               }
+
+               // Flush whole list
+               this.flush();
+       }
+
+       /**
+        * Let the user change other address
+        */
+       @Override
+       public void doChangeOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       /**
+        * Let the user change other data
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        * @todo Didn't handle birthday
+        */
+       @Override
+       public void doChangeOtherData (final Contact contact, final Client client) {
+               // First display them again
+               this.getClient().displayOtherDataBox(contact);
+
+               // Is this own data?
+               if (contact.isOwnContact()) {
+                       // Re-ask own data
+                       this.getClient().doChangeOwnOtherData(contact);
+               } else {
+                       // Then re-ask them ...
+                       throw new UnsupportedOperationException("Changing contact entries not finished.");
+               }
+
+               // Flush whole list
+               this.flush();
+       }
+
+       /**
+        * Allows the user to change his/her own data
+        */
+       @Override
+       public void doChangeOwnData () {
+               /*
+                * First check if the user has registered own contact, before that
+                * nothing can be changed.
+                */
+               if (!this.isOwnContactAdded()) {
+                       // Not added
+                       this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben.");
+
+                       // Skip any below code
+                       return;
+               }
+
+               // Instance
+               Contact contact = this.getOwnContact();
+
+               // It must be found
+               assert (contact instanceof Contact);
+
+               // Display contact
+               contact.show(this.getClient());
+
+               try {
+                       // Ask user what to change
+                       this.getClient().userChooseChangeContactData(contact);
+               } catch (final UnhandledUserChoiceException ex) {
+                       this.getLogger().catching(ex);
+               }
+       }
+
+       /**
+        * Let the user delete other address
+        */
+       @Override
+       public void doDeleteOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       /**
+        * Asks user for own data
+        */
+       @Override
+       public void doEnterOwnData () {
+               // Deligate this call to the client
+               Contact contact = this.getClient().doEnterOwnData();
+
+               // Add it to contact "book"
+               this.registerContact(contact);
+       }
+
+       @Override
+       public void doListContacts () {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       @Override
+       public void doSearchContacts () {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       /**
+        * Shuts down this contact manager
+        */
+       @Override
+       public void doShutdown () {
+               // Shut down the database layer
+               this.getContactDatabase().doShutdown();
+       }
+
+       /**
+        * Asks the user for his/her cellphone number
+        *
+        * @return User's cellphone number
+        */
+       @Override
+       public String enterOwnCellNumber () {
+               return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);
+       }
+
+       /**
+        * Asks the user for his/her city's name
+        *
+        * @return City's name of the user
+        */
+       @Override
+       public String enterOwnCity () {
+               return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
+       }
+
+       /**
+        * Asks the user for his/her city's name
+        *
+        * @return City's name of the user
+        */
+       @Override
+       public String enterOwnComment () {
+               return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);
+       }
+
+       /**
+        * Asks the user for his/her company name
+        *
+        * @return User's company name
+        */
+       @Override
+       public String enterOwnCompanyName () {
+               return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);
+       }
+
+       /**
+        * Asks user for his/her own country code
+        *
+        * @return User's own country code
+        */
+       @Override
+       public String enterOwnCountryCode () {
+               return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();
+       }
+
+       /**
+        * Asks user for his/her own country code
+        *
+        * @return User's own country code
+        */
+       @Override
+       public String enterOwnEmailAddress () {
+               return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);
+       }
+
+       /**
+        * Asks the user for family name
+        *
+        * @return Family name of the user
+        */
+       @Override
+       public String enterOwnFamilyName () {
+               return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);
+       }
+
+       /**
+        * Asks the user for family name
+        *
+        * @return Family name of the user
+        */
+       @Override
+       public String enterOwnFaxNumber () {
+               return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
+       }
+
+       /**
+        * Asks the user for gender, until a valid has been entered
+        *
+        * @return Gender of the user
+        */
+       @Override
+       public char enterOwnGender () {
+               return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
+       }
+
+       /**
+        * Asks the user for phone number
+        *
+        * @return Phone number of the user
+        */
+       @Override
+       public String enterOwnPhoneNumber () {
+               return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);
+       }
+
+       /**
+        * Asks the user for own street (including number)
+        *
+        * @return Own street an number
+        */
+       @Override
+       public String enterOwnStreet () {
+               return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
+       }
+
+       /**
+        * Asks the user for surname
+        *
+        * @return Surname of the user
+        */
+       @Override
+       public String enterOwnSurname () {
+               return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
+       }
+
+       /**
+        * Asks the user for own ZIP code
+        *
+        * @return ZIP code
+        */
+       @Override
+       public int enterOwnZipCode () {
+               return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");
+       }
+
+       @Override
+       public final int getColumnCount () {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized";
+
+               return this.columnNames.size();
+       }
+
+       /**
+        * Getter for column name at given index.
+        *
+        * @param columnIndex Column index
+        * @return Human-readable column name
+        */
+       @Override
+       public String getColumnName (final int columnIndex) {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized";
+
+               // Get column name at index
+               return this.columnNames.get(columnIndex);
+       }
+
+       /**
+        * Getter for whole contact list
+        *
+        * @return List of all contacts
+        */
+       @Override
+       public List<Contact> getList () {
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
+               return Collections.unmodifiableList(this.contacts);
+       }
+
+       /**
+        * Checks whether own contact is already added by checking all entries for
+        * isOwnContact flag
+        *
+        * @return Whether own contact is already added
+        */
+       @Override
+       public boolean isOwnContactAdded () {
+               // Trace message
+               this.getLogger().trace("CALLED!");
+
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
+
+               // Default is not added
+               boolean isAdded = false;
+
+               // Now get it back from address book, first get an iterator
+               Iterator<Contact> iterator = this.contacts.iterator();
+
+               // Check entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
+
+                       // Is it valid?
+                       if (contact instanceof Contact) {
+                               // Get flag
+                               isAdded = contact.isOwnContact();
+
+                               // Is this own contact?
+                               if (isAdded) {
+                                       // Then abort loop
+                                       break;
+                               }
+                       }
                }
-           }
-       }
-
-       // Trace message
-       this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded));
-
-       // Return result
-       return isAdded;
-    }
-
-    /**
-     * Adds given contact to address book and flushes all entries to database
-     *
-     * @param contact Contact being added
-     * @todo Add check for book size
-     */
-    @Override
-    public void registerContact (final Contact contact) {
-       // Check if contact is found
-       if (this.isContactAlreadyAdded(contact)) {
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded));
+
+               // Return result
+               return isAdded;
+       }
+
+       /**
+        * Adds given contact to address book and flushes all entries to database
+        *
+        * @param contact Contact being added
+        * @todo Add check for book size
+        */
+       @Override
+       public void registerContact (final Contact contact) {
+               // Check if contact is found
+               if (this.isContactAlreadyAdded(contact)) {
            // Contact already added
-           // @todo Do something here
-       } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
+                       // @todo Do something here
+               } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
            // Own contact already added
-           // @todo Do something
-       }
-       
-       // Debug message
-       /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size()));
-       
-       // Add contact to internal list
-       this.addContact(contact);
-       
-       // Flush whole list
-       this.flush();
-    }
-
-    /**
-     * Getter for size
-     *
-     * @return size of contact "book"
-     */
-    @Override
-    public final int size () {
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-       return this.contacts.size();
-    }
-
-    /**
-     * Fills the column names array with strings from bundle
-     */
-    private void fillColumnNamesFromBundle () {
-       assert(this.columnNames instanceof List) : "this.columnNames is not initialized";
+                       // @todo Do something
+               }
 
        // Debug message
-       this.getLogger().trace("CALLED!");
+       /*
+                * NOISY-DEBUG:
+                */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size()));
+
+               // Add contact to internal list
+               this.addContact(contact);
+
+               // Flush whole list
+               this.flush();
+       }
+
+       /**
+        * Getter for size
+        *
+        * @return size of contact "book"
+        */
+       @Override
+       public final int size () {
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
+               return this.contacts.size();
+       }
+
+       /**
+        * Fills the column names array with strings from bundle
+        */
+       private void fillColumnNamesFromBundle () {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized";
+
+               // Debug message
+               this.getLogger().trace("CALLED!");
 
-       // First get an iterator from key set to iterate over
-       Iterator<String> iterator = this.getBundle().keySet().iterator();
+               // First get an iterator from key set to iterate over
+               Iterator<String> iterator = this.getBundle().keySet().iterator();
 
-       // Then iterate over all
-       while (iterator.hasNext()) {
-           // Get next element
-           String key = iterator.next();
+               // Then iterate over all
+               while (iterator.hasNext()) {
+                       // Get next element
+                       String key = iterator.next();
 
-           // Does the key start with ContactManager.columnName ?
-           if (key.startsWith("ContactManager.columnName")) {
-               // This is the wanted entry.
-               this.getLogger().debug(MessageFormat.format("key={0}", key));
+                       // Does the key start with ContactManager.columnName ?
+                       if (key.startsWith("ContactManager.columnName")) {
+                               // This is the wanted entry.
+                               this.getLogger().debug(MessageFormat.format("key={0}", key));
 
-               // So add it
-               this.columnNames.add(this.getBundle().getString(key));
-           }
+                               // So add it
+                               this.columnNames.add(this.getBundle().getString(key));
+                       }
+               }
+
+               // Debug message
+               this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount()));
        }
 
-       // Debug message
-       this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount()));
-    }
-
-    /**
-     * Flushes all entries by calling database backend
-     */
-    private void flush () {
-       // Flusgh all
-       this.getContactDatabase().flushAllContacts();
-    }
-
-    /**
-     * A ContactWrapper instance
-     *
-     * @return the database
-     */
-    private ContactWrapper getContactDatabase () {
-       return this.contactDatabase;
-    }
-
-    /**
-     * "Getter" for own contact instance or null if not found
-     *
-     * @return Contact instance or null
-     */
-    private Contact getOwnContact () {
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-
-       // Now get it back from address book, first get an iterator
-       Iterator<Contact> iterator = this.contacts.iterator();
-
-       // Init instance
-       Contact contact = null;
-
-       // Search all contact
-       while (iterator.hasNext()) {
-           // Get next instance
-           Contact next = iterator.next();
-
-           // Is this own contact?
-           if (next.isOwnContact()) {
-               // Found it
-               contact = next;
-               break;
-               
-           }
-       }
-
-       // Return instance or null
-       return contact;
-    }
-
-    /**
-     * Checks whether given contact was found in "address book"
-     *
-     * @param checkContact Contact to be checked
-     * @return TRUE if found, FALSE if not found
-     */
-    private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException {
-       assert(this.contacts instanceof List) : "this.contacts is not initialized";
-
-       // Default is not found
-       boolean isFound = false;
+       /**
+        * Flushes all entries by calling database backend
+        */
+       private void flush () {
+               // Flusgh all
+               this.getContactDatabase().flushAllContacts();
+       }
 
-       // Debug message
-       //* NOISY-DEBUG: */ this.getLogger().debug("Checking '" +  this.contacts.length + "' entries...");
+       /**
+        * A ContactWrapper instance
+        *
+        * @return the database
+        */
+       private ContactWrapper getContactDatabase () {
+               return this.contactDatabase;
+       }
 
-       // Now get it back from address book, first get an iterator
-       Iterator<Contact> iterator = this.contacts.iterator();
+       /**
+        * "Getter" for own contact instance or null if not found
+        *
+        * @return Contact instance or null
+        */
+       private Contact getOwnContact () {
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
 
-       // Check entries
-       while (iterator.hasNext()) {
-           // Get next entry
-           Contact contact = iterator.next();
+               // Now get it back from address book, first get an iterator
+               Iterator<Contact> iterator = this.contacts.iterator();
 
-           // Debug message
-           //* NOISY-DEBUG: */ this.getLogger().debug("contact=" + contact + ",checkContent=" + checkContact);
+               // Init instance
+               Contact contact = null;
 
-           // Is it valid?
-           if ((contact instanceof Contact) && ((contact.equals(checkContact)))) {
-               // Found matching entry
-               isFound = true;
-               break;
-           }
+               // Search all contact
+               while (iterator.hasNext()) {
+                       // Get next instance
+                       Contact next = iterator.next();
+
+                       // Is this own contact?
+                       if (next.isOwnContact()) {
+                               // Found it
+                               contact = next;
+                               break;
+
+                       }
+               }
+
+               // Return instance or null
+               return contact;
        }
 
-       // Return result
-       return isFound;
-    }
+       /**
+        * Checks whether given contact was found in "address book"
+        *
+        * @param checkContact Contact to be checked
+        * @return TRUE if found, FALSE if not found
+        */
+       private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException {
+               assert (this.contacts instanceof List) : "this.contacts is not initialized";
+
+               // Default is not found
+               boolean isFound = false;
+
+       // Debug message
+               //* NOISY-DEBUG: */ this.getLogger().debug("Checking '" +  this.contacts.length + "' entries...");
+               // Now get it back from address book, first get an iterator
+               Iterator<Contact> iterator = this.contacts.iterator();
+
+               // Check entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
+
+           // Debug message
+                       //* NOISY-DEBUG: */ this.getLogger().debug("contact=" + contact + ",checkContent=" + checkContact);
+                       // Is it valid?
+                       if ((contact instanceof Contact) && ((contact.equals(checkContact)))) {
+                               // Found matching entry
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return result
+               return isFound;
+       }
 }
index 928df17dc8032373502cdb9cc24f27f7bfc91a9e..869f3e2ac4a554fbe7bee325df434353ccaba8d7 100644 (file)
@@ -27,211 +27,212 @@ import org.mxchange.addressbook.manager.Manageable;
  */
 public interface ManageableContact extends Manageable {
 
-    /**
-     * Shuts down this contact manager
-     */
-    public void doShutdown ();
-
-    /**
-     * Allows the user to enter own cellphone number.
-     * 
-     * @return Cellphone number
-     */
-    public String enterOwnCellNumber ();
-
-    /**
-     * Allows the user to enter own city name.
-     * 
-     * @return City name
-     */
-    public String enterOwnCity ();
-
-    /**
-     * Allows the user to enter comment for own entry.
-     * 
-     * @return Comment
-     */
-    public String enterOwnComment ();
-
-    /**
-     * Allows the user to enter own company name.
-     * 
-     * @return Company name
-     */
-    public String enterOwnCompanyName ();
-
-    /**
-     * Allows the user to enter own country code.
-     * 
-     * @return Country code
-     */
-    public String enterOwnCountryCode ();
-
-    /**
-     * Allows the user to enter own email address.
-     * 
-     * @return Email address
-     */
-    public String enterOwnEmailAddress ();
-
-    /**
-     * Allows the user to enter own family name.
-     * 
-     * @return Family name
-     */
-    public String enterOwnFamilyName ();
-
-    /**
-     * Allows the user to enter own fax number.
-     * 
-     * @return Fax number
-     */
-    public String enterOwnFaxNumber ();
-
-    /**
-     * Allows the user to enter own gender.
-     * 
-     * @return Gender
-     */
-    public char enterOwnGender ();
-
-    /**
-     * Allows the user to enter own phone number.
-     * 
-     * @return Phone number
-     */
-    public String enterOwnPhoneNumber ();
-
-    /**
-     * Allows the user to enter own street and house number.
-     * 
-     * @return Street and house number
-     */
-    public String enterOwnStreet ();
-
-    /**
-     * Allows the user to enter own surname.
-     * 
-     * @return Surname
-     */
-    public String enterOwnSurname ();
-
-    /**
-     * Allows the user to enter own ZIP code.
-     * 
-     * @return ZIP code
-     */
-    public int enterOwnZipCode ();
-
-    /**
-     * Getter for column count
-     * 
-     * @return Column count
-     */
-    public int getColumnCount ();
-
-    /**
-     * List all contacts
-     */
-    public void doListContacts ();
-
-    /**
-     * Getter for column name at given index.
-     * 
-     * @param columnIndex Column index
-     * @return Human-readable column name
-     */
-    public String getColumnName (final int columnIndex);
-
-    /**
-     * Adds given contact to address book
-     *
-     * @param contact Contact being added
-     * @todo Add check for book size
-     */
-    public void registerContact (final Contact contact);
-
-    /**
-     * Adds given Contact instance to list
-     * 
-     * @param contact Contact instance to add
-     */
-    public void addContact (final Contact contact);
-
-    /**
-     * Let the user add a new other address
-     */
-    public void doAddOtherAddress();
-
-    /**
-     * The user can change address data, like street, ZIP code, city and country
-     * of given Contact instance.
-     * 
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     */
-    public void doChangeAddressData (final Contact contact, final Client client);
-
-    /**
-     * The user can change name data, like gender, surname, family name and
-     * company name (if business contact).
-     * 
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     */
-    public void doChangeNameData (final Contact contact, final Client client);
-
-    /**
-     * Let the user change other address
-     */
-    public void doChangeOtherAddress();
-
-    /**
-     * The user can change other data, like phone numbers or comments.
-     * 
-     * @param contact Instance to change data
-     * @param client Client instance to call back
-     */
-    public void doChangeOtherData (final Contact contact, final Client client);
-
-    /**
-     * Let the user change own data
-     */
-    public void doChangeOwnData();
-
-    /**
-     * Let the user delete other address
-     */
-    public void doDeleteOtherAddress();
-
-    /**
-     * Asks user for own data
-     */
-    public void doEnterOwnData();
-
-    /**
-     * Getter for whole list
-     * @return List of all contacts
-     */
-    public List<Contact> getList ();
-
-    /**
-     * Searches address book for a contact
-     */
-    public void doSearchContacts ();
-
-    /**
-     * Checks whether own contact is already added by checking all entries for
-     * isOwnContact flag
-     * 
-     * @return Whether own contact is already added
-     */
-    public boolean isOwnContactAdded ();
-
-    /**
-     * Getter for size
-     *
-     * @return size of contact "book"
-     */
-    public int size();
+       /**
+        * Shuts down this contact manager
+        */
+       public void doShutdown ();
+
+       /**
+        * Allows the user to enter own cellphone number.
+        *
+        * @return Cellphone number
+        */
+       public String enterOwnCellNumber ();
+
+       /**
+        * Allows the user to enter own city name.
+        *
+        * @return City name
+        */
+       public String enterOwnCity ();
+
+       /**
+        * Allows the user to enter comment for own entry.
+        *
+        * @return Comment
+        */
+       public String enterOwnComment ();
+
+       /**
+        * Allows the user to enter own company name.
+        *
+        * @return Company name
+        */
+       public String enterOwnCompanyName ();
+
+       /**
+        * Allows the user to enter own country code.
+        *
+        * @return Country code
+        */
+       public String enterOwnCountryCode ();
+
+       /**
+        * Allows the user to enter own email address.
+        *
+        * @return Email address
+        */
+       public String enterOwnEmailAddress ();
+
+       /**
+        * Allows the user to enter own family name.
+        *
+        * @return Family name
+        */
+       public String enterOwnFamilyName ();
+
+       /**
+        * Allows the user to enter own fax number.
+        *
+        * @return Fax number
+        */
+       public String enterOwnFaxNumber ();
+
+       /**
+        * Allows the user to enter own gender.
+        *
+        * @return Gender
+        */
+       public char enterOwnGender ();
+
+       /**
+        * Allows the user to enter own phone number.
+        *
+        * @return Phone number
+        */
+       public String enterOwnPhoneNumber ();
+
+       /**
+        * Allows the user to enter own street and house number.
+        *
+        * @return Street and house number
+        */
+       public String enterOwnStreet ();
+
+       /**
+        * Allows the user to enter own surname.
+        *
+        * @return Surname
+        */
+       public String enterOwnSurname ();
+
+       /**
+        * Allows the user to enter own ZIP code.
+        *
+        * @return ZIP code
+        */
+       public int enterOwnZipCode ();
+
+       /**
+        * Getter for column count
+        *
+        * @return Column count
+        */
+       public int getColumnCount ();
+
+       /**
+        * List all contacts
+        */
+       public void doListContacts ();
+
+       /**
+        * Getter for column name at given index.
+        *
+        * @param columnIndex Column index
+        * @return Human-readable column name
+        */
+       public String getColumnName (final int columnIndex);
+
+       /**
+        * Adds given contact to address book
+        *
+        * @param contact Contact being added
+        * @todo Add check for book size
+        */
+       public void registerContact (final Contact contact);
+
+       /**
+        * Adds given Contact instance to list
+        *
+        * @param contact Contact instance to add
+        */
+       public void addContact (final Contact contact);
+
+       /**
+        * Let the user add a new other address
+        */
+       public void doAddOtherAddress ();
+
+       /**
+        * The user can change address data, like street, ZIP code, city and country
+        * of given Contact instance.
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        */
+       public void doChangeAddressData (final Contact contact, final Client client);
+
+       /**
+        * The user can change name data, like gender, surname, family name and
+        * company name (if business contact).
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        */
+       public void doChangeNameData (final Contact contact, final Client client);
+
+       /**
+        * Let the user change other address
+        */
+       public void doChangeOtherAddress ();
+
+       /**
+        * The user can change other data, like phone numbers or comments.
+        *
+        * @param contact Instance to change data
+        * @param client Client instance to call back
+        */
+       public void doChangeOtherData (final Contact contact, final Client client);
+
+       /**
+        * Let the user change own data
+        */
+       public void doChangeOwnData ();
+
+       /**
+        * Let the user delete other address
+        */
+       public void doDeleteOtherAddress ();
+
+       /**
+        * Asks user for own data
+        */
+       public void doEnterOwnData ();
+
+       /**
+        * Getter for whole list
+        *
+        * @return List of all contacts
+        */
+       public List<Contact> getList ();
+
+       /**
+        * Searches address book for a contact
+        */
+       public void doSearchContacts ();
+
+       /**
+        * Checks whether own contact is already added by checking all entries for
+        * isOwnContact flag
+        *
+        * @return Whether own contact is already added
+        */
+       public boolean isOwnContactAdded ();
+
+       /**
+        * Getter for size
+        *
+        * @return size of contact "book"
+        */
+       public int size ();
 }
index 02d00b65808179e9c8231d88b7ffbb7671da1bfe..418a7cb1b784bf39c26c2618d481945ab803242a 100644 (file)
@@ -1,85 +1,86 @@
-/*\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
+/*
+ * 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.menu;
+
+import java.util.List;
+import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+
+/**
+ * Utility class for menu structure
+ *
+ * @author Roland Haeder
+ */
+public class AddressbookMenu extends BaseFrameworkSystem {
+
+       /**
+        * Copies entries for given type into the menu list
+        *
+        * @param menuList Menu list for later showing
+        * @param menuType Type of menu
+        * @param client Client instance to call back
+        */
+       public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
+               // Get logger
+               Logger log = new AddressbookMenu().getLogger();
+
+               // Get list size
+               int size = menuList.size();
+
+               // Debug message
+               log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ...");
+
+               // Depends on type
+               switch (menuType) {
+                       case "main": // Main menu
+                               // Enter own data
+                               menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen"));
+
+                               // Change own data
+                               menuList.add(client.getMenuItem('2', "Eigene Adresse ändern"));
+
+                               // Add new addess
+                               menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen"));
+
+                               // List entries
+                               menuList.add(client.getMenuItem('4', "Adressbuch anzeigen"));
+
+                               // Address search
+                               menuList.add(client.getMenuItem('5', "Adresse suchen"));
+
+                               // Change other address
+                               menuList.add(client.getMenuItem('6', "Adresse ändern"));
+
+                               // Delete other address
+                               menuList.add(client.getMenuItem('7', "Adresse löschen"));
+
+                               // Always last line: Exit program
+                               menuList.add(client.getMenuItem('0', "Programm verlassen"));
+                               break;
+
+                       default: // Not supported
+                               log.error("Menu type '" + menuType + "' ont supported");
+                               System.exit(1);
+               }
+
+               // Size must have changed to more entries than before
+               assert (menuList.size() > size);
+       }
+
+}
index d81c0714f877bdb74e00243e5331117002fb9527..73f3422db93b0ea38bc6354659e6fb514e6e3c4b 100644 (file)
-/*\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
+/*
+ * 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.menu;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class BaseMenu extends BaseFrameworkSystem {
+
+       /**
+        * Menu list
+        */
+       private List<SelectableMenuItem> menuList;
+
+       /**
+        * No instance from this object
+        */
+       protected BaseMenu () {
+               super();
+       }
+
+       /**
+        * Size of menu items
+        *
+        * @return Count of menu items
+        */
+       public int getMenuItemsCount () {
+               return this.menuList.size();
+       }
+
+       /**
+        * "Getter" for an iterator of this menu's items
+        *
+        * @return An iterator of all menu items
+        */
+       public Iterator<SelectableMenuItem> getMenuItemsIterator () {
+               return this.menuList.iterator();
+       }
+
+       /**
+        * Shows this menu
+        *
+        * @param client Client instance to call back
+        */
+       public void show (final Client client) {
+               // Get values
+               Iterator<SelectableMenuItem> iterator = this.menuList.iterator();
+
+               // Debug message
+               this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");
+
+               // Output all menus
+               while (iterator.hasNext()) {
+                       // Get item
+                       SelectableMenuItem item = iterator.next();
+
+                       // Show this item
+                       item.show(client);
+               }
+       }
+
+       /**
+        * Getter for menu list
+        *
+        * @return      menuList List of menu entries
+        */
+       protected final List<SelectableMenuItem> getMenuList () {
+               return this.menuList;
+       }
+
+       /**
+        * Initializes menu
+        *
+        * @param menuType      Menu type to initialize
+        * @param client CLient to call back
+        */
+       protected void initMenu (final String menuType, final Client client) {
+               // Init menu list
+               this.menuList = new ArrayList<>(5);
+       }
+}
index 4a13bdba1b4b2a2643452a75663308bbabd0e35e..872719e97ba2d2330a870fb62c2526f77e635d3d 100644 (file)
@@ -1,47 +1,50 @@
-/*\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
+/*
+ * 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.menu;
+
+import java.util.Iterator;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+
+/**
+ *
+ * @author Roland Haeder
+ * @todo find better name
+ */
+public interface Menu {
+
+       /**
+        * "Getter" for an iterator on all menu items of the current menu
+        *
+        * @return Iterator on all menu items
+        */
+       public Iterator<SelectableMenuItem> getMenuItemsIterator ();
+
+       /**
+        * Shows this menu
+        *
+        * @param client Client instance
+        */
+       public void show (final Client client);
+
+       /**
+        * Size of all menu items
+        *
+        * @return
+        */
+       public int getMenuItemsCount ();
+}
index 75bfb7ed58a5e139327fcf2dd967d7114cf87bc2..44d5395c398b513d852ff994ff74af767404b43f 100644 (file)
@@ -1,78 +1,78 @@
-/*\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
+/*
+ * 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.menu;
+
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.logging.log4j.Logger;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class MenuTools extends BaseFrameworkSystem {
+
+       /**
+        * Gets an array with all available access keys back from given menu map.
+        * This can later be handle to the client's enterChar() method.
+        *
+        * @param menus A Map with all menus and their entries
+        * @param menuType Menu type
+        * @return An array with available access chars
+        */
+       public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {
+               // Get logger
+               Logger logger = new MenuTools().getLogger();
+
+               // First search for the proper menu class
+               Menu menu = menus.get(menuType);
+
+               // Is it there?
+               if (!(menu instanceof Menu)) {
+           // Not found
+                       // @todo Rewrite to exception
+                       logger.error("Menu '" + menuType + "' not found.");
+                       System.exit(1);
+               }
+
+               // Get iterator
+               Iterator<SelectableMenuItem> iterator = menu.getMenuItemsIterator();
+
+               // Init return array and counter 'i'
+               char[] accessKeys = new char[menu.getMenuItemsCount()];
+               int i = 0;
+
+               // Now "walk" through all menu entries
+               while (iterator.hasNext()) {
+                       // Get item
+                       SelectableMenuItem item = iterator.next();
+           //* NOISY-DEBUG: */ logger.debug("item=" + item);
+
+                       // Get access key from item and add it to the array
+                       accessKeys[i] = item.getAccessKey();
+           //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]);
+
+                       // Increment counter
+                       i++;
+               }
+
+               // Return finished array
+               return accessKeys;
+       }
+}
index cefa2c54d845a8ad05d55ee6eb6f86cf8a171785..7064473b735399be33004353f1cd8bd3b79e5837 100644 (file)
@@ -1,40 +1,42 @@
-/*\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
+/*
+ * 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.menu.console;
+
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.menu.AddressbookMenu;
+import org.mxchange.addressbook.menu.BaseMenu;
+import org.mxchange.addressbook.menu.Menu;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class ConsoleMenu extends BaseMenu implements Menu {
+
+       /**
+        * Constructor for this menu
+        *
+        * @param menuType      Menu type to initialize
+        * @param client CLient to call back
+        */
+       public ConsoleMenu (final String menuType, final Client client) {
+               this.initMenu(menuType, client);
+
+               // Add all items
+               AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client);
+       }
+}
index efbce50b3aeceb4c17ad32e74c6e9aa8e43cef39..22ed0088144bac561c8c1ac77193f0916829c3e3 100644 (file)
@@ -1,44 +1,47 @@
-/*\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
+/*
+ * 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.menu.item;
+
+import org.mxchange.addressbook.client.Client;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public interface SelectableMenuItem {
+
+       /**
+        * Shows this menu item
+        *
+        * @param client Client instance
+        */
+       public void show (final Client client);
+
+       /**
+        * Access key
+        *
+        * @return the accessKey
+        */
+       public char getAccessKey ();
+
+       /**
+        * Text to user
+        *
+        * @return the text
+        */
+       public String getText ();
+}
index 82dd838c42348a85b8c05f9492b978ce17dc6afb..7fe38bbe242183e0b079aa2f971c9360a43cb67b 100644 (file)
@@ -25,65 +25,70 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem;
  * @author Roland Haeder
  */
 public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem {
-    /**
-     * Access key
-     */
-    private char accessKey;
 
-    /**
-     * Text to user
-     */
-    private String text;
+       /**
+        * Access key
+        */
+       private char accessKey;
 
-    /**
-     * Constructor for building a console menu with access key and text
-     * 
-     * @param accessKey Access key for this menu entry
-     * @param text Text to show to user
-     */
-    public ConsoleMenuItem (final char accessKey, final String text) {
-       this.accessKey = accessKey;
-       this.text = text;
-    }
+       /**
+        * Text to user
+        */
+       private String text;
 
-    /**
-     * Access key
-     * @return the accessKey
-     */
-    @Override
-    public final char getAccessKey () {
-       return this.accessKey;
-    }
+       /**
+        * Constructor for building a console menu with access key and text
+        *
+        * @param accessKey Access key for this menu entry
+        * @param text Text to show to user
+        */
+       public ConsoleMenuItem (final char accessKey, final String text) {
+               this.accessKey = accessKey;
+               this.text = text;
+       }
 
-    /**
-     * Text to user
-     * @return the text
-     */
-    @Override
-    public String getText () {
-       return this.text;
-    }
+       /**
+        * Access key
+        *
+        * @return the accessKey
+        */
+       @Override
+       public final char getAccessKey () {
+               return this.accessKey;
+       }
 
-    @Override
-    public void show (final Client client) {
-       // Call-back client over menu
-       client.showEntry(this);
-    }
+       /**
+        * Text to user
+        *
+        * @return the text
+        */
+       @Override
+       public String getText () {
+               return this.text;
+       }
 
-    /**
-     * Text to user
-     * @param text the text to set
-     */
-    private void setText (String text) {
-       this.text = text;
-    }
+       @Override
+       public void show (final Client client) {
+               // Call-back client over menu
+               client.showEntry(this);
+       }
+
+       /**
+        * Text to user
+        *
+        * @param text the text to set
+        */
+       private void setText (String text) {
+               this.text = text;
+       }
+
+       /**
+        * Access key
+        *
+        * @param accessKey the accessKey to set
+        */
+       private void setAccessKey (char accessKey) {
+               this.accessKey = accessKey;
+       }
 
-    /**
-     * Access key
-     * @param accessKey the accessKey to set
-     */
-    private void setAccessKey (char accessKey) {
-       this.accessKey = accessKey;
-    }
-    
 }
index 54aa507680fd589db76fd277698339a3056984ea..cc74cad8267c4203d6e8c28363f8604022b83516 100644 (file)
@@ -1,65 +1,68 @@
-/*\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;\r
-\r
-import java.text.MessageFormat;\r
-import javax.swing.event.EventListenerList;\r
-import javax.swing.event.TableModelListener;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class BaseModel extends BaseFrameworkSystem {\r
-    /** List of listeners */\r
-    private final EventListenerList listenerList;\r
-\r
-    /**\r
-     * Protected constructor\r
-     */\r
-    protected BaseModel () {\r
-       // Init listener list\r
-       this.listenerList = new EventListenerList();\r
-    }\r
-\r
-    /**\r
-     * Adds a TableModel listener instance to the event list.\r
-     * \r
-     * @param listener Lister instance\r
-     */\r
-    public void addTableModelListener (final TableModelListener listener) {\r
-       // Debug message\r
-       this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass()));\r
-\r
-       // Add listener\r
-       this.listenerList.add(TableModelListener.class, listener);\r
-    }\r
-\r
-    /**\r
-     * Removes a TableModel listener instance from the event list.\r
-     * \r
-     * @param listener Listener instance\r
-     */\r
-    public void removeTableModelListener (final TableModelListener listener) {\r
-       // Debug message\r
-       this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass()));\r
-\r
-       // Remove listener\r
-       this.listenerList.remove(TableModelListener.class, listener);\r
-    }\r
-}\r
+/*
+ * 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.model;
+
+import java.text.MessageFormat;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.TableModelListener;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public class BaseModel extends BaseFrameworkSystem {
+
+       /**
+        * List of listeners
+        */
+       private final EventListenerList listenerList;
+
+       /**
+        * Protected constructor
+        */
+       protected BaseModel () {
+               // Init listener list
+               this.listenerList = new EventListenerList();
+       }
+
+       /**
+        * Adds a TableModel listener instance to the event list.
+        *
+        * @param listener Lister instance
+        */
+       public void addTableModelListener (final TableModelListener listener) {
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass()));
+
+               // Add listener
+               this.listenerList.add(TableModelListener.class, listener);
+       }
+
+       /**
+        * Removes a TableModel listener instance from the event list.
+        *
+        * @param listener Listener instance
+        */
+       public void removeTableModelListener (final TableModelListener listener) {
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass()));
+
+               // Remove listener
+               this.listenerList.remove(TableModelListener.class, listener);
+       }
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java b/Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java
deleted file mode 100644 (file)
index 0041637..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.model.address;
-
-import javax.swing.table.TableModel;
-import org.mxchange.addressbook.client.Client;
-import org.mxchange.addressbook.model.BaseModel;
-
-/**
- *
- * @author Roland Haeder
- */
-public class AddressTableModel extends BaseModel implements TableModel {
-
-    /**
-     * Constructor with Client instance which holds the contact manager
-     *
-     * @param client Client instance
-     */
-    public AddressTableModel (final Client client) {
-       // Parent super constructor
-       super();
-
-       // Set client
-       this.setClient(client);
-    }
-
-    @Override
-    public Class<?> getColumnClass (final int columnIndex) {
-       throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public int getColumnCount () {
-       // Deligate this call to contact manager
-       return this.getClient().getContactManager().getColumnCount();
-    }
-
-    @Override
-    public String getColumnName (final int columnIndex) {
-       // Deligate this call to contact manager
-       return this.getClient().getContactManager().getColumnName(columnIndex);
-    }
-
-    @Override
-    public int getRowCount () {
-       // Deligate this call to contact manager
-       return this.getClient().getContactManager().size();
-    }
-
-    @Override
-    public Object getValueAt (final int rowIndex, final int columnIndex) {
-       throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public boolean isCellEditable (final int rowIndex, final int columnIndex) {
-       throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void setValueAt (final Object value, final int rowIndex, final int columnIndex) {
-       throw new UnsupportedOperationException("Not supported yet. value=" + value + ",rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
-    }
-}
diff --git a/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java b/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java
new file mode 100644 (file)
index 0000000..ef125a0
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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.model.contact;
+
+import javax.swing.table.TableModel;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.model.BaseModel;
+
+/**
+ * A table model for contacts
+ *
+ * @author Roland Haeder
+ */
+public class ContactTableModel extends BaseModel implements TableModel {
+
+       /**
+        * Constructor with Client instance which holds the contact manager
+        *
+        * @param client Client instance
+        */
+       public ContactTableModel (final Client client) {
+               // Parent super constructor
+               super();
+
+               // Set client
+               this.setClient(client);
+       }
+
+       @Override
+       public Class<?> getColumnClass (final int columnIndex) {
+               throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public int getColumnCount () {
+               // Deligate this call to contact manager
+               return this.getClient().getContactManager().getColumnCount();
+       }
+
+       @Override
+       public String getColumnName (final int columnIndex) {
+               // Deligate this call to contact manager
+               return this.getClient().getContactManager().getColumnName(columnIndex);
+       }
+
+       @Override
+       public int getRowCount () {
+               // Deligate this call to contact manager
+               return this.getClient().getContactManager().size();
+       }
+
+       @Override
+       public Object getValueAt (final int rowIndex, final int columnIndex) {
+               throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public boolean isCellEditable (final int rowIndex, final int columnIndex) {
+               throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void setValueAt (final Object value, final int rowIndex, final int columnIndex) {
+               throw new UnsupportedOperationException("Not supported yet. value=" + value + ",rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates.
+       }
+}