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