]> git.mxchange.org Git - addressbook-lib.git/blob - src/org/mxchange/addressbook/menu/AddressbookMenu.java
c939abd348f8a1ebbf993cb3a33977155aecbb27
[addressbook-lib.git] / src / org / mxchange / addressbook / menu / AddressbookMenu.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
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.apache.logging.log4j.Logger;
22 import org.mxchange.addressbook.client.AddressbookClient;
23 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
24 import org.mxchange.jcore.client.Client;
25
26 /**
27  * Utility class for menu structure
28  * <p>
29  * @author Roland Haeder
30  */
31 public class AddressbookMenu extends BaseMenu {
32
33         /**
34          * Copies entries for given type into the menu list
35          * <p>
36          * @param menuList Menu list for later showing
37          * @param menuType Type of menu
38          * @param client Client instance to call back
39          */
40         public static void addItemsToList (final List<SelectableMenuItem> menuList, final String menuType, final Client client) {
41                 // Get logger
42                 Logger log = new AddressbookMenu().getLogger();
43
44                 // Trace call
45                 log.trace(MessageFormat.format("menuList={0},menuType={1},client={2} - CALLED!", menuList, menuType, client)); //NOI18N
46
47                 // Some instances must be set
48                 if (null == menuList) {
49                         // Abort here
50                         throw new NullPointerException("menuList is null"); //NOI18N
51                 } else if (null == client) {
52                         // Abort here
53                         throw new NullPointerException("contact is null"); //NOI18N
54                 } else if (!(client instanceof AddressbookClient)) {
55                         // Not correct instance
56                         throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client));
57                 }
58
59                 // Cast client to proper interface
60                 AddressbookClient c = (AddressbookClient) client;
61
62                 // Get list size
63                 int size = menuList.size();
64
65                 // Debug message
66                 log.debug(MessageFormat.format("Adding menu for '{0}' (old size: '{1}') ...", menuType, size)); //NOI18N
67
68                 // Depends on type
69                 switch (menuType) {
70                         case "main": // Main menu //NOI18N
71                                 // Enter own data
72                                 menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen"));
73
74                                 // Change own data
75                                 menuList.add(c.getMenuItem('2', "Eigene Adresse ändern"));
76
77                                 // Add new addess
78                                 menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen"));
79
80                                 // List entries
81                                 menuList.add(c.getMenuItem('4', "Adressbuch anzeigen"));
82
83                                 // Address search
84                                 menuList.add(c.getMenuItem('5', "Adresse suchen"));
85
86                                 // Change other address
87                                 menuList.add(c.getMenuItem('6', "Adresse ändern"));
88
89                                 // Delete other address
90                                 menuList.add(c.getMenuItem('7', "Adresse löschen"));
91
92                                 // Always last line: Exit program
93                                 menuList.add(c.getMenuItem('0', "Programm verlassen"));
94                                 break;
95
96                         default: // Not supported
97                                 log.error(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N
98                                 System.exit(1);
99                 }
100
101                 // Size must have changed to more entries than before
102                 assert (menuList.size() > size);
103         }
104
105 }