]> git.mxchange.org Git - jfinancials-swing.git/commitdiff
Made getMenu() abstract as showMenu() is now in BaseClient. This has the benefit...
authorRoland Haeder <roland@mxchange.org>
Thu, 16 Jul 2015 06:26:25 +0000 (08:26 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 16 Jul 2015 06:27:12 +0000 (08:27 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.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

index 44fe4684cc5cffc000efaf930e1293f04d42054d..00baae06f58dbe960b474bee216e58eefd12e4d3 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.addressbook.application;\r
 \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.manager.application.ApplicationManager;\r
@@ -164,14 +165,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
        this.getClient().setCurrentMenu("main");\r
 \r
        // --- Main loop starts here ---\r
-       while (this.getClient().isApplicationRunning()) {\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 Exception ex) {\r
+           } catch (final UnhandledUserChoiceException ex) {\r
                this.getLogger().catching(ex);\r
            }\r
        }\r
index 09c7b0fe865c26c2dc267d49be4195902630d121..706229c3036de3a5c9089f01a547a4f7a2d936ef 100644 (file)
 package org.mxchange.addressbook.client;\r
 \r
 import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.menu.Menu;\r
 \r
 /**\r
  * A general client\r
  *\r
  * @author Roland Haeder\r
  */\r
-public class BaseClient extends BaseFrameworkSystem {\r
+public abstract class BaseClient extends BaseFrameworkSystem {\r
 \r
     /**\r
      * Current menu choice\r
@@ -49,12 +50,16 @@ public class BaseClient extends BaseFrameworkSystem {
        this.isRunning = false;\r
     }\r
 \r
+    /**\r
+     * Enables the client\r
+     */\r
     public void enableIsRunning () {\r
        this.isRunning = true;\r
     }\r
 \r
     /**\r
      * Current menu choice\r
+     * \r
      * @return the currentMenu\r
      */\r
     public String getCurrentMenu () {\r
@@ -69,8 +74,41 @@ public class BaseClient extends BaseFrameworkSystem {
        this.currentMenu = currentMenu;\r
     }\r
 \r
-    public boolean isApplicationRunning () {\r
+    /**\r
+     * Some kind of "getter" for a Menu instance from given menu type\r
+     *\r
+     * @param menuType Menu type, e.g. "main" for main menu\r
+     * @return\r
+     */\r
+    public abstract Menu getMenu (final String menuType);\r
+\r
+    /**\r
+     * Determines whether the application is still active by checking some\r
+     * conditions\r
+     * \r
+     * @return Whether the application is still active\r
+     */\r
+    public boolean isRunning () {\r
        // In console client, 0 may have been used\r
        return this.isRunning;\r
     }\r
+\r
+    /**\r
+     * Shows given menu\r
+     *\r
+     * @param menuType Given menu to show\r
+     */\r
+    protected void showMenu (final String menuType) {\r
+       Menu menu = this.getMenu(menuType);\r
+       \r
+       // Is the menu set?\r
+       if (!(menu instanceof Menu)) {\r
+           // Not found\r
+           // @todo Own exception?\r
+           throw new NullPointerException("Menu '" + menuType + "' not found.");\r
+       }\r
+       \r
+       // Show menu\r
+       menu.show((Client) this);\r
+    }\r
 }\r
index 4319a59969fdcfd2d607fc3319ff35224c982a68..67131390ae84bece05d8b23ee11484660fd14fc9 100644 (file)
@@ -22,7 +22,8 @@ import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
 \r
 /**\r
- *\r
+ * An interface for application clients\r
+ * \r
  * @author Roland Haeder\r
  */\r
 public interface Client extends FrameworkInterface {\r
@@ -125,15 +126,16 @@ public interface Client extends FrameworkInterface {
     public SelectableMenuItem getMenuItem (final char accessKey, final String text);\r
 \r
     /**\r
-     * Determines whether the application is still active by checking some\r
+     * Determines whether the client is still active by checking some\r
      * conditions\r
      * \r
-     * @return Whether the application is still active\r
+     * @return Whether the client is still active\r
      */\r
-    public boolean isApplicationRunning ();\r
+    public boolean isRunning ();\r
 \r
     /**\r
      * Shows given menu entry in client\r
+     * \r
      * @param item Menu item to show\r
      */\r
     public void showEntry (final SelectableMenuItem item);\r
index 841b7b65d8a9d979f17dbc6f75ebba978c3eac83..160eab33eb8a5bb31fb4990a3779d04a4ff98778 100644 (file)
@@ -324,37 +324,6 @@ public class ConsoleClient extends BaseClient implements Client {
        }\r
     }\r
 \r
-    /**\r
-     * Fills menu map with menu entries\r
-     */\r
-    private void fillConsoleMenuMap () {\r
-       // Initialize first (main) menu\r
-       Menu menu = new ConsoleMenu("main", this);\r
-\r
-       // Add it\r
-       this.menus.put("main", menu);\r
-    }\r
-\r
-    /**\r
-     * "Getter" for given menu type\r
-     * \r
-     * @param menuType Menu type instance to return\r
-     * @return Menu or null if not found\r
-     */\r
-    private Menu getMenu (final String menuType) {\r
-       // Default is not found\r
-       Menu menu = null;\r
-\r
-       // Check array\r
-       if (this.menus.containsKey(menuType)) {\r
-           // Found!\r
-           menu = this.menus.get(menuType);\r
-       }\r
-       \r
-       // Return it\r
-       return menu;\r
-    }\r
-\r
     /**\r
      * Reads one character\r
      * \r
@@ -408,21 +377,34 @@ public class ConsoleClient extends BaseClient implements Client {
     }\r
 \r
     /**\r
-     * Shows given menu\r
+     * Fills menu map with menu entries\r
+     */\r
+    protected void fillConsoleMenuMap () {\r
+       // Initialize first (main) menu\r
+       Menu menu = new ConsoleMenu("main", this);\r
+       \r
+       // Add it\r
+       this.menus.put("main", menu);\r
+    }\r
+\r
+    /**\r
+     * "Getter" for given menu type\r
      *\r
-     * @param menuType Given menu to show\r
+     * @param menuType Menu type instance to return\r
+     * @return Menu or null if not found\r
      */\r
-    private void showMenu (final String menuType) {\r
-       Menu menu = this.getMenu(menuType);\r
+    @Override\r
+    public Menu getMenu (final String menuType) {\r
+       // Default is not found\r
+       Menu menu = null;\r
        \r
-       // Is the menu set?\r
-       if (!(menu instanceof Menu)) {\r
-           // Not found\r
-           // @todo Own exception?\r
-           throw new NullPointerException("Menu '" + menuType + "' not found.");\r
+       // Check array\r
+       if (this.menus.containsKey(menuType)) {\r
+           // Found!\r
+           menu = this.menus.get(menuType);\r
        }\r
        \r
-       // Show menu\r
-       menu.show(this);\r
+       // Return it\r
+       return menu;\r
     }\r
 }\r