]> git.mxchange.org Git - jaddressbook-share-lib.git/blob - Addressbook/src/org/mxchange/addressbook/client/BaseClient.java
706229c3036de3a5c9089f01a547a4f7a2d936ef
[jaddressbook-share-lib.git] / Addressbook / src / org / mxchange / addressbook / client / BaseClient.java
1 /*\r
2  * Copyright (C) 2015 Roland Haeder\r
3  *\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
8  *\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
13  *\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
16  */\r
17 package org.mxchange.addressbook.client;\r
18 \r
19 import org.mxchange.addressbook.BaseFrameworkSystem;\r
20 import org.mxchange.addressbook.menu.Menu;\r
21 \r
22 /**\r
23  * A general client\r
24  *\r
25  * @author Roland Haeder\r
26  */\r
27 public abstract class BaseClient extends BaseFrameworkSystem {\r
28 \r
29     /**\r
30      * Current menu choice\r
31      */\r
32     private String currentMenu;\r
33 \r
34     /**\r
35      * Application is not running by default\r
36      */\r
37     private boolean isRunning;\r
38 \r
39     /**\r
40      * No instances can be created of this class\r
41      */\r
42     protected BaseClient () {\r
43         super();\r
44     }\r
45 \r
46     /**\r
47      * Disables running state, so the main loop can abort.\r
48      */\r
49     public void disableIsRunning () {\r
50         this.isRunning = false;\r
51     }\r
52 \r
53     /**\r
54      * Enables the client\r
55      */\r
56     public void enableIsRunning () {\r
57         this.isRunning = true;\r
58     }\r
59 \r
60     /**\r
61      * Current menu choice\r
62      * \r
63      * @return the currentMenu\r
64      */\r
65     public String getCurrentMenu () {\r
66         return this.currentMenu;\r
67     }\r
68 \r
69     /**\r
70      * Current menu choice\r
71      * @param currentMenu the currentMenu to set\r
72      */\r
73     public void setCurrentMenu (final String currentMenu) {\r
74         this.currentMenu = currentMenu;\r
75     }\r
76 \r
77     /**\r
78      * Some kind of "getter" for a Menu instance from given menu type\r
79      *\r
80      * @param menuType Menu type, e.g. "main" for main menu\r
81      * @return\r
82      */\r
83     public abstract Menu getMenu (final String menuType);\r
84 \r
85     /**\r
86      * Determines whether the application is still active by checking some\r
87      * conditions\r
88      * \r
89      * @return Whether the application is still active\r
90      */\r
91     public boolean isRunning () {\r
92         // In console client, 0 may have been used\r
93         return this.isRunning;\r
94     }\r
95 \r
96     /**\r
97      * Shows given menu\r
98      *\r
99      * @param menuType Given menu to show\r
100      */\r
101     protected void showMenu (final String menuType) {\r
102         Menu menu = this.getMenu(menuType);\r
103         \r
104         // Is the menu set?\r
105         if (!(menu instanceof Menu)) {\r
106             // Not found\r
107             // @todo Own exception?\r
108             throw new NullPointerException("Menu '" + menuType + "' not found.");\r
109         }\r
110         \r
111         // Show menu\r
112         menu.show((Client) this);\r
113     }\r
114 }\r