2 * Copyright (C) 2015 Roland Haeder
\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
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
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
17 package org.mxchange.addressbook.menu;
\r
19 import java.util.Iterator;
\r
20 import java.util.Map;
\r
21 import org.apache.logging.log4j.Logger;
\r
22 import org.mxchange.addressbook.BaseFrameworkSystem;
\r
23 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
\r
27 * @author Roland Haeder
\r
29 public class MenuTools extends BaseFrameworkSystem {
\r
32 * Gets an array with all available access keys back from given menu map.
\r
33 * This can later be handle to the client's enterChar() method.
\r
35 * @param menus A Map with all menus and their entries
\r
36 * @param menuType Menu type
\r
37 * @return An array with available access chars
\r
39 public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {
\r
41 Logger logger = new MenuTools().getLogger();
\r
43 // First search for the proper menu class
\r
44 Menu menu = menus.get(menuType);
\r
47 if (!(menu instanceof Menu)) {
\r
49 // @todo Rewrite to exception
\r
50 logger.error("Menu '" + menuType + "' not found.");
\r
55 Iterator<SelectableMenuItem> iterator = menu.getMenuItemsIterator();
\r
57 // Init return array and counter 'i'
\r
58 char[] accessKeys = new char[menu.getMenuItemsCount()];
\r
61 // Now "walk" through all menu entries
\r
62 while (iterator.hasNext()) {
\r
64 SelectableMenuItem item = iterator.next();
\r
65 //* NOISY-DEBUG: */ logger.debug("item=" + item);
\r
67 // Get access key from item and add it to the array
\r
68 accessKeys[i] = item.getAccessKey();
\r
69 //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]);
\r
71 // Increment counter
\r
75 // Return finished array
\r