]> git.mxchange.org Git - addressbook-swing.git/blob - src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java
64f917bd8206ac195598e91d72ee60ca4462da2a
[addressbook-swing.git] / src / org / mxchange / addressbook / menu / item / console / ConsoleMenuItem.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
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.item.console;
18
19 import java.text.MessageFormat;
20 import org.mxchange.addressbook.client.AddressbookClient;
21 import org.mxchange.addressbook.menu.item.BaseMenuItem;
22 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
23 import org.mxchange.jcore.client.Client;
24
25 /**
26  * A menu item class for the console
27  * <p>
28  * @author Roland Häder<roland@mxchange.org>
29  */
30 public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem {
31
32         /**
33          * Access key
34          */
35         private char accessKey;
36
37         /**
38          * Text to user
39          */
40         private String text;
41
42         /**
43          * Constructor for building a console menu with access key and text
44          * <p>
45          * @param accessKey Access key for this menu entry
46          * @param text Text to show to user
47          */
48         public ConsoleMenuItem (final char accessKey, final String text) {
49                 this.setAccessKey(accessKey);
50                 this.setText(text);
51         }
52
53         @Override
54         public char getAccessKey () {
55                 return this.accessKey;
56         }
57
58         /**
59          * Access key
60          * <p>
61          * @param accessKey the accessKey to set
62          */
63         private void setAccessKey (final char accessKey) {
64                 this.accessKey = accessKey;
65         }
66
67         @Override
68         public String getText () {
69                 return this.text;
70         }
71
72         /**
73          * Text to user
74          * <p>
75          * @param text the text to set
76          */
77         private void setText (final String text) {
78                 this.text = text;
79         }
80
81         @Override
82         public void show (final Client client) {
83                 // Trace message
84                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
85
86                 // Client must not be null
87                 if (null == client) {
88                         // Abort here
89                         throw new NullPointerException("client is null");
90                 } else if (!(client instanceof AddressbookClient)) {
91                         // Wrong interface
92                         throw new IllegalArgumentException("client " + client + " must implement AddressbookClient");
93                 }
94
95                 // Cast it
96                 AddressbookClient c = (AddressbookClient) client;
97
98                 // Call-back client over menu
99                 c.showEntry(this);
100
101                 // Trace message
102                 this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
103         }
104
105 }