]> git.mxchange.org Git - addressbook-swing.git/blob - src/org/mxchange/addressbook/menu/BaseMenu.java
Project relocated (a bit better now?) + continued with Swing client
[addressbook-swing.git] / src / org / mxchange / addressbook / menu / BaseMenu.java
1 /*\r
2  * Copyright (C) 2015 Roland Haeder\r
3  *\r
4  * This program is free software: you can redistribute it and/or modify\r
5  * it under the terms of the GNU General Public License as published by\r
6  * the Free Software Foundation, either version 3 of the License, or\r
7  * (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
16  */\r
17 package org.mxchange.addressbook.menu;\r
18 \r
19 import java.util.ArrayList;\r
20 import java.util.Iterator;\r
21 import java.util.List;\r
22 import org.mxchange.addressbook.BaseFrameworkSystem;\r
23 import org.mxchange.addressbook.client.Client;\r
24 import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
25 \r
26 /**\r
27  *\r
28  * @author Roland Haeder\r
29  */\r
30 public class BaseMenu extends BaseFrameworkSystem {\r
31     /**\r
32      * Menu list\r
33      */\r
34     private List<SelectableMenuItem> menuList;\r
35 \r
36     /**\r
37      * No instance from this object\r
38      */\r
39     protected BaseMenu () {\r
40         super();\r
41     }\r
42 \r
43     /**\r
44      * Size of menu items\r
45      * @return Count of menu items\r
46      */\r
47     public int getMenuItemsCount () {\r
48         return this.menuList.size();\r
49     }\r
50 \r
51     /**\r
52      * "Getter" for an iterator of this menu's items\r
53      *\r
54      * @return An iterator of all menu items\r
55      */\r
56     public Iterator<SelectableMenuItem> getMenuItemsIterator () {\r
57         return this.menuList.iterator();\r
58     }\r
59 \r
60     /**\r
61      * Shows this menu\r
62      * \r
63      * @param client Client instance to call back\r
64      */\r
65     public void show (final Client client) {\r
66         // Get values\r
67         Iterator<SelectableMenuItem> iterator = this.menuList.iterator();\r
68 \r
69         // Debug message\r
70         this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries.");\r
71 \r
72         // Output all menus\r
73         while (iterator.hasNext()) {\r
74             // Get item\r
75             SelectableMenuItem item = iterator.next();\r
76 \r
77             // Show this item\r
78             item.show(client);\r
79         }\r
80     }\r
81 \r
82     /**\r
83      * Getter for menu list\r
84      *\r
85      * @return  menuList List of menu entries\r
86      */\r
87     protected final List<SelectableMenuItem> getMenuList () {\r
88         return this.menuList;\r
89     }\r
90 \r
91     /**\r
92      * Initializes menu\r
93      * @param menuType  Menu type to initialize\r
94      * @param client CLient to call back\r
95      */\r
96     protected void initMenu (final String menuType, final Client client) {\r
97         // Init menu list\r
98         this.menuList = new ArrayList<>(5);\r
99     }\r
100 }\r