package org.mxchange.addressbook.application;\r
\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.manager.application.ApplicationManager;\r
this.getClient().setCurrentMenu("main");\r
\r
// --- Main loop starts here ---\r
- while (this.getClient().isApplicationRunning()) {\r
+ while (this.getClient().isRunning()) {\r
// The application is still active, show menu selection\r
this.getClient().showCurrentMenu();\r
\r
try {\r
// Ask for user input and run proper method\r
this.getClient().doUserMenuChoice();\r
- } catch (final Exception ex) {\r
+ } catch (final UnhandledUserChoiceException ex) {\r
this.getLogger().catching(ex);\r
}\r
}\r
package org.mxchange.addressbook.client;\r
\r
import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.menu.Menu;\r
\r
/**\r
* A general client\r
*\r
* @author Roland Haeder\r
*/\r
-public class BaseClient extends BaseFrameworkSystem {\r
+public abstract class BaseClient extends BaseFrameworkSystem {\r
\r
/**\r
* Current menu choice\r
this.isRunning = false;\r
}\r
\r
+ /**\r
+ * Enables the client\r
+ */\r
public void enableIsRunning () {\r
this.isRunning = true;\r
}\r
\r
/**\r
* Current menu choice\r
+ * \r
* @return the currentMenu\r
*/\r
public String getCurrentMenu () {\r
this.currentMenu = currentMenu;\r
}\r
\r
- public boolean isApplicationRunning () {\r
+ /**\r
+ * Some kind of "getter" for a Menu instance from given menu type\r
+ *\r
+ * @param menuType Menu type, e.g. "main" for main menu\r
+ * @return\r
+ */\r
+ public abstract Menu getMenu (final String menuType);\r
+\r
+ /**\r
+ * Determines whether the application is still active by checking some\r
+ * conditions\r
+ * \r
+ * @return Whether the application is still active\r
+ */\r
+ public boolean isRunning () {\r
// In console client, 0 may have been used\r
return this.isRunning;\r
}\r
+\r
+ /**\r
+ * Shows given menu\r
+ *\r
+ * @param menuType Given menu to show\r
+ */\r
+ protected void showMenu (final String menuType) {\r
+ Menu menu = this.getMenu(menuType);\r
+ \r
+ // Is the menu set?\r
+ if (!(menu instanceof Menu)) {\r
+ // Not found\r
+ // @todo Own exception?\r
+ throw new NullPointerException("Menu '" + menuType + "' not found.");\r
+ }\r
+ \r
+ // Show menu\r
+ menu.show((Client) this);\r
+ }\r
}\r
import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
\r
/**\r
- *\r
+ * An interface for application clients\r
+ * \r
* @author Roland Haeder\r
*/\r
public interface Client extends FrameworkInterface {\r
public SelectableMenuItem getMenuItem (final char accessKey, final String text);\r
\r
/**\r
- * Determines whether the application is still active by checking some\r
+ * Determines whether the client is still active by checking some\r
* conditions\r
* \r
- * @return Whether the application is still active\r
+ * @return Whether the client is still active\r
*/\r
- public boolean isApplicationRunning ();\r
+ public boolean isRunning ();\r
\r
/**\r
* Shows given menu entry in client\r
+ * \r
* @param item Menu item to show\r
*/\r
public void showEntry (final SelectableMenuItem item);\r
}\r
}\r
\r
- /**\r
- * Fills menu map with menu entries\r
- */\r
- private void fillConsoleMenuMap () {\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
- private 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
- }\r
-\r
/**\r
* Reads one character\r
* \r
}\r
\r
/**\r
- * Shows given menu\r
+ * Fills menu map with menu entries\r
+ */\r
+ protected void fillConsoleMenuMap () {\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 Given menu to show\r
+ * @param menuType Menu type instance to return\r
+ * @return Menu or null if not found\r
*/\r
- private void showMenu (final String menuType) {\r
- Menu menu = this.getMenu(menuType);\r
+ @Override\r
+ public Menu getMenu (final String menuType) {\r
+ // Default is not found\r
+ Menu menu = null;\r
\r
- // Is the menu set?\r
- if (!(menu instanceof Menu)) {\r
- // Not found\r
- // @todo Own exception?\r
- throw new NullPointerException("Menu '" + menuType + "' not found.");\r
+ // Check array\r
+ if (this.menus.containsKey(menuType)) {\r
+ // Found!\r
+ menu = this.menus.get(menuType);\r
}\r
\r
- // Show menu\r
- menu.show(this);\r
+ // Return it\r
+ return menu;\r
}\r
}\r