-/*\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.List;\r
-import org.apache.logging.log4j.Logger;\r
-import org.mxchange.addressbook.BaseFrameworkSystem;\r
-import org.mxchange.addressbook.client.Client;\r
-import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
-\r
-/**\r
- * Utility class for menu structure\r
- * \r
- * @author Roland Haeder\r
- */\r
-public class AddressbookMenu extends BaseFrameworkSystem {\r
- /**\r
- * Copies entries for given type into the menu list\r
- *\r
- * @param menuList Menu list for later showing\r
- * @param menuType Type of menu\r
- * @param client Client instance to call back\r
- */\r
- public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {\r
- // Get logger\r
- Logger log = new AddressbookMenu().getLogger();\r
-\r
- // Get list size\r
- int size = menuList.size();\r
-\r
- // Debug message\r
- log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ...");\r
-\r
- // Depends on type\r
- switch (menuType) {\r
- case "main": // Main menu\r
- // Enter own data\r
- menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen"));\r
-\r
- // Change own data\r
- menuList.add(client.getMenuItem('2', "Eigene Adresse ändern"));\r
-\r
- // Add new addess\r
- menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen"));\r
-\r
- // List entries\r
- menuList.add(client.getMenuItem('4', "Adressbuch anzeigen"));\r
-\r
- // Address search\r
- menuList.add(client.getMenuItem('5', "Adresse suchen"));\r
-\r
- // Change other address\r
- menuList.add(client.getMenuItem('6', "Adresse ändern"));\r
-\r
- // Delete other address\r
- menuList.add(client.getMenuItem('7', "Adresse löschen"));\r
-\r
- // Always last line: Exit program\r
- menuList.add(client.getMenuItem('0', "Programm verlassen"));\r
- break;\r
-\r
- default: // Not supported\r
- log.error("Menu type '" + menuType + "' ont supported");\r
- System.exit(1);\r
- }\r
-\r
- // Size must have changed to more entries than before\r
- assert(menuList.size() > size);\r
- }\r
-\r
-}\r
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.menu;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.mxchange.addressbook.client.AddressbookClient;
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+import org.mxchange.jcore.client.Client;
+
+/**
+ * Utility class for menu structure
+ * <p>
+ * @author Roland Haeder
+ */
+public class AddressbookMenu extends BaseMenu {
+
+ /**
+ * Copies entries for given type into the menu list
+ * <p>
+ * @param menuList Menu list for later showing
+ * @param menuType Type of menu
+ * @param client Client instance to call back
+ */
+ public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
+ // Some instances must be set
+ if (null == menuList) {
+ // Abort here
+ throw new NullPointerException("menuList is null"); //NOI18N
+ } else if (null == client) {
+ // Abort here
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (!(client instanceof AddressbookClient)) {
+ // Not correct instance
+ throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client));
+ }
+
+ // Cast client to proper interface
+ AddressbookClient c = (AddressbookClient) client;
+
+ // Get list size
+ int size = menuList.size();
+
+ // Depends on type
+ switch (menuType) {
+ case "main": // Main menu //NOI18N
+ // Enter own data
+ menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen"));
+
+ // Change own data
+ menuList.add(c.getMenuItem('2', "Eigene Adresse ändern"));
+
+ // Add new addess
+ menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen"));
+
+ // List entries
+ menuList.add(c.getMenuItem('4', "Adressbuch anzeigen"));
+
+ // Address search
+ menuList.add(c.getMenuItem('5', "Adresse suchen"));
+
+ // Change other address
+ menuList.add(c.getMenuItem('6', "Adresse ändern"));
+
+ // Delete other address
+ menuList.add(c.getMenuItem('7', "Adresse löschen"));
+
+ // Always last line: Exit program
+ menuList.add(c.getMenuItem('0', "Programm verlassen"));
+ break;
+
+ default: // Not supported
+ System.err.println(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
+ System.exit(1);
+ }
+
+ // Size must have changed to more entries than before
+ assert (menuList.size() > size);
+ }
+
+}