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.application;
\r
19 import java.text.MessageFormat;
\r
20 import org.mxchange.addressbook.BaseFrameworkSystem;
\r
21 import org.mxchange.addressbook.UnhandledUserChoiceException;
\r
22 import org.mxchange.addressbook.client.Client;
\r
23 import org.mxchange.addressbook.client.console.ConsoleClient;
\r
24 import org.mxchange.addressbook.client.gui.SwingClient;
\r
25 import org.mxchange.addressbook.manager.application.ApplicationManager;
\r
28 * ============================================
\r
29 * AddressbookApplication management:
\r
30 * ============================================
\r
32 * Inernet("public" service) and Intranet
\r
35 * - Single-user local application
\r
46 * + Cell phone number
\r
54 * - Categorization of contacts
\r
57 * - Permanent storage in database
\r
60 * - Multi-user web application
\r
61 * - Local user registration / login / resend confirmation link / password
\r
63 * - User groups (aka. teams)
\r
64 * - Administration area (user role)
\r
65 * + Create/edit/delete groups
\r
66 * + Edit/delete/lock/unlock user
\r
67 * + Assign user roles/rights
\r
68 * - Allow other users / groups to view addressbook
\r
69 * + Full addressbook
\r
70 * + Only some categories
\r
72 * + Allow users/guests (not recommended)
\r
73 * - XML export of addressbook and compressable (ZIP)
\r
74 * - Form to contact other user/group without need of mail program
\r
75 * + User can disabled this
\r
76 * - Directory for ussers/groups (who allowed to be listed)
\r
77 * + Simple click to add user to own addressbook
\r
81 * - Multi-language support
\r
83 * Version 2.2+:("socialized")
\r
84 * - "Social login" (OpenID consumer)
\r
85 * + Connect user account to social account
\r
87 * - "Social profile"
\r
89 * + RSS/activity feed
\r
91 * ============================================
\r
93 * ============================================
\r
99 * + Initial tables: contacts, categories, contact_category
\r
103 * + Additional tables: admins (?), admin_rights, groups,
\r
104 * users, user_contacts, user_user_rights, user_category_rights,
\r
108 * + Additional tables: languages (disable, enable language "pack" ?)
\r
112 * + Additional tables: ???
\r
114 * @author Roland Haeder
\r
118 public class AddressbookApplication extends BaseFrameworkSystem implements Application {
\r
120 * Application title
\r
122 public static final String APP_TITLE = "Adressbuch";
\r
125 * Application version
\r
127 public static final String APP_VERSION = "0.0";
\r
130 * Console client is enabled by default
\r
132 private boolean consoleClient = true;
\r
135 * GUI client is disabled by default
\r
137 private boolean guiClient = false;
\r
140 * Bootstraps application
\r
143 public void doBootstrap () {
\r
144 this.getLogger().debug("Initializing application ...");
\r
146 // Init client variable
\r
147 Client client = null;
\r
149 // Is console or Swing choosen?
\r
150 if (this.isConsole()) {
\r
152 this.getLogger().debug("Initializing console client ...");
\r
154 // Init console client instance
\r
155 client = new ConsoleClient(this);
\r
156 } else if (this.isGui()) {
\r
158 this.getLogger().debug("Initializing GUI (Swing) client ...");
\r
160 // Init console instance
\r
161 client = new SwingClient(this);
\r
163 // Not client choosen
\r
164 this.getLogger().error("No client choosen. Cannot launch.");
\r
169 client.initClient();
\r
171 // Set client instance
\r
172 this.setClient(client);
\r
174 // The application is running at this point
\r
175 this.getClient().enableIsRunning();
\r
179 * Main loop of the application
\r
182 public void doMainLoop () {
\r
183 // @TODO The application should be running now
\r
185 // Output introduction
\r
188 // Set current menu to main
\r
189 this.getClient().setCurrentMenu("main");
\r
191 // --- Main loop starts here ---
\r
192 while (this.getClient().isRunning()) {
\r
193 // The application is still active, show menu selection
\r
194 this.getClient().showCurrentMenu();
\r
197 // Ask for user input and run proper method
\r
198 this.getClient().doUserMenuChoice();
\r
199 } catch (final UnhandledUserChoiceException ex) {
\r
200 this.getLogger().catching(ex);
\r
203 // --- Main loop ends here ---
\r
206 this.getLogger().debug("Main loop exit - shutting down ...");
\r
210 * Enables console client by setting propper flag
\r
212 private void enableConsoleClient () {
\r
213 this.getLogger().debug("Enabling console client (may become optional client) ...");
\r
214 this.consoleClient = true;
\r
215 this.guiClient = false;
\r
219 * Enables GUI client by setting propper flag
\r
221 private void enableGuiClient () {
\r
222 this.getLogger().debug("Enabling GUI client (may become new default client) ...");
\r
223 this.consoleClient = false;
\r
224 this.guiClient = true;
\r
228 * Checks whether the client shoule be console client should be launched by
\r
229 * checking if -console is set.
\r
231 * @return Whether console client should be taken
\r
233 private boolean isConsole () {
\r
234 return this.consoleClient;
\r
238 * Checks whether the client shoule be GUI client should be launched by
\r
239 * checking if -gui is set.
\r
241 * @return Whether GUI client should be taken
\r
243 private boolean isGui () {
\r
244 return this.guiClient;
\r
248 * Parses all given arguments
\r
250 * @param args Arguments from program launch
\r
252 private void parseArguments (final String[] args) {
\r
254 this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));
\r
256 for (final String arg : args) {
\r
260 enableConsoleClient();
\r
271 * Show introduction which depends on client
\r
273 private void showIntro () {
\r
274 // Let the client show it
\r
275 this.getClient().showWelcome();
\r
279 * Launches the application
\r
281 * @param args Arguments handled to program
\r
283 private void start (final String args[]) {
\r
284 this.getLogger().info("Program is started.");
\r
287 this.parseArguments(args);
\r
289 // Launch application
\r
290 ApplicationManager.getManager(this).start();
\r
292 this.getLogger().info("End of program (last line)");
\r
296 * Main method (entry point)
\r
298 * @param args the command line arguments
\r
300 public static void main (String[] args) {
\r
301 // Start application
\r
302 new AddressbookApplication().start(args);
\r