]> git.mxchange.org Git - addressbook-swing.git/blobdiff - Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Nicer formatted comment
[addressbook-swing.git] / Addressbook / src / org / mxchange / addressbook / application / AddressbookApplication.java
index 788c940ed3c41eb082ab699fcda3f03383381a24..5704a144f4aba380914df35646e8ccdf33aac7e3 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.application;\r
-\r
-import java.text.MessageFormat;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.UnhandledUserChoiceException;\r
-import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.client.console.ConsoleClient;\r
-import org.mxchange.addressbook.client.gui.SwingClient;\r
-import org.mxchange.addressbook.manager.application.ApplicationManager;\r
-\r
-/**\r
- * ============================================\r
- * AddressbookApplication management:\r
- * ============================================\r
- * \r
- * Inernet("public" service) and Intranet\r
- * \r
- * Version 1.0+:\r
- * - Single-user local application\r
- * - Fields:\r
- *   + Gender\r
- *   + Surname\r
- *   + Family name\r
- *   + Company name\r
- *   + Street + number\r
- *   + ZIP code\r
- *   + City\r
- *   + Landline number\r
- *   + Fax number\r
- *   + Cell phone number\r
- *   + Email address\r
- *   + Birth day\r
- *   + Comment (?)\r
- * - Edit own data\r
- * - Add new contact\r
- * - Edit contacts\r
- * - Delete contacts\r
- * - Categorization of contacts\r
- * \r
- * Version 1.1+:\r
- * - Permanent storage in database\r
- * \r
- * Version 2.0+:\r
- * - Multi-user web application\r
- * - Local user registration / login / resend confirmation link / password\r
- *   recovery\r
- * - User groups (aka. teams)\r
- * - Administration area (user role)\r
- *   + Create/edit/delete groups\r
- *   + Edit/delete/lock/unlock user\r
- *   + Assign user roles/rights\r
- * - Allow other users / groups to view addressbook\r
- *   + Full addressbook\r
- *   + Only some categories\r
- * - VCard export\r
- *   + Allow users/guests (not recommended)\r
- * - XML export of addressbook and compressable (ZIP)\r
- * - Form to contact other user/group without need of mail program\r
- *   + User can disabled this\r
- * - Directory for ussers/groups (who allowed to be listed)\r
- *   + Simple click to add user to own addressbook\r
- *   + Search form?\r
- * \r
- * Version 2.1+:\r
- * - Multi-language support\r
- * \r
- * Version 2.2+:("socialized")\r
- * - "Social login" (OpenID consumer)\r
- *   + Connect user account to social account\r
- *   + Sync own data?\r
- * - "Social profile"\r
- *   + OpenID provider\r
- *   + RSS/activity feed \r
- * \r
- * ============================================\r
- * Time esitmation:\r
- * ============================================\r
- * 1.0 (console):\r
- *   + 2 days\r
- * \r
- * 1.1 (database):\r
- *   + 2 day\r
- *   + Initial tables: contacts, categories, contact_category\r
- * \r
- * 2.0 (web):\r
- *   + 3 days\r
- *   + Additional tables: admins (?), admin_rights, groups,\r
- *    users, user_contacts, user_user_rights, user_category_rights, \r
- * \r
- * 2.1 (language)\r
- *   + 1 day\r
- *   + Additional tables: languages (disable, enable language "pack" ?)\r
- * \r
- * 2.2 (social):\r
- *   + 3 days\r
- *   + Additional tables: ???\r
- * \r
- * @author Roland Haeder\r
- * @version 0.0\r
- * @since 0.0\r
- */\r
-public class AddressbookApplication extends BaseFrameworkSystem implements Application {\r
-    /**\r
-     * Application title\r
-     */\r
-    public static final String APP_TITLE = "Adressbuch";\r
-\r
-    /**\r
-     * Application version\r
-     */\r
-    public static final String APP_VERSION = "0.0";\r
-\r
-    /**\r
-     * Console client is enabled by default\r
-     */\r
-    private boolean consoleClient = true;\r
-\r
-    /**\r
-     * GUI client is disabled by default\r
-     */\r
-    private boolean guiClient = false;\r
-\r
-    /**\r
-     * Getter for printable application name\r
-     * \r
-     * @return A printable name\r
-     */\r
-    public static String printableTitle () {\r
-       return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);\r
-    }\r
-\r
-    /**\r
-     * Bootstraps application\r
-     */\r
-    @Override\r
-    public void doBootstrap () {\r
-       this.getLogger().debug("Initializing application ...");\r
-\r
-       // Init client variable\r
-       Client client = null;\r
-\r
-       // Is console or Swing choosen?\r
-       if (this.isConsole()) {\r
-           // Debug message\r
-           this.getLogger().debug("Initializing console client ...");\r
-\r
-           // Init console client instance\r
-           client = new ConsoleClient(this);\r
-       } else if (this.isGui()) {\r
-           // Debug message\r
-           this.getLogger().debug("Initializing GUI (Swing) client ...");\r
-\r
-           // Init console instance\r
-           client = new SwingClient(this);\r
-       } else {\r
-           // Not client choosen\r
-           this.getLogger().error("No client choosen. Cannot launch.");\r
-           System.exit(1);\r
-       }\r
-\r
-       // Init client\r
-       client.initClient();\r
-\r
-       // Set client instance\r
-       this.setClient(client);\r
-       \r
-       // The application is running at this point\r
-       this.getClient().enableIsRunning();\r
-    }\r
-\r
-    /**\r
-     * Main loop of the application\r
-     */\r
-    @Override\r
-    public void doMainLoop () {\r
-       // @TODO The application should be running now\r
-       \r
-       // Output introduction\r
-       this.showIntro();\r
-\r
-       // Set current menu to main\r
-       this.getClient().setCurrentMenu("main");\r
-\r
-       // --- Main loop starts here ---\r
-       while (this.getClient().isRunning()) {\r
-           // The application is still active, show menu selection\r
-           this.getClient().showCurrentMenu();\r
-\r
-           try {\r
-               // Ask for user input and run proper method\r
-               this.getClient().doUserMenuChoice();\r
-           } catch (final UnhandledUserChoiceException ex) {\r
-               this.getLogger().catching(ex);\r
-           }\r
-       }\r
-       // --- Main loop ends here ---\r
-\r
-       // Debug message\r
-       this.getLogger().debug("Main loop exit - shutting down ...");\r
-    }\r
-\r
-    /**\r
-     * Enables console client by setting propper flag\r
-     */\r
-    private void enableConsoleClient () {\r
-       this.getLogger().debug("Enabling console client (may become optional client) ...");\r
-       this.consoleClient = true;\r
-       this.guiClient = false;\r
-    }\r
-\r
-    /**\r
-     * Enables GUI client by setting propper flag\r
-     */\r
-    private void enableGuiClient () {\r
-       this.getLogger().debug("Enabling GUI client (may become new default client) ...");\r
-       this.consoleClient = false;\r
-       this.guiClient = true;\r
-    }\r
-\r
-    /**\r
-     * Checks whether the client shoule be console client should be launched by\r
-     * checking if -console is set.\r
-     * \r
-     * @return Whether console client should be taken\r
-     */\r
-    private boolean isConsole () {\r
-       return this.consoleClient;\r
-    }\r
-\r
-    /**\r
-     * Checks whether the client shoule be GUI client should be launched by\r
-     * checking if -gui is set.\r
-     * \r
-     * @return Whether GUI client should be taken\r
-     */\r
-    private boolean isGui () {\r
-       return this.guiClient;\r
-    }\r
-\r
-    /**\r
-     * Parses all given arguments\r
-     *\r
-     * @param args Arguments from program launch\r
-     */\r
-    private void parseArguments (final String[] args) {\r
-       // Debug message\r
-       this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));\r
-       \r
-       for (final String arg : args) {\r
-           // Switch on it\r
-           switch (arg) {\r
-               case "-console":\r
-                   enableConsoleClient();\r
-                   break;\r
-                   \r
-               case "-gui":\r
-                   enableGuiClient();\r
-                   break;\r
-}\r
-       }\r
-    }\r
-\r
-    /**\r
-     * Show introduction which depends on client\r
-     */\r
-    private void showIntro () {\r
-       // Let the client show it\r
-       this.getClient().showWelcome();\r
-    }\r
-\r
-    /**\r
-     * Launches the application\r
-     * \r
-     * @param args Arguments handled to program\r
-     */\r
-    private void start (final String args[]) {\r
-       this.getLogger().info("Program is started.");\r
-\r
-       // Parse arguments\r
-       this.parseArguments(args);\r
-\r
-       // Launch application\r
-       ApplicationManager.getManager(this).start();\r
-\r
-       // Good bye, but this should not be reached ...\r
-       this.getLogger().warn("Unusual exit reached.");\r
-       this.doShutdown();\r
-    }\r
-\r
-    /**\r
-     * Main method (entry point)\r
-     *\r
-     * @param args the command line arguments\r
-     */\r
-    public static void main (String[] args) {\r
-       // Start application\r
-       new AddressbookApplication().start(args);\r
-    }\r
-\r
-    /**\r
-     * Shuts down the application.\r
-     */\r
-    @Override\r
-    public void doShutdown () {\r
-       // Shutdown client\r
-       this.getClient().doShutdown();\r
-\r
-       this.getLogger().info("End of program (last line)");\r
-       System.exit(0);\r
-    }\r
-}\r
+/*
+ * 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 java.text.MessageFormat;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.client.console.ConsoleClient;
+import org.mxchange.addressbook.client.gui.SwingClient;
+import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
+import org.mxchange.addressbook.manager.application.ApplicationManager;
+
+/**
+ * ============================================
+ * AddressbookApplication management:
+ * ============================================
+ * 
+ * Inernet("public" service) and Intranet
+ * 
+ * Version 1.0+:
+ * - Single-user local application
+ * - Fields:
+ *   + Gender
+ *   + Surname
+ *   + Family name
+ *   + Company name
+ *   + Street + number
+ *   + ZIP code
+ *   + City
+ *   + Landline number
+ *   + Fax number
+ *   + Cell phone number
+ *   + Email address
+ *   + Birth day
+ *   + Comment (?)
+ * - Edit own data
+ * - Add new contact
+ * - Edit contacts
+ * - Delete contacts
+ * - Categorization of contacts
+ * 
+ * Version 1.1+:
+ * - Permanent storage in database
+ * 
+ * Version 2.0+:
+ * - Multi-user web application
+ * - Local user registration / login / resend confirmation link / password
+ *   recovery
+ * - User groups (aka. teams)
+ * - Administration area (user role)
+ *   + Create/edit/delete groups
+ *   + Edit/delete/lock/unlock user
+ *   + Assign user roles/rights
+ * - Allow other users / groups to view addressbook
+ *   + Full addressbook
+ *   + Only some categories
+ * - VCard export
+ *   + Allow users/guests (not recommended)
+ * - XML export of addressbook and compressable (ZIP)
+ * - Form to contact other user/group without need of mail program
+ *   + User can disabled this
+ * - Directory for ussers/groups (who allowed to be listed)
+ *   + Simple click to add user to own addressbook
+ *   + Search form?
+ * 
+ * Version 2.1+:
+ * - Multi-language support
+ * 
+ * Version 2.2+:("socialized")
+ * - "Social login" (OpenID consumer)
+ *   + Connect user account to social account
+ *   + Sync own data?
+ * - "Social profile"
+ *   + OpenID provider
+ *   + RSS/activity feed 
+ * 
+ * ============================================
+ * Time esitmation:
+ * ============================================
+ * 1.0 (console):
+ *   + 2 days
+ * 
+ * 1.1 (database):
+ *   + 2 day
+ *   + Initial tables: contacts, categories, contact_category
+ * 
+ * 2.0 (web):
+ *   + 3 days
+ *   + Additional tables: admins (?), admin_rights, groups,
+ *    users, user_contacts, user_user_rights, user_category_rights, 
+ * 
+ * 2.1 (language)
+ *   + 1 day
+ *   + Additional tables: languages (disable, enable language "pack" ?)
+ * 
+ * 2.2 (social):
+ *   + 3 days
+ *   + Additional tables: ???
+*
+ * @author Roland Haeder
+ * @version 0.0
+ */
+public class AddressbookApplication extends BaseFrameworkSystem implements Application {
+
+       /**
+        * Application title
+        */
+       public static final String APP_TITLE = "Adressbuch"; //NOI18N
+
+       /**
+        * Application version
+        */
+       public static final String APP_VERSION = "0.0"; //NOI18N
+
+       /**
+        * Self instance
+        */
+       private static Application selfInstance;
+
+       /**
+        * Console client is enabled by default
+        */
+       private boolean consoleClient = true;
+
+       /**
+        * GUI client is disabled by default
+        */
+       private boolean guiClient = false;
+
+       /**
+        * Protected constructor
+        */
+       protected AddressbookApplication () {
+               // Set own instance
+               selfInstance = this;
+       }
+
+       /**
+        * Getter for printable application name
+        *
+        * @return A printable name
+        */
+       public static String printableTitle () {
+               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N
+       }
+
+       /**
+        * Bootstraps application
+        */
+       @Override
+       public void doBootstrap () {
+               this.getLogger().debug("Initializing application ..."); //NOI18N
+
+               // Init client variable
+               Client client = null;
+
+               // Is console or Swing choosen?
+               if (this.isConsole()) {
+                       // Debug message
+                       this.getLogger().debug("Initializing console client ..."); //NOI18N
+
+                       // Init console client instance
+                       client = new ConsoleClient(this);
+               } else if (this.isGui()) {
+                       // Debug message
+                       this.getLogger().debug("Initializing GUI (Swing) client ..."); //NOI18N
+
+                       // Init console instance
+                       client = new SwingClient(this);
+               } else {
+                       // Not client choosen
+                       this.getLogger().error("No client choosen. Cannot launch."); //NOI18N
+                       System.exit(1);
+               }
+
+               // Init client
+               client.init();
+
+               // Set client instance
+               this.setClient(client);
+
+               // The application is running at this point
+               this.getClient().enableIsRunning();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Main loop of the application
+        */
+       @Override
+       public void doMainLoop () {
+               // Debug message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // @TODO The application should be running now
+               // Output introduction
+               this.showIntro();
+
+               // Set current menu to main
+               this.getClient().setCurrentMenu("main"); //NOI18N
+
+               // --- 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 ..."); //NOI18N
+       }
+
+       /**
+        * Enables console client by setting propper flag
+        */
+       private void enableConsoleClient () {
+               this.getLogger().debug("Enabling console client (may become optional client) ..."); //NOI18N
+               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) ..."); //NOI18N
+               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) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N
+
+               for (final String arg : args) {
+                       // Switch on it
+                       switch (arg) {
+                               case "-console": //NOI18N
+                                       enableConsoleClient();
+                                       break;
+
+                               case "-gui": //NOI18N
+                                       enableGuiClient();
+                                       break;
+                       }
+               }
+       }
+
+       /**
+        * Show introduction which depends on client
+        */
+       private void showIntro () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Let the client show it
+               this.getClient().showWelcome();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Launches the application
+        *
+        * @param args Arguments handled to program
+        */
+       private void start (final String args[]) {
+               this.getLogger().info("Program is started."); //NOI18N
+
+               // 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."); //NOI18N
+               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 () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Shutdown client
+               this.getClient().doShutdown();
+
+               this.getLogger().info("End of program (last line)"); //NOI18N
+               System.exit(0);
+       }
+
+       /**
+        * Getter for this application
+        *
+        * @return Instance from this application
+        */
+       public static final Application getInstance () {
+               // Return it
+               return selfInstance;
+       }
+}