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
168 // Set client instance
\r
169 this.setClient(client);
\r
171 // The application is running at this point
\r
172 this.getClient().enableIsRunning();
\r
176 * Main loop of the application
\r
179 public void doMainLoop () {
\r
180 // @TODO The application should be running now
\r
182 // Output introduction
\r
185 // Set current menu to main
\r
186 this.getClient().setCurrentMenu("main");
\r
188 // --- Main loop starts here ---
\r
189 while (this.getClient().isRunning()) {
\r
190 // The application is still active, show menu selection
\r
191 this.getClient().showCurrentMenu();
\r
194 // Ask for user input and run proper method
\r
195 this.getClient().doUserMenuChoice();
\r
196 } catch (final UnhandledUserChoiceException ex) {
\r
197 this.getLogger().catching(ex);
\r
200 // --- Main loop ends here ---
\r
203 this.getLogger().debug("Main loop exit - shutting down ...");
\r
207 * Enables console client by setting propper flag
\r
209 private void enableConsoleClient () {
\r
210 this.getLogger().debug("Enabling console client (may become optional client) ...");
\r
211 this.consoleClient = true;
\r
212 this.guiClient = false;
\r
216 * Enables GUI client by setting propper flag
\r
218 private void enableGuiClient () {
\r
219 this.getLogger().debug("Enabling GUI client (may become new default client) ...");
\r
220 this.consoleClient = false;
\r
221 this.guiClient = true;
\r
225 * Checks whether the client shoule be console client should be launched by
\r
226 * checking if -console is set.
\r
228 * @return Whether console client should be taken
\r
230 private boolean isConsole () {
\r
231 return this.consoleClient;
\r
235 * Checks whether the client shoule be GUI client should be launched by
\r
236 * checking if -gui is set.
\r
238 * @return Whether GUI client should be taken
\r
240 private boolean isGui () {
\r
241 return this.guiClient;
\r
245 * Parses all given arguments
\r
247 * @param args Arguments from program launch
\r
249 private void parseArguments (final String[] args) {
\r
251 this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));
\r
253 for (final String arg : args) {
\r
257 enableConsoleClient();
\r
268 * Show introduction which depends on client
\r
270 private void showIntro () {
\r
271 // Let the client show it
\r
272 this.getClient().showWelcome();
\r
276 * Launches the application
\r
278 * @param args Arguments handled to program
\r
280 private void start (final String args[]) {
\r
281 this.getLogger().info("Program is started.");
\r
284 this.parseArguments(args);
\r
286 // Launch application
\r
287 ApplicationManager.getManager(this).start();
\r
289 this.getLogger().info("End of program (last line)");
\r
293 * Main method (entry point)
\r
295 * @param args the command line arguments
\r
297 public static void main (String[] args) {
\r
298 // Start application
\r
299 new AddressbookApplication().start(args);
\r