]> git.mxchange.org Git - jbonuscard-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Introduced a lot Swing stuff + moved some attributes
[jbonuscard-lib.git] / Addressbook / src / org / mxchange / addressbook / application / AddressbookApplication.java
index 2d3237a6bb74e056ac3cd3f232e89c5b18b2aac9..fcda1bca021f4c138bdefe0856442683fe4b0818 100644 (file)
  */\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
@@ -117,7 +119,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
     /**\r
      * Application title\r
      */\r
-    public static final String APP_TITLE = "Addressbuch";\r
+    public static final String APP_TITLE = "Adressbuch";\r
 \r
     /**\r
      * Application version\r
@@ -125,14 +127,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
     public static final String APP_VERSION = "0.0";\r
 \r
     /**\r
-     * Main method (entry point)\r
-     *\r
-     * @param args the command line arguments\r
+     * Console client is enabled by default\r
      */\r
-    public static void main (String[] args) {\r
-       // Start application\r
-       new AddressbookApplication().start();\r
-    }\r
+    private boolean consoleClient = true;\r
+\r
+    /**\r
+     * GUI client is disabled by default\r
+     */\r
+    private boolean guiClient = false;\r
 \r
     /**\r
      * Bootstraps application\r
@@ -140,11 +142,30 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
     @Override\r
     public void doBootstrap () {\r
        this.getLogger().debug("Initializing application ...");\r
-       \r
-       // Init client instance\r
-       Client client = new ConsoleClient(this);\r
 \r
-               // Init client instance\r
+       // 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
+       // Set client instance\r
        this.setClient(client);\r
        \r
        // The application is running at this point\r
@@ -182,6 +203,67 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
        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
@@ -192,14 +274,28 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
 \r
     /**\r
      * Launches the application\r
+     * \r
+     * @param args Arguments handled to program\r
      */\r
-    private void start () {\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
        this.getLogger().info("End of program (last line)");\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