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 org.mxchange.addressbook.BaseFrameworkSystem;
\r
20 import org.mxchange.addressbook.menu.Menu;
\r
25 * @author Roland Haeder
\r
27 public abstract class BaseClient extends BaseFrameworkSystem {
\r
30 * Current menu choice
\r
32 private String currentMenu;
\r
35 * Application is not running by default
\r
37 private boolean isRunning;
\r
40 * No instances can be created of this class
\r
42 protected BaseClient () {
\r
47 * Disables running state, so the main loop can abort.
\r
49 public void disableIsRunning () {
\r
50 this.isRunning = false;
\r
54 * Enables the client
\r
56 public void enableIsRunning () {
\r
57 this.isRunning = true;
\r
61 * Current menu choice
\r
63 * @return the currentMenu
\r
65 public String getCurrentMenu () {
\r
66 return this.currentMenu;
\r
70 * Current menu choice
\r
71 * @param currentMenu the currentMenu to set
\r
73 public void setCurrentMenu (final String currentMenu) {
\r
74 this.currentMenu = currentMenu;
\r
78 * Some kind of "getter" for a Menu instance from given menu type
\r
80 * @param menuType Menu type, e.g. "main" for main menu
\r
83 public abstract Menu getMenu (final String menuType);
\r
86 * Determines whether the application is still active by checking some
\r
89 * @return Whether the application is still active
\r
91 public boolean isRunning () {
\r
92 // In console client, 0 may have been used
\r
93 return this.isRunning;
\r
99 * @param menuType Given menu to show
\r
101 protected void showMenu (final String menuType) {
\r
102 Menu menu = this.getMenu(menuType);
\r
104 // Is the menu set?
\r
105 if (!(menu instanceof Menu)) {
\r
107 // @todo Own exception?
\r
108 throw new NullPointerException("Menu '" + menuType + "' not found.");
\r
112 menu.show((Client) this);
\r