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