]> git.mxchange.org Git - addressbook-swing.git/blob - src/org/mxchange/addressbook/menu/AddressbookMenu.java
09addc9a6086f5e8f35b98739d665446ab780add
[addressbook-swing.git] / src / org / mxchange / addressbook / menu / AddressbookMenu.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.menu;
18
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;
24
25 /**
26  * Utility class for menu structure
27  * <p>
28  * @author Roland Häder<roland@mxchange.org>
29  */
30 public class AddressbookMenu extends BaseMenu {
31
32         /**
33          * Copies entries for given type into the menu list
34          * <p>
35          * @param menuList Menu list for later showing
36          * @param menuType Type of menu
37          * @param client Client instance to call back
38          */
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) {
42                         // Abort here
43                         throw new NullPointerException("menuList is null"); //NOI18N
44                 } else if (null == client) {
45                         // Abort here
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));
50                 }
51
52                 // Cast client to proper interface
53                 AddressbookClient c = (AddressbookClient) client;
54
55                 // Get list size
56                 int size = menuList.size();
57
58                 // Depends on type
59                 switch (menuType) {
60                         case "main": // Main menu //NOI18N
61                                 // Enter own data
62                                 menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen"));
63
64                                 // Change own data
65                                 menuList.add(c.getMenuItem('2', "Eigene Adresse ändern"));
66
67                                 // Add new addess
68                                 menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen"));
69
70                                 // List entries
71                                 menuList.add(c.getMenuItem('4', "Adressbuch anzeigen"));
72
73                                 // Address search
74                                 menuList.add(c.getMenuItem('5', "Adresse suchen"));
75
76                                 // Change other address
77                                 menuList.add(c.getMenuItem('6', "Adresse ändern"));
78
79                                 // Delete other address
80                                 menuList.add(c.getMenuItem('7', "Adresse löschen"));
81
82                                 // Always last line: Exit program
83                                 menuList.add(c.getMenuItem('0', "Programm verlassen"));
84                                 break;
85
86                         default: // Not supported
87                                 System.err.println(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
88                                 System.exit(1);
89                 }
90
91                 // Size must have changed to more entries than before
92                 assert (menuList.size() > size);
93         }
94
95 }