X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Faddressbook%2Fmenu%2Fitem%2Fconsole%2FConsoleMenuItem.java;h=fd008a9bb0c1864fc595fa1a41bf66db3ce05159;hb=16624bae7209070f842d14159924d85a320c362d;hp=37f9c7cacbdaff13dcf07baa71c313a23b8ecb86;hpb=31fce847a127086ff40fa9b4edde6137a8ef7e3f;p=jaddressbook-lib.git diff --git a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java index 37f9c7ca..fd008a9b 100644 --- a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java +++ b/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java @@ -1,89 +1,114 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.menu.item.console; - -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.item.BaseMenuItem; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - */ -public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem { - /** - * Access key - */ - private char accessKey; - - /** - * Text to user - */ - private String text; - - /** - * Constructor for building a console menu with access key and text - * - * @param accessKey Access key for this menu entry - * @param text Text to show to user - */ - public ConsoleMenuItem (final char accessKey, final String text) { - this.accessKey = accessKey; - this.text = text; - } - - /** - * Access key - * @return the accessKey - */ - @Override - public char getAccessKey () { - return this.accessKey; - } - - /** - * Access key - * @param accessKey the accessKey to set - */ - private void setAccessKey (char accessKey) { - this.accessKey = accessKey; - } - - /** - * Text to user - * @return the text - */ - @Override - public String getText () { - return this.text; - } - - /** - * Text to user - * @param text the text to set - */ - private void setText (String text) { - this.text = text; - } - - @Override - public void show (final Client client) { - // Call-back client over menu - client.showEntry(this); - } - -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.menu.item.console; + +import java.text.MessageFormat; +import org.mxchange.addressbook.client.AddressbookClient; +import org.mxchange.addressbook.menu.item.BaseMenuItem; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; +import org.mxchange.jcore.client.Client; + +/** + * + * @author Roland Haeder + */ +public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem { + + /** + * Access key + */ + private char accessKey; + + /** + * Text to user + */ + private String text; + + /** + * Constructor for building a console menu with access key and text + *

+ * @param accessKey Access key for this menu entry + * @param text Text to show to user + */ + public ConsoleMenuItem (final char accessKey, final String text) { + this.setAccessKey(accessKey); + this.setText(text); + } + + /** + * Access key + *

+ * @return the accessKey + */ + @Override + public final char getAccessKey () { + return this.accessKey; + } + + /** + * Access key + *

+ * @param accessKey the accessKey to set + */ + private void setAccessKey (char accessKey) { + this.accessKey = accessKey; + } + + /** + * Text to user + *

+ * @return the text + */ + @Override + public String getText () { + return this.text; + } + + /** + * Text to user + *

+ * @param text the text to set + */ + private void setText (String text) { + this.text = text; + } + + @Override + public void show (final Client client) { + // Trace message + this.getLogger().logTrace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N + + // Client must not be null + if (null == client) { + // Abort here + throw new NullPointerException("client is null"); + } else if (!(client instanceof AddressbookClient)) { + // Wrong interface + throw new IllegalArgumentException("client " + client + " must implement AddressbookClient"); + } + + // Cast it + AddressbookClient c = (AddressbookClient) client; + + // Call-back client over menu + c.showEntry(this); + + // Trace message + this.getLogger().logTrace("EXIT!"); //NOI18N + } + +}