]> git.mxchange.org Git - addressbook-swing.git/blob - src/org/mxchange/addressbook/menu/BaseMenu.java
Better compare this way:
[addressbook-swing.git] / src / org / mxchange / addressbook / menu / BaseMenu.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.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23 import org.mxchange.addressbook.BaseAddressbookSystem;
24 import org.mxchange.addressbook.client.AddressbookClient;
25 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
26 import org.mxchange.jcore.client.Client;
27
28 /**
29  *
30  * @author Roland Haeder
31  */
32 public class BaseMenu extends BaseAddressbookSystem {
33
34         /**
35          * Menu list
36          */
37         private List<SelectableMenuItem> menuList;
38
39         /**
40          * No instance from this object
41          */
42         protected BaseMenu () {
43         }
44
45         /**
46          * Size of menu items
47          *
48          * @return Count of menu items
49          */
50         public int getMenuItemsCount () {
51                 return this.menuList.size();
52         }
53
54         /**
55          * "Getter" for an iterator of this menu's items
56          *
57          * @return An iterator of all menu items
58          */
59         public Iterator<SelectableMenuItem> getMenuItemsIterator () {
60                 return this.menuList.iterator();
61         }
62
63         /**
64          * Shows this menu
65          *
66          * @param client Client instance to call back
67          */
68         public void show (final Client client) {
69                 // Trace message
70                 this.getLogger().trace(MessageFormat.format("client={0} CALLED!", client)); //NOI18N
71
72                 // Client must not be null
73                 if (null == client) {
74                         // Abort here
75                         throw new NullPointerException("client is null"); //NOI18N
76                 }
77
78                 // Get values
79                 Iterator<SelectableMenuItem> iterator = this.menuList.iterator();
80
81                 // Debug message
82                 this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");
83
84                 // Output all menus
85                 while (iterator.hasNext()) {
86                         // Get item
87                         SelectableMenuItem item = iterator.next();
88
89                         // Show this item
90                         item.show((AddressbookClient) client);
91                 }
92
93                 // Trace message
94                 this.getLogger().trace("EXIT!"); //NOI18N
95         }
96
97         /**
98          * Getter for menu list
99          *
100          * @return      menuList List of menu entries
101          */
102         protected final List<SelectableMenuItem> getMenuList () {
103                 return this.menuList;
104         }
105
106         /**
107          * Initializes menu
108          *
109          * @param menuType      Menu type to initialize
110          * @param client CLient to call back
111          */
112         protected void initMenu (final String menuType, final Client client) {
113                 // Trace message
114                 this.getLogger().trace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N
115
116                 // Init menu list
117                 this.menuList = new ArrayList<>(5);
118
119                 // Trace message
120                 this.getLogger().trace("EXIT!"); //NOI18N
121         }
122 }