2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.mxchange.addressbook.client.AddressbookClient;
22 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
23 import org.mxchange.jcore.client.Client;
26 * Utility class for menu structure
28 * @author Roland Häder<roland@mxchange.org>
30 public class AddressbookMenu extends BaseMenu {
33 * Copies entries for given type into the menu list
35 * @param menuList Menu list for later showing
36 * @param menuType Type of menu
37 * @param client Client instance to call back
39 public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
40 // Some instances must be set
41 if (null == menuList) {
43 throw new NullPointerException("menuList is null"); //NOI18N
44 } else if (null == client) {
46 throw new NullPointerException("contact is null"); //NOI18N
47 } else if (!(client instanceof AddressbookClient)) {
48 // Not correct instance
49 throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client));
52 // Cast client to proper interface
53 AddressbookClient c = (AddressbookClient) client;
56 int size = menuList.size();
60 case "main": // Main menu //NOI18N
62 menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen"));
65 menuList.add(c.getMenuItem('2', "Eigene Adresse ändern"));
68 menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen"));
71 menuList.add(c.getMenuItem('4', "Adressbuch anzeigen"));
74 menuList.add(c.getMenuItem('5', "Adresse suchen"));
76 // Change other address
77 menuList.add(c.getMenuItem('6', "Adresse ändern"));
79 // Delete other address
80 menuList.add(c.getMenuItem('7', "Adresse löschen"));
82 // Always last line: Exit program
83 menuList.add(c.getMenuItem('0', "Programm verlassen"));
86 default: // Not supported
87 System.err.println(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
91 // Size must have changed to more entries than before
92 assert (menuList.size() > size);