2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.addressbook.client;
19 import java.text.MessageFormat;
20 import java.util.HashMap;
22 import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
23 import org.mxchange.addressbook.menu.Menu;
24 import org.mxchange.jcore.client.BaseClient;
25 import org.mxchange.jcore.client.Client;
26 import org.mxchange.jcore.manager.database.ManageableDatabase;
29 * A general addressbook client
31 * @author Roland Haeder
33 public abstract class BaseAddressbookClient extends BaseClient {
38 private String currentMenu;
43 private final Map<String, Menu> menus;
46 * No instances can be created of this class
48 protected BaseAddressbookClient () {
50 this.menus = new HashMap<>(10);
56 * @return the currentMenu
58 public final String getCurrentMenu () {
59 return this.currentMenu;
65 * @param currentMenu the currentMenu to set
67 public final void setCurrentMenu (final String currentMenu) {
68 this.currentMenu = currentMenu;
72 * "Getter" for given menu type
74 * @param menuType Menu type instance to return
75 * @return Menu or null if not found
77 public Menu getMenu (final String menuType) {
78 // Default is not found
82 if (this.getMenus().containsKey(menuType)) {
84 menu = this.getMenus().get(menuType);
92 * Fills menu map with swing menus
94 protected abstract void fillMenuMap ();
97 * Getter for menus map
99 * @return Map of all menus
101 protected final Map<String, Menu> getMenus () {
106 * Initializes contact manager
108 protected void initContactManager () {
110 this.getLogger().trace("CALLED!"); //NOI18N
113 this.getLogger().debug("Initializing contact manager ..."); //NOI18N
115 // Init contact manager with console client
116 // @TODO Static initial amount of contacts
117 ManageableDatabase manager = new AddressbookContactManager((Client) this);
120 this.setContactManager(manager);
123 this.getLogger().debug("Contact manager has been initialized."); //NOI18N
126 this.getLogger().trace("EXIT!"); //NOI18N
132 * @param menuType Given menu to show
134 protected void showMenu (final String menuType) {
136 this.getLogger().trace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N
138 Menu menu = this.getMenu(menuType);
141 if (!(menu instanceof Menu)) {
143 // @todo Own exception?
144 throw new NullPointerException(MessageFormat.format("Menu '{0}' not found.", menuType)); //NOI18N
151 this.getLogger().trace("EXIT!"); //NOI18N