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