2 * Copyright (C) 2015 Roland Haeder
\r
4 * This program is free software: you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation, either version 3 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
17 package org.mxchange.addressbook.client;
\r
19 import java.util.HashMap;
\r
20 import java.util.Map;
\r
21 import org.mxchange.addressbook.BaseFrameworkSystem;
\r
22 import org.mxchange.addressbook.menu.Menu;
\r
27 * @author Roland Haeder
\r
29 public abstract class BaseClient extends BaseFrameworkSystem {
\r
32 * Current menu choice
\r
34 private String currentMenu;
\r
37 * Application is not running by default
\r
39 private boolean isRunning;
\r
44 private final Map<String, Menu> menus;
\r
47 * No instances can be created of this class
\r
49 protected BaseClient () {
\r
53 this.menus = new HashMap<>(10);
\r
57 * Disables running state, so the main loop can abort.
\r
59 public void disableIsRunning () {
\r
60 this.isRunning = false;
\r
64 * Enables the client
\r
66 public void enableIsRunning () {
\r
67 this.isRunning = true;
\r
71 * Current menu choice
\r
73 * @return the currentMenu
\r
75 public String getCurrentMenu () {
\r
76 return this.currentMenu;
\r
80 * Current menu choice
\r
81 * @param currentMenu the currentMenu to set
\r
83 public void setCurrentMenu (final String currentMenu) {
\r
84 this.currentMenu = currentMenu;
\r
88 * "Getter" for given menu type
\r
90 * @param menuType Menu type instance to return
\r
91 * @return Menu or null if not found
\r
93 public Menu getMenu (final String menuType) {
\r
94 // Default is not found
\r
98 if (this.getMenus().containsKey(menuType)) {
\r
100 menu = this.getMenus().get(menuType);
\r
108 * Determines whether the application is still active by checking some
\r
111 * @return Whether the application is still active
\r
113 public boolean isRunning () {
\r
114 // In console client, 0 may have been used
\r
115 return this.isRunning;
\r
119 * Fills menu map with swing menus
\r
121 protected abstract void fillMenuMap ();
\r
124 * Getter for menus map
\r
125 * @return Map of all menus
\r
127 protected final Map<String, Menu> getMenus () {
\r
134 * @param menuType Given menu to show
\r
136 protected void showMenu (final String menuType) {
\r
137 Menu menu = this.getMenu(menuType);
\r
139 // Is the menu set?
\r
140 if (!(menu instanceof Menu)) {
\r
142 // @todo Own exception?
\r
143 throw new NullPointerException("Menu '" + menuType + "' not found.");
\r
147 menu.show((Client) this);
\r