import java.text.MessageFormat;
import org.mxchange.addressbook.BaseFrameworkSystem;
-import org.mxchange.addressbook.UnhandledUserChoiceException;
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;
/**
* @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.initClient();
+ /**
+ * 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);
- }
}