]> git.mxchange.org Git - jfinancials-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/client/BaseClient.java
Moved declaration of menu and item instances up as they will be used again
[jfinancials-lib.git] / Addressbook / src / org / mxchange / addressbook / client / BaseClient.java
index 399a6c1b9bedb891adc79f848e9ce61269ab9777..0c8bba50c4b12c8f373ca36acb97b7c9d74e22e5 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.client;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.manager.contact.ContactManager;\r
-import org.mxchange.addressbook.manager.contact.ManageableContact;\r
-import org.mxchange.addressbook.menu.Menu;\r
-\r
-/**\r
- * A general client\r
- *\r
- * @author Roland Haeder\r
- */\r
-public abstract class BaseClient extends BaseFrameworkSystem {\r
-\r
-    /**\r
-     * Current menu choice\r
-     */\r
-    private String currentMenu;\r
-\r
-    /**\r
-     * Application is not running by default\r
-     */\r
-    private boolean isRunning;\r
-\r
-    /**\r
-     * Menu system\r
-     */\r
-    private final Map<String, Menu> menus;\r
-\r
-    /**\r
-     * No instances can be created of this class\r
-     */\r
-    protected BaseClient () {\r
-       super();\r
-\r
-       // Init menu map\r
-       this.menus = new HashMap<>(10);\r
-    }\r
-\r
-    /**\r
-     * Shutdown method for all clients\r
-     */\r
-    public void doShutdown () {\r
-       // Disable client\r
-       this.disableIsRunning();\r
-\r
-       // Shuts down contact manager\r
-       this.getContactManager().doShutdown();\r
-    }\r
-\r
-    /**\r
-     * Enables the client\r
-     */\r
-    public final void enableIsRunning () {\r
-       this.isRunning = true;\r
-    }\r
-\r
-    /**\r
-     * Current menu choice\r
-     * \r
-     * @return the currentMenu\r
-     */\r
-    public final String getCurrentMenu () {\r
-       return this.currentMenu;\r
-    }\r
-\r
-    /**\r
-     * Current menu choice\r
-     * @param currentMenu the currentMenu to set\r
-     */\r
-    public final void setCurrentMenu (final String currentMenu) {\r
-       this.currentMenu = currentMenu;\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
-    public Menu getMenu (final String menuType) {\r
-       // Default is not found\r
-       Menu menu = null;\r
-       \r
-       // Check array\r
-       if (this.getMenus().containsKey(menuType)) {\r
-           // Found!\r
-           menu = this.getMenus().get(menuType);\r
-       }\r
-       \r
-       // Return it\r
-       return menu;\r
-    }\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 final boolean isRunning () {\r
-       // In console client, 0 may have been used\r
-       return this.isRunning;\r
-    }\r
-\r
-    /**\r
-     * Disables running state, so the main loop can abort.\r
-     */\r
-    protected final void disableIsRunning () {\r
-       this.isRunning = false;\r
-    }\r
-\r
-    /**\r
-     * Fills menu map with swing menus\r
-     */\r
-    protected abstract void fillMenuMap ();\r
-\r
-    /**\r
-     * Getter for menus map\r
-     * @return Map of all menus\r
-     */\r
-    protected final Map<String, Menu> getMenus () {\r
-       return this.menus;\r
-    }\r
-\r
-    /**\r
-     * Initializes contact manager\r
-     */\r
-    protected void initContactManager () {\r
-       // Debug message\r
-       this.getLogger().debug("Initializing contact manager ...");\r
-       \r
-       // Init contact manager with console client\r
-       // @TODO Static initial amount of contacts\r
-       ManageableContact manager = new ContactManager (100, (Client) this);\r
-       \r
-       // Set it here\r
-       this.setContactManager(manager);\r
-       \r
-       // Debug message\r
-       this.getLogger().debug("Contact manager has been initialized.");\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
+/*
+ * 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.client;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.manager.contact.ContactManager;
+import org.mxchange.addressbook.manager.contact.ManageableContact;
+import org.mxchange.addressbook.menu.Menu;
+
+/**
+ * A general client
+ *
+ * @author Roland Haeder
+ */
+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);
+       }
+       
+       // 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);
+    }
+}