*/\r
package org.mxchange.addressbook.application;\r
\r
+import java.text.MessageFormat;\r
import org.mxchange.addressbook.BaseFrameworkSystem;\r
import org.mxchange.addressbook.UnhandledUserChoiceException;\r
import org.mxchange.addressbook.client.Client;\r
import org.mxchange.addressbook.client.console.ConsoleClient;\r
+import org.mxchange.addressbook.client.gui.SwingClient;\r
import org.mxchange.addressbook.manager.application.ApplicationManager;\r
\r
/**\r
/**\r
* Application title\r
*/\r
- public static final String APP_TITLE = "Addressbuch";\r
+ public static final String APP_TITLE = "Adressbuch";\r
\r
/**\r
* Application version\r
public static final String APP_VERSION = "0.0";\r
\r
/**\r
- * Main method (entry point)\r
- *\r
- * @param args the command line arguments\r
+ * Console client is enabled by default\r
*/\r
- public static void main (String[] args) {\r
- // Start application\r
- new AddressbookApplication().start();\r
- }\r
+ private boolean consoleClient = true;\r
+\r
+ /**\r
+ * GUI client is disabled by default\r
+ */\r
+ private boolean guiClient = false;\r
\r
/**\r
* Bootstraps application\r
@Override\r
public void doBootstrap () {\r
this.getLogger().debug("Initializing application ...");\r
- \r
- // Init client instance\r
- Client client = new ConsoleClient(this);\r
\r
- // Init client instance\r
+ // Init client variable\r
+ Client client = null;\r
+\r
+ // Is console or Swing choosen?\r
+ if (this.isConsole()) {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing console client ...");\r
+\r
+ // Init console client instance\r
+ client = new ConsoleClient(this);\r
+ } else if (this.isGui()) {\r
+ // Debug message\r
+ this.getLogger().debug("Initializing GUI (Swing) client ...");\r
+\r
+ // Init console instance\r
+ client = new SwingClient(this);\r
+ } else {\r
+ // Not client choosen\r
+ this.getLogger().error("No client choosen. Cannot launch.");\r
+ System.exit(1);\r
+ }\r
+ \r
+ // Set client instance\r
this.setClient(client);\r
\r
// The application is running at this point\r
this.getLogger().debug("Main loop exit - shutting down ...");\r
}\r
\r
+ /**\r
+ * Enables console client by setting propper flag\r
+ */\r
+ private void enableConsoleClient () {\r
+ this.getLogger().debug("Enabling console client (may become optional client) ...");\r
+ this.consoleClient = true;\r
+ this.guiClient = false;\r
+ }\r
+\r
+ /**\r
+ * Enables GUI client by setting propper flag\r
+ */\r
+ private void enableGuiClient () {\r
+ this.getLogger().debug("Enabling GUI client (may become new default client) ...");\r
+ this.consoleClient = false;\r
+ this.guiClient = true;\r
+ }\r
+\r
+ /**\r
+ * Checks whether the client shoule be console client should be launched by\r
+ * checking if -console is set.\r
+ * \r
+ * @return Whether console client should be taken\r
+ */\r
+ private boolean isConsole () {\r
+ return this.consoleClient;\r
+ }\r
+\r
+ /**\r
+ * Checks whether the client shoule be GUI client should be launched by\r
+ * checking if -gui is set.\r
+ * \r
+ * @return Whether GUI client should be taken\r
+ */\r
+ private boolean isGui () {\r
+ return this.guiClient;\r
+ }\r
+\r
+ /**\r
+ * Parses all given arguments\r
+ *\r
+ * @param args Arguments from program launch\r
+ */\r
+ private void parseArguments (final String[] args) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));\r
+ \r
+ for (final String arg : args) {\r
+ // Switch on it\r
+ switch (arg) {\r
+ case "-console":\r
+ enableConsoleClient();\r
+ break;\r
+ \r
+ case "-gui":\r
+ enableGuiClient();\r
+ break;\r
+}\r
+ }\r
+ }\r
+\r
/**\r
* Show introduction which depends on client\r
*/\r
\r
/**\r
* Launches the application\r
+ * \r
+ * @param args Arguments handled to program\r
*/\r
- private void start () {\r
+ private void start (final String args[]) {\r
this.getLogger().info("Program is started.");\r
\r
+ // Parse arguments\r
+ this.parseArguments(args);\r
+\r
// Launch application\r
ApplicationManager.getManager(this).start();\r
\r
this.getLogger().info("End of program (last line)");\r
}\r
\r
+ /**\r
+ * Main method (entry point)\r
+ *\r
+ * @param args the command line arguments\r
+ */\r
+ public static void main (String[] args) {\r
+ // Start application\r
+ new AddressbookApplication().start(args);\r
+ }\r
}\r
*/\r
package org.mxchange.addressbook.client;\r
\r
+import java.util.HashMap;\r
+import java.util.Map;\r
import org.mxchange.addressbook.BaseFrameworkSystem;\r
import org.mxchange.addressbook.menu.Menu;\r
\r
*/\r
private boolean isRunning;\r
\r
+ /**\r
+ * Menu system\r
+ */\r
+ private final Map<String, Menu> menus;\r
+\r
/**\r
* No instances can be created of this class\r
*/\r
protected BaseClient () {\r
super();\r
+\r
+ // Init menu map\r
+ this.menus = new HashMap<>(10);\r
}\r
\r
/**\r
}\r
\r
/**\r
- * Some kind of "getter" for a Menu instance from given menu type\r
+ * "Getter" for given menu type\r
*\r
- * @param menuType Menu type, e.g. "main" for main menu\r
- * @return\r
+ * @param menuType Menu type instance to return\r
+ * @return Menu or null if not found\r
*/\r
- public abstract Menu getMenu (final String menuType);\r
+ public Menu getMenu (final String menuType) {\r
+ // Default is not found\r
+ Menu menu = null;\r
+ \r
+ // Check array\r
+ if (this.getMenus().containsKey(menuType)) {\r
+ // Found!\r
+ menu = this.getMenus().get(menuType);\r
+ }\r
+ \r
+ // Return it\r
+ return menu;\r
+ }\r
\r
/**\r
* Determines whether the application is still active by checking some\r
return this.isRunning;\r
}\r
\r
+ /**\r
+ * Fills menu map with swing menus\r
+ */\r
+ protected abstract void fillMenuMap ();\r
+\r
+ /**\r
+ * Getter for menus map\r
+ * @return Map of all menus\r
+ */\r
+ protected final Map<String, Menu> getMenus () {\r
+ return this.menus;\r
+ }\r
+\r
/**\r
* Shows given menu\r
*\r
\r
import java.text.MessageFormat;\r
import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
import java.util.Scanner;\r
import org.mxchange.addressbook.UnhandledUserChoiceException;\r
import org.mxchange.addressbook.application.AddressbookApplication;\r
* @author Roland Haeder\r
*/\r
public class ConsoleClient extends BaseClient implements Client {\r
- /**\r
- * Menu system\r
- */\r
- private final Map<String, Menu> menus;\r
-\r
/**\r
* Scanner instance for reading data from console input\r
*/\r
// Init scanner instance\r
this.scanner = new Scanner(System.in);\r
\r
- // Init menu map\r
- this.menus = new HashMap<>(10);\r
-\r
// Fill menu map\r
- this.fillConsoleMenuMap();\r
+ this.fillMenuMap();\r
}\r
\r
/**\r
@Override\r
public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
// Get all access keys from menu\r
- char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.menus, this.getCurrentMenu());\r
+ char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());\r
\r
// Output textural message and ask for a char as input\r
char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
this.getContactManager().addOtherAddress();\r
break;\r
\r
- case '4': // Change other addess\r
+ case '4': // List contacts\r
+ this.getContactManager().listContacts();\r
+ break;\r
+ \r
+ case '5': // Search addresses\r
+ this.getContactManager().searchContacts();\r
+ break;\r
+\r
+ case '6': // Change other addess\r
this.getContactManager().changeOtherAddress();\r
break;\r
\r
- case '5': // Delete other address\r
+ case '7': // Delete other address\r
this.getContactManager().deleteOtherAddress();\r
break;\r
\r
this.showMenu(this.getCurrentMenu());\r
}\r
\r
+ /**\r
+ * Shows given menu entry to user\r
+ * \r
+ * @param item Menu entry\r
+ */\r
@Override\r
public void showEntry (final SelectableMenuItem item) {\r
// Access key then text\r
\r
// Debug message\r
this.getLogger().debug("Intro shown to user");\r
- }\r
+ }\r
\r
@Override\r
public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
/**\r
* Fills menu map with menu entries\r
*/\r
- protected void fillConsoleMenuMap () {\r
+ @Override\r
+ protected final void fillMenuMap () {\r
// Initialize first (main) menu\r
Menu menu = new ConsoleMenu("main", this);\r
\r
// Add it\r
- this.menus.put("main", menu);\r
- }\r
-\r
- /**\r
- * "Getter" for given menu type\r
- *\r
- * @param menuType Menu type instance to return\r
- * @return Menu or null if not found\r
- */\r
- @Override\r
- public Menu getMenu (final String menuType) {\r
- // Default is not found\r
- Menu menu = null;\r
- \r
- // Check array\r
- if (this.menus.containsKey(menuType)) {\r
- // Found!\r
- menu = this.menus.get(menuType);\r
- }\r
- \r
- // Return it\r
- return menu;\r
+ this.getMenus().put("main", menu);\r
}\r
}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.client.gui;\r
+\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
+import org.mxchange.addressbook.application.AddressbookApplication;\r
+import org.mxchange.addressbook.client.BaseClient;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.menu.Menu;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class SwingClient extends BaseClient implements Client {\r
+ /**\r
+ * Constructor with application instance\r
+ * @param application \r
+ */\r
+ public SwingClient (final AddressbookApplication application) {\r
+ super();\r
+\r
+ // Set application instance\r
+ this.setApplication(application);\r
+\r
+ // Init contact manager here\r
+ this.initContactManager(this);\r
+\r
+ // Fill menu map\r
+ this.fillMenuMap();\r
+ }\r
+\r
+ @Override\r
+ public void displayAddressBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void displayNameBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void displayOtherDataBox (final Contact contact) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public char enterChar (final char[] validChars, String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public int enterInt (final int minimum, final int maximum, final String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public Menu getMenu (final String menuType) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ /**\r
+ * Returns a Swing menu item\r
+ * \r
+ * @param accessKey Key to access the menu\r
+ * @param text Text to show to user\r
+ * @return A SelectableMenuItem\r
+ * @todo Make sure the access key is unique\r
+ */\r
+ @Override\r
+ public SelectableMenuItem getMenuItem (final char accessKey, final String text) {\r
+ // Returns null as the menu is now no longer controlled here.\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void outputMessage (final String message) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void showCurrentMenu () {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void showEntry (final SelectableMenuItem item) {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void showWelcome () {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ @Override\r
+ public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {\r
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ }\r
+\r
+ /**\r
+ * Fills menu map with swing menus\r
+ */\r
+ @Override\r
+ protected final void fillMenuMap () {\r
+ // Nothing to fill here as the Swing frame is handling this all\r
+ }\r
+ \r
+}\r
return Collections.unmodifiableList(this.contacts);\r
}\r
\r
+ @Override\r
+ public void listContacts () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
/**\r
* Adds given contact to address book and flushes all entries to database\r
*\r
this.flush();\r
}\r
\r
+ @Override\r
+ public void searchContacts () {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
+ }\r
+\r
/**\r
* Getter for size\r
*\r
* @author Roland Haeder\r
*/\r
public interface ManageableContact extends Manageable {\r
+\r
+ /**\r
+ * List all contacts\r
+ */\r
+ public void listContacts ();\r
+\r
/**\r
* Adds given contact to address book\r
*\r
*/\r
public List<Contact> getList ();\r
\r
+ /**\r
+ * Searches address book for a contact\r
+ */\r
+ public void searchContacts ();\r
+\r
/**\r
* Getter for size\r
*\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseMenu extends BaseFrameworkSystem {\r
+ /**\r
+ * Menu list\r
+ */\r
+ private List<SelectableMenuItem> menuList;\r
+\r
+ /**\r
+ * No instance from this object\r
+ */\r
+ protected BaseMenu () {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * Size of menu items\r
+ * @return Count of menu items\r
+ */\r
+ public int getMenuItemsCount () {\r
+ return this.menuList.size();\r
+ }\r
+\r
+ /**\r
+ * "Getter" for an iterator of this menu's items\r
+ *\r
+ * @return An iterator of all menu items\r
+ */\r
+ public Iterator<SelectableMenuItem> getMenuItemsIterator () {\r
+ return this.menuList.iterator();\r
+ }\r
+\r
+ /**\r
+ * Shows this menu\r
+ * \r
+ * @param client Client instance to call back\r
+ */\r
+ public void show (final Client client) {\r
+ // Get values\r
+ Iterator<SelectableMenuItem> iterator = this.menuList.iterator();\r
+\r
+ // Debug message\r
+ this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");\r
+\r
+ // Output all menus\r
+ while (iterator.hasNext()) {\r
+ // Get item\r
+ SelectableMenuItem item = iterator.next();\r
+\r
+ // Show this item\r
+ item.show(client);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Getter for menu list\r
+ *\r
+ * @return menuList List of menu entries\r
+ */\r
+ protected final List<SelectableMenuItem> getMenuList () {\r
+ return this.menuList;\r
+ }\r
+\r
+ /**\r
+ * Initializes menu\r
+ * @param menuType Menu type to initialize\r
+ * @param client CLient to call back\r
+ */\r
+ protected void initMenu (final String menuType, final Client client) {\r
+ // Init menu list\r
+ this.menuList = new ArrayList<>(5);\r
+ }\r
+}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2015 Roland Haeder\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package org.mxchange.addressbook.menu.console;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.menu.AddressbookMenu;\r
-import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
-\r
-/**\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class BaseMenu extends BaseFrameworkSystem {\r
- /**\r
- * Menu list\r
- */\r
- private List<SelectableMenuItem> menuList;\r
-\r
- /**\r
- * No instance from this object\r
- */\r
- protected BaseMenu () {\r
- super();\r
- }\r
-\r
- /**\r
- * Size of menu items\r
- * @return Count of menu items\r
- */\r
- public int getMenuItemsCount () {\r
- return this.menuList.size();\r
- }\r
-\r
- /**\r
- * "Getter" for an iterator of this menu's items\r
- *\r
- * @return An iterator of all menu items\r
- */\r
- public Iterator<SelectableMenuItem> getMenuItemsIterator () {\r
- return this.menuList.iterator();\r
- }\r
-\r
- /**\r
- * Shows this menu\r
- * \r
- * @param client Client instance to call back\r
- */\r
- public void show (final Client client) {\r
- // Get values\r
- Iterator<SelectableMenuItem> iterator = this.menuList.iterator();\r
-\r
- // Debug message\r
- this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");\r
-\r
- // Output all menus\r
- while (iterator.hasNext()) {\r
- // Get item\r
- SelectableMenuItem item = iterator.next();\r
-\r
- // Show this item\r
- item.show(client);\r
- }\r
- }\r
-\r
- /**\r
- * Initializes menu\r
- * @param menuType Menu type to initialize\r
- * @param client CLient to call back\r
- */\r
- protected void initMenu (final String menuType, final Client client) {\r
- // Init menu list\r
- this.menuList = new ArrayList<>(5);\r
- \r
- // Add all items\r
- AddressbookMenu.addItemsToList(this.menuList, menuType, client);\r
- }\r
-}\r
package org.mxchange.addressbook.menu.console;\r
\r
import org.mxchange.addressbook.client.Client;\r
+import org.mxchange.addressbook.menu.AddressbookMenu;\r
+import org.mxchange.addressbook.menu.BaseMenu;\r
import org.mxchange.addressbook.menu.Menu;\r
\r
/**\r
*/\r
public ConsoleMenu (final String menuType, final Client client) {\r
this.initMenu(menuType, client);\r
+ \r
+ // Add all items\r
+ AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client);\r
}\r
}\r