2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.menu;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import org.apache.logging.log4j.Logger;
22 import org.mxchange.addressbook.BaseAddressbookSystem;
23 import org.mxchange.addressbook.client.AddressbookClient;
24 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
25 import org.mxchange.jcore.client.Client;
28 * Utility class for menu structure
30 * @author Roland Haeder
32 public class AddressbookMenu extends BaseAddressbookSystem {
35 * Copies entries for given type into the menu list
37 * @param menuList Menu list for later showing
38 * @param menuType Type of menu
39 * @param client Client instance to call back
41 public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
43 Logger log = new AddressbookMenu().getLogger();
46 log.trace(MessageFormat.format("menuList={0},menuType={1},client={2} - CALLED!", menuList, menuType, client)); //NOI18N
48 // Some instances must be set
49 if (menuList == null) {
51 throw new NullPointerException("menuList is null"); //NOI18N
52 } else if (client == null) {
54 throw new NullPointerException("contact is null"); //NOI18N
55 } else if (!(client instanceof AddressbookClient)) {
56 // Not correct instance
57 throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client));
60 // Cast client to proper interface
61 AddressbookClient c = (AddressbookClient) client;
64 int size = menuList.size();
67 log.debug(MessageFormat.format("Adding menu for '{0}' (old size: '{1}') ...", menuType, size)); //NOI18N
71 case "main": // Main menu //NOI18N
73 menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen"));
76 menuList.add(c.getMenuItem('2', "Eigene Adresse ändern"));
79 menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen"));
82 menuList.add(c.getMenuItem('4', "Adressbuch anzeigen"));
85 menuList.add(c.getMenuItem('5', "Adresse suchen"));
87 // Change other address
88 menuList.add(c.getMenuItem('6', "Adresse ändern"));
90 // Delete other address
91 menuList.add(c.getMenuItem('7', "Adresse löschen"));
93 // Always last line: Exit program
94 menuList.add(c.getMenuItem('0', "Programm verlassen"));
97 default: // Not supported
98 log.error(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
102 // Size must have changed to more entries than before
103 assert (menuList.size() > size);