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.BaseFrameworkSystem;
23 import org.mxchange.addressbook.client.Client;
24 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
27 * Utility class for menu structure
29 * @author Roland Haeder
31 public class AddressbookMenu extends BaseFrameworkSystem {
34 * Copies entries for given type into the menu list
36 * @param menuList Menu list for later showing
37 * @param menuType Type of menu
38 * @param client Client instance to call back
40 public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
42 Logger log = new AddressbookMenu().getLogger();
45 log.trace(MessageFormat.format("menuList={0},menuType={1},client={2} - CALLED!", menuList, menuType, client)); //NOI18N
47 // Some instances must be set
48 if (menuList == null) {
50 throw new NullPointerException("menuList is null"); //NOI18N
51 } else if (client == null) {
53 throw new NullPointerException("contact is null"); //NOI18N
57 int size = menuList.size();
60 log.debug(MessageFormat.format("Adding menu for '{0}' (old size: '{1}') ...", menuType, size)); //NOI18N
64 case "main": // Main menu //NOI18N
66 menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen"));
69 menuList.add(client.getMenuItem('2', "Eigene Adresse ändern"));
72 menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen"));
75 menuList.add(client.getMenuItem('4', "Adressbuch anzeigen"));
78 menuList.add(client.getMenuItem('5', "Adresse suchen"));
80 // Change other address
81 menuList.add(client.getMenuItem('6', "Adresse ändern"));
83 // Delete other address
84 menuList.add(client.getMenuItem('7', "Adresse löschen"));
86 // Always last line: Exit program
87 menuList.add(client.getMenuItem('0', "Programm verlassen"));
90 default: // Not supported
91 log.error(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
95 // Size must have changed to more entries than before
96 assert (menuList.size() > size);