From 4019a53fac53269d0a64eea7608dd2fbd23e80ee Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 13 Apr 2017 14:58:21 +0200 Subject: [PATCH] Cleared project: - no more old addressbook classes - re-added jcore-logger-lib - added jfinancials-core - removed addressbook-core (inherited project) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- lib/jcore-logger-lib.jar | Bin 0 -> 2535 bytes ...ressbook-core.jar => jfinancials-core.jar} | Bin 17751 -> 17746 bytes nbproject/project.properties | 2 +- .../addressbook/BaseAddressbookSystem.java | 85 -- .../application/AddressbookApplication.java | 392 ------- .../addressbook/client/AddressbookClient.java | 180 --- .../client/BaseAddressbookClient.java | 209 ---- .../client/console/ConsoleClient.java | 663 ----------- .../client/gui/AddressbookFrame.java | 1023 ----------------- .../addressbook/client/gui/SwingClient.java | 240 ---- .../contact/AddressbookContactFacade.java | 640 ----------- .../facade/contact/ContactFacade.java | 251 ---- .../addressbook/menu/AddressbookMenu.java | 95 -- .../mxchange/addressbook/menu/BaseMenu.java | 111 -- src/org/mxchange/addressbook/menu/Menu.java | 50 - .../mxchange/addressbook/menu/MenuTools.java | 78 -- .../addressbook/menu/console/ConsoleMenu.java | 54 - .../addressbook/menu/item/BaseMenuItem.java | 28 - .../menu/item/SelectableMenuItem.java | 49 - .../menu/item/console/ConsoleMenuItem.java | 105 -- .../localization/bundle_de_DE.properties | 57 +- .../localization/bundle_en_US.properties | 57 +- 22 files changed, 5 insertions(+), 4364 deletions(-) create mode 100644 lib/jcore-logger-lib.jar rename lib/{addressbook-core.jar => jfinancials-core.jar} (56%) delete mode 100644 src/org/mxchange/addressbook/BaseAddressbookSystem.java delete mode 100644 src/org/mxchange/addressbook/application/AddressbookApplication.java delete mode 100644 src/org/mxchange/addressbook/client/AddressbookClient.java delete mode 100644 src/org/mxchange/addressbook/client/BaseAddressbookClient.java delete mode 100644 src/org/mxchange/addressbook/client/console/ConsoleClient.java delete mode 100644 src/org/mxchange/addressbook/client/gui/AddressbookFrame.java delete mode 100644 src/org/mxchange/addressbook/client/gui/SwingClient.java delete mode 100644 src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java delete mode 100644 src/org/mxchange/addressbook/facade/contact/ContactFacade.java delete mode 100644 src/org/mxchange/addressbook/menu/AddressbookMenu.java delete mode 100644 src/org/mxchange/addressbook/menu/BaseMenu.java delete mode 100644 src/org/mxchange/addressbook/menu/Menu.java delete mode 100644 src/org/mxchange/addressbook/menu/MenuTools.java delete mode 100644 src/org/mxchange/addressbook/menu/console/ConsoleMenu.java delete mode 100644 src/org/mxchange/addressbook/menu/item/BaseMenuItem.java delete mode 100644 src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java delete mode 100644 src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java diff --git a/lib/jcore-logger-lib.jar b/lib/jcore-logger-lib.jar new file mode 100644 index 0000000000000000000000000000000000000000..c32f27e47f7cbbdc3d93efb9edc92f9a4e9dbe83 GIT binary patch literal 2535 zcmbtV-EI>{6h50calFZr1dK#Qs~RLIKeCqyBuG)En#2|cJ8>NoK)tBO%f#7evlETi zY0^6$pm%))`V6gl(QA~OUbh#OcmOW?0;u2F-T1H0lBgri&zU(tGiSbYPW|a*$|Ra0 z`gQWhCp6G9l%iUxS;(BusXMOnzsxNa?pS8gAJ{4G31?g8u!qCt!hOqJ(NYBRRsPW-^FJuu`EGeB|DcPZ zwRA6km&e?VbuAoE=2n#6Q(6R2e$z57vwz3Y=cI5)rQ7z&99GP+d*EyfzbzA3FORbB zI7&+?J=JbYogjE6S+FIA-$@Yv;xyu(a)g(lq;PsAW8ZUo?XP!#8${gipIKK`wF{0X zI-R2rzx@vByL2&4=hJi{O<9A?4b|0-EW4gGXoh)r#J(`-lSbDM++DfpcHEXHi@vXd z@Yg#AU8*wAf$jP`(h2Nuy25j}T&W)#lnak+58r8vo{Zg)frL8cgJo)8cwHE~{t?!? z@?7T-0_n!HwPvMOGU&7MB2A&&G63h*@#iH^?!tWYa8H718iDh8eH9leS4vgPnR>BN z#Ac~sP^$T|4ns=}+#W24u@*rl`t$g^;5LI6*eTJ=*IVougFf$X4LGCk%j*UiG=V;e ze<7?mW+rHgrZE?=o5nnY^Nb{uW@(O>-%?7FMdx^!=V5_|#o;hpzpUQQPY`imfs!-7 z2T}D1u~B7cC%|V09$1yFF5Z9f#(?)X0`2gtYBI3w^X#*M9u=zOl&?E+Q*GX0H3Xf`J?~RkAr_P zy!(MIcUpGn9YE@<|K;AX(8-3-ah1IxwTt-rfn78`h!-mbxB@E_&Oi+2G}jf(nRq|L zNCIufv>DU0F+Cg8b1^*^(^gDdOaqbU!f~D!Fi!)7i(H(HiR|Rbl?PhEW9*3z)VU<%979oK<9}coRiVDk(MrX2C~7S650*p!nPiOXQq)-V zQzYmi(c#RIr0B}Ap3r5_k`*0St&^X`bt`Ioub)n%?zoDbtd#3mU+JHxSBm(Hs`Rk# z(Yki5{mtuZNLvYx9G`-tG&Snv(M;Gk@&ZUXvyuPi#ro4J4idzeNf{*aw;}Z}`0!_5 literal 0 HcmV?d00001 diff --git a/lib/addressbook-core.jar b/lib/jfinancials-core.jar similarity index 56% rename from lib/addressbook-core.jar rename to lib/jfinancials-core.jar index 36c8f87e76366fe7597f8c5dc14348a9ec148b72..c7773edc2a81dbdebecf87f08f92fed6ce6d0b32 100644 GIT binary patch delta 545 zcmccK#dxWUkte{LnT3mifrEiTsbV6JCX-^tMDs;VG8GeVD}czqnm}^02BW-0R$69W zVqS7)VotF>LK9Fjo>9IYSu!QDBrz$mI2A=zuh))M4IL4V3=AOb#K6FiUzDz&TalcR zn3tZak5#`D&=5Dcr7loool+C?^pbNDi;GYF+qDm9kTH|W=6{UpEJk)dq?)-og6%v9 zzdWi%lg;_9xse<+xt8AnnZNl2zlxxt4as)NDcUMADOF64b+!bC^5hxL4xpgDmwrr KgSRsd39*CBLf2nJ2NmaSNXK1T@4EVe96HjLs~^_CBO*3}ZXbA)tU}++-7eYi=ZaCs*-1AoDjL?%s-N2w?WD;S9!~;-Omy50uvNTeV gBCA6S)X6Vh. - */ -package org.mxchange.addressbook; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcore.BaseFrameworkSystem; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; - -/** - * A general addressbook class - *

- * @author Roland Häder - */ -public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Protected constructor - */ - protected BaseAddressbookSystem () { - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup loggerBeanLocal - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw - throw new RuntimeException(ex); - } - } - - /** - * Log exception and abort program. - *

- * @param throwable Throwable - */ - protected void abortProgramWithException (final Throwable throwable) { - // Log exception - this.logException(throwable); - - // Abort here - System.exit(1); - } - - /** - * Getter for loggerBeanLocal instance - *

- * @return Logger instance - */ - protected LoggerBeanLocal getLoggerBeanLocal () { - return this.loggerBeanLocal; - } - - /** - * Logs given exception - *

- * @param exception Throwable - */ - protected void logException (final Throwable exception) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } -} diff --git a/src/org/mxchange/addressbook/application/AddressbookApplication.java b/src/org/mxchange/addressbook/application/AddressbookApplication.java deleted file mode 100644 index 9eb8d37..0000000 --- a/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.application; - -import java.io.IOException; -import java.sql.SQLException; -import java.text.MessageFormat; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.addressbook.client.AddressbookClient; -import org.mxchange.addressbook.client.console.ConsoleClient; -import org.mxchange.addressbook.client.gui.SwingClient; -import org.mxchange.jcore.application.Application; -import org.mxchange.jcore.application.BaseApplication; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.exceptions.MenuInitializationException; -import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; -import org.mxchange.jcore.manager.application.ApplicationManager; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; - -/** - * Address book application class. Please see ROADMAP.txt for details. - *

- * @author Roland Häder - * @version 0.0 - */ -public class AddressbookApplication extends BaseApplication implements Application { - - /** - * Application title - */ - public static final String APP_TITLE = "Adressbuch"; //NOI18N - - /** - * Application version - */ - public static final String APP_VERSION = "0.0"; //NOI18N - - /** - * Main method (entry point) - *

- * @param args the command line arguments - */ - public static void main (String[] args) { - // Start application - new AddressbookApplication().start(args); - } - - /** - * Getter for printable application name - *

- * @return A printable name - */ - public static String printableTitle () { - return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N - } - - /** - * Console client is enabled by default - */ - private boolean consoleClient = true; - - /** - * GUI client is disabled by default - */ - private boolean guiClient = false; - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Protected constructor - */ - protected AddressbookApplication () { - // Try this - try { - // Get context - Context context = new InitialContext(); - - // Get loggerBeanLocal - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - } catch (final NamingException ex) { - // Output it and exit - System.err.println(MessageFormat.format("Cannot initialize: {0}", ex)); //NOI18N - - // Abort here - System.exit(1); - } - - // Call init method - this.init(); - } - - @Override - public void doBootstrap () { - this.getLoggerBeanLocal().logDebug("Initializing application ..."); //NOI18N - - // Init client variable - Client client = null; - - // Is console or Swing choosen? - if (this.isConsole()) { - // Debug message - this.getLoggerBeanLocal().logDebug("Initializing console client ..."); //NOI18N - - // Init console client instance - client = new ConsoleClient(this); - } else if (this.isGui()) { - // Debug message - this.getLoggerBeanLocal().logDebug("Initializing GUI (Swing) client ..."); //NOI18N - - // Init console instance - client = new SwingClient(this); - } else { - // Not client choosen - this.getLoggerBeanLocal().logError("No client choosen. Cannot launch."); //NOI18N - - try { - this.doShutdown(); - } catch (final SQLException | IOException ex) { - // Abort here - this.abortProgramWithException(ex); - } - - // Bye ... - System.exit(1); - } - - // Init client - client.init(); - - // Set client instance - this.setClient(client); - - // The application is running at this point - this.getClient().enableIsRunning(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doMainLoop () throws MenuInitializationException { - // Get client and cast it - AddressbookClient client = (AddressbookClient) this.getClient(); - - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // TODO The application should be running now - // Output introduction - this.showIntro(); - - // Set current menu to main - client.setCurrentMenu("main"); //NOI18N - - // --- Main loop starts here --- - while (this.getClient().isRunning()) { - // The application is still active, show menu selection - client.showCurrentMenu(); - - try { - // Ask for user input and run proper method - client.doUserMenuChoice(); - } catch (final UnhandledUserChoiceException ex) { - // Log exception - this.getLoggerBeanLocal().logException(ex); - } - - try { - // Sleep a little to reduce system load - Thread.sleep(100); - } catch (final InterruptedException ex) { - // Ignore it - } - } - // --- Main loop ends here --- - - // Debug message - this.getLoggerBeanLocal().logDebug("Main loop exit - shutting down ..."); //NOI18N - } - - /** - * Shuts down the application. - */ - @Override - public void doShutdown () throws SQLException, IOException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Shutdown client - this.getClient().doShutdown(); - - // Regular exit reached - this.getLoggerBeanLocal().logInfo("End of program (last line)"); //NOI18N - System.exit(0); - } - - /** - * Enables console client by setting propper flag - */ - private void enableConsoleClient () { - this.getLoggerBeanLocal().logDebug("Enabling console client (may become optional client) ..."); //NOI18N - this.consoleClient = true; - this.guiClient = false; - } - - /** - * Enables GUI client by setting propper flag - */ - private void enableGuiClient () { - this.getLoggerBeanLocal().logDebug("Enabling GUI client (may become new default client) ..."); //NOI18N - this.consoleClient = false; - this.guiClient = true; - } - - /** - * Initializes this application - */ - private void init () { - // Try this - try { - // Init properties file - this.initProperties(); - } catch (final IOException ex) { - // Abort here - this.abortProgramWithException(ex); - } - - // Is the bundle initialized? - if (!isBundledInitialized()) { - // Temporary initialize default bundle - // TODO The enum Gender uses this - this.initBundle(); - } - } - - /** - * Initializes properties - */ - private void initProperties () throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * Checks whether the client shoule be console client should be launched by - * checking if -console is set. - *

- * @return Whether console client should be taken - */ - private boolean isConsole () { - return this.consoleClient; - } - - /** - * Checks whether the client shoule be GUI client should be launched by - * checking if -gui is set. - *

- * @return Whether GUI client should be taken - */ - private boolean isGui () { - return this.guiClient; - } - - /** - * Parses all given arguments - *

- * @param args Arguments from program launch - */ - private void parseArguments (final String[] args) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N - for (final String arg : args) { - // Switch on it - switch (arg) { - case "-console": - //NOI18N - this.enableConsoleClient(); - break; - case "-gui": - //NOI18N - this.enableGuiClient(); - break; - } - } - } - - /** - * Show introduction which depends on client - */ - private void showIntro () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Let the client show it - this.getClient().showWelcome(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Launches the application - *

- * @param args Arguments handled to program - */ - private void start (final String args[]) { - this.getLoggerBeanLocal().logInfo("Program is started."); //NOI18N - - try { - // Init properties file - this.initProperties(); - } catch (final IOException ex) { - // Something bad happened - this.abortProgramWithException(ex); - } - - // Parse arguments - this.parseArguments(args); - - try { - // Launch application - ApplicationManager.getSingeltonManager(this).start(); - } catch (final MenuInitializationException ex) { - // Something bad happened - this.abortProgramWithException(ex); - } - - // Good bye, but this should not be reached ... - this.getLoggerBeanLocal().logWarning("Unusual exit reached."); //NOI18N - - try { - this.doShutdown(); - } catch (final SQLException | IOException ex) { - // Something bad happened - this.abortProgramWithException(ex); - } - } - - /** - * Log exception and abort program. - *

- * @param throwable Throwable - */ - protected void abortProgramWithException (final Throwable throwable) { - // Log exception - this.logException(throwable); - - // Abort here - System.exit(1); - } - - /** - * Getter for loggerBeanLocal instance - *

- * @return Logger instance - */ - protected LoggerBeanLocal getLoggerBeanLocal () { - return this.loggerBeanLocal; - } - - /** - * Logs given exception - *

- * @param exception Throwable - */ - protected void logException (final Throwable exception) { - this.getLoggerBeanLocal().logException(exception); - } - -} diff --git a/src/org/mxchange/addressbook/client/AddressbookClient.java b/src/org/mxchange/addressbook/client/AddressbookClient.java deleted file mode 100644 index c43d1c2..0000000 --- a/src/org/mxchange/addressbook/client/AddressbookClient.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.client; - -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.exceptions.MenuInitializationException; -import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; - -/** - * A special client interface for addressbook applications. - *

- * @author Roland Häder - */ -public interface AddressbookClient extends Client { - - /** - * Displays a "box" for the address - *

- * @param contact Contact to show address from - */ - void displayAddressBox (final Contact contact); - - /** - * Displays a "box" for the name - *

- * @param contact Contact to show name from - */ - void displayNameBox (final Contact contact); - - /** - * Displays a "box" for other data - *

- * @param contact Contact to show other data from - */ - void displayOtherDataBox (final Contact contact); - - /** - * Shows given contact instamce - *

- * @param contact Contact instance - */ - void show (final Contact contact); - - /** - * The user changes own address data - *

- * @param contact Contact instance to change - */ - void doChangeOwnAddressData (final Contact contact); - - /** - * The user changes own name data - *

- * @param contact - */ - void doChangeOwnNameData (final Contact contact); - - /** - * The user changes own other data - *

- * @param contact Constact instance to change - */ - void doChangeOwnOtherData (final Contact contact); - - /** - * Allows the user to enter own data - *

- * @return Finished Contact instance - */ - Contact doEnterOwnData (); - - /** - * Asks the user for a choice and proceeds accordingly - *

- * @throws UnhandledUserChoiceException If choice is not supported - * @throws org.mxchange.jcore.exceptions.MenuInitializationException If the - * menu cannot be initialized - */ - void doUserMenuChoice () throws UnhandledUserChoiceException, MenuInitializationException; - - /** - * Asks the the user to enter a single character which must match validChars - *

- * @param validChars Valid chars that are accepted - * @param message Message to user - *

- * @return Allowed character - */ - char enterChar (final char[] validChars, final String message); - - /** - * Asks the user to enter his/her gender (M=Male, F=Female, C=Company) - *

- * @param message Message to output - *

- * @return Gender enum - */ - Gender enterGender (final String message); - - /** - * Reads an integer (int) from the user - *

- * @param minimum Minimum allowed number - * @param maximum Maximum allowed number - * @param message Message to user - *

- * @return Entered string by user or null if empty string is allowed - */ - int enterInt (final int minimum, final int maximum, final String message); - - /** - * Reads a string of minimum and maximum length from the user. An empty - * string should be generally not allowed, but might be okay for e.g. - * company name. - *

- * @param minLength Minimum length of the string to read - * @param maxLength Maximum length of the string to read - * @param message Message to user - * @param allowEmpty Whether empty strings are allowed - *

- * @return Entered string by user or null if empty string is allowed - */ - String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty); - - /** - * Setter for current menu choice - *

- * @param currentMenu Current menu choice - */ - void setCurrentMenu (final String currentMenu); - - /** - * Some "Getter" for menu item - *

- * @param accessKey Key to press to access this menu - * @param text Text to show to user - *

- * @return - */ - SelectableMenuItem getMenuItem (final char accessKey, final String text); - - /** - * Shows current menu selection to the user - */ - void showCurrentMenu (); - - /** - * Shows given menu entry in client - *

- * @param item Menu item to show - */ - void showEntry (final SelectableMenuItem item); - - /** - * Let the user choose what to change on the address: [n]ame, [a]ddress, - * [o]ther - *

- * @param contact Contact instance to let the user change data - *

- * @throws UnhandledUserChoiceException If choice is not supported - */ - void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException; -} diff --git a/src/org/mxchange/addressbook/client/BaseAddressbookClient.java b/src/org/mxchange/addressbook/client/BaseAddressbookClient.java deleted file mode 100644 index b3a55df..0000000 --- a/src/org/mxchange/addressbook/client/BaseAddressbookClient.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.client; - -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.addressbook.facade.contact.AddressbookContactFacade; -import org.mxchange.addressbook.facade.contact.ContactFacade; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.jcore.client.BaseClient; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; - -/** - * A general addressbook client - *

- * @author Roland Häder TODO: Find better name - */ -public abstract class BaseAddressbookClient extends BaseClient implements AddressbookClient { - - /** - * Current menu choice - */ - private String currentMenu; - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Menu system - */ - private final Map menus; - - /** - * No instances can be created of this class - */ - protected BaseAddressbookClient () { - // Init menu map - this.menus = new HashMap<>(10); - - // Try it - try { - // Get context - Context context = new InitialContext(); - - // Lookup loggerBeanLocal - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw - throw new RuntimeException(ex); - } - } - - /** - * Current menu choice - *

- * @return the currentMenu - */ - public String getCurrentMenu () { - return this.currentMenu; - } - - @Override - public void setCurrentMenu (final String currentMenu) { - this.currentMenu = currentMenu; - } - - /** - * "Getter" for given menu type - *

- * @param menuType Menu type instance to return - *

- * @return Menu or null if not found - */ - private Menu getMenu (final String menuType) { - // Default is not found - Menu menu = null; - - // Check array - if (this.getMenus().containsKey(menuType)) { - // Found! - menu = this.getMenus().get(menuType); - } - - // Return it - return menu; - } - - /** - * Logs exception and exits program - *

- * @param throwable Throwable - */ - protected void abortProgramWithException (final Throwable throwable) { - // Log exception - this.logException(throwable); - - // Abort here - System.exit(1); - } - - /** - * Fills menu map with swing menus - */ - protected abstract void fillMenuMap (); - - /** - * Getter for loggerBeanLocal instance - *

- * @return Logger instance - */ - protected LoggerBeanLocal getLoggerBeanLocal () { - return this.loggerBeanLocal; - } - - /** - * Getter for menus map - *

- * @return Map of all menus - */ - protected Map getMenus () { - return Collections.unmodifiableMap(this.menus); - } - - /** - * Initializes contact manager - *

- * @throws java.sql.SQLException If any SQL error occurs - */ - protected void initContactManager () throws SQLException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug("Initializing contact manager ..."); //NOI18N - - // Init contact facade with console client - // TODO Static initial amount of contacts - ContactFacade facade = new AddressbookContactFacade(this); - - // Set it here - this.setFacade(facade); - - // Debug message - this.getLoggerBeanLocal().logDebug("Contact manager has been initialized."); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Logs an exception - *

- * @param throwable Throwable - */ - protected void logException (final Throwable throwable) { - // Deligate to loggerBeanLocal - this.getLoggerBeanLocal().logException(throwable); - } - - /** - * Shows given menu - *

- * @param menuType Given menu to show - */ - protected void showMenu (final String menuType) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N - - // Get menu from type - Menu menu = this.getMenu(menuType); - - // Is the menu set? - if (!(menu instanceof Menu)) { - // Not found - // TODO Own exception? - throw new NullPointerException(MessageFormat.format("Menu '{0}' not found.", menuType)); //NOI18N - } - - // Show menu - menu.show(this); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } -} diff --git a/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/src/org/mxchange/addressbook/client/console/ConsoleClient.java deleted file mode 100644 index 6bccf45..0000000 --- a/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ /dev/null @@ -1,663 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.client.console; - -import java.io.IOException; -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Scanner; -import org.mxchange.addressbook.application.AddressbookApplication; -import org.mxchange.addressbook.client.AddressbookClient; -import org.mxchange.addressbook.client.BaseAddressbookClient; -import org.mxchange.addressbook.facade.contact.ContactFacade; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.addressbook.menu.MenuTools; -import org.mxchange.addressbook.menu.console.ConsoleMenu; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.contact.gender.GenderUtils; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcore.application.Application; -import org.mxchange.jcore.exceptions.MenuInitializationException; -import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; - -/** - * A client for the console - *

- * @author Roland Häder - */ -public class ConsoleClient extends BaseAddressbookClient implements AddressbookClient { - - /** - * Scanner instance for reading data from console input - */ - private final Scanner scanner; - - /** - * Parameterless constructor - *

- * @param application An instance of an Application class - */ - public ConsoleClient (final Application application) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("application={0} - CALLED!", application)); //NOI18N - - // Set application instance - this.setApplication(application); - - // Init scanner instance - this.scanner = new Scanner(System.in, "UTF-8"); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void displayAddressBox (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Simple display ... - this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getContactStreet(), contact.getContactZipCode(), contact.getContactCity(), contact.getContactCountry())); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void displayNameBox (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Get translated gender as the user may want to see "Mr.", "Mrs." - String gender = GenderUtils.getTranslatedGender(contact); - - // Now put all together: gender, surname, family name - this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getContactFirstName(), contact.getContactFamilyName())); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void displayOtherDataBox (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Mobile and such ... - this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getContactLandLineNumber(), contact.getContactFaxNumber(), contact.getContactMobileNumber(), contact.getContactComment())); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeOwnAddressData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); //NOI18N - } - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // Own street and number - String streetNumber = manager.enterOwnStreet(); - - // Get zip code - Integer zipCode = manager.enterOwnZipCode(); - - // Get city name - String city = manager.enterOwnCity(); - - // Get country code - Country country = manager.enterOwnCountryCode(); - - // Update address data - contact.setContactStreet(streetNumber); - contact.setContactZipCode(zipCode); - contact.setContactCity(city); - contact.setContactCountry(country); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeOwnNameData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); //NOI18N - } - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // Gender: - Gender gender = manager.enterOwnGender(); - - // Surname - String firstName = manager.enterOwnFirstName(); - - // Family name - String familyName = manager.enterOwnFamilyName(); - - // Update contact instance - contact.setContactGender(gender); - contact.setContactFirstName(firstName); - contact.setContactFamilyName(familyName); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeOwnOtherData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Is it null? - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); //NOI18N - } - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // Phone number - DialableLandLineNumber phoneNumber = manager.enterOwnPhoneNumber(); - - // Phone number - DialableMobileNumber mobileNumber = manager.enterOwnCellNumber(); - - // Fax number - DialableFaxNumber faxNumber = manager.enterOwnFaxNumber(); - - // Email address - String email = manager.enterOwnEmailAddress(); - - // Comment - String comment = manager.enterOwnComment(); - - // Update contact instance - contact.setContactLandLineNumber(phoneNumber); - contact.setContactMobileNumber(mobileNumber); - contact.setContactFaxNumber(faxNumber); - contact.setContactEmailAddress(email); - contact.setContactComment(comment); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public Contact doEnterOwnData () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // First ask for gender - Gender gender = manager.enterOwnGender(); - - // 2nd for first name - String firstName = manager.enterOwnFirstName(); - - // And 3rd for family name - String familyName = manager.enterOwnFamilyName(); - - // Construct UserContact instance - Contact contact = new UserContact(gender, firstName, familyName); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N - - // And return object - return contact; - } - - @Override - public void doShutdown () throws SQLException, IOException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Parent call - super.doShutdown(); - - // TODO Add other shutdown stuff - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doUserMenuChoice () throws UnhandledUserChoiceException, MenuInitializationException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get all access keys from menu - char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu()); - - // Output textural message and ask for a char as input - char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // TODO Rewrite this ugly switch() block - switch (choice) { - case '1': - try { - // Enter/add own data - manager.doEnterOwnData(); - } catch (final ContactAlreadyAddedException ex) { - // Already added - this.outputMessage("Sie haben bereits Ihre eigenen Daten eingegeben."); - } - break; - - case '2': // Change own data - manager.doChangeOwnData(); - break; - - case '3': // Add new addess - manager.doAddOtherAddress(); - break; - - case '4': // List contacts - manager.doListContacts(); - break; - - case '5': // Search addresses - manager.doSearchContacts(); - break; - - case '6': // Change other addess - manager.doChangeOtherAddress(); - break; - - case '7': // Delete other address - manager.doDeleteOtherAddress(); - break; - - case '0': - try { - // Program exit - this.getApplication().doShutdown(); - } catch (final SQLException | IOException ex) { - this.abortProgramWithException(ex); - } - break; - - default: - // TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - @SuppressWarnings ("UseOfSystemOutOrSystemErr") - public char enterChar (final char[] validChars, final String message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("validChars={0},message={1} - CALLED!", Arrays.toString(validChars), message)); //NOI18N - - // The validChars must not null be null and filled with at least one char - if (null == validChars) { - // Is null - throw new NullPointerException("validChars is null"); //NOI18N - } else if (validChars.length == 0) { - // Is not filled - throw new IllegalArgumentException("validChars is not filled."); //NOI18N - } - - char input = 0; - - // Sort array, else binarySearch() won't work - Arrays.sort(validChars); - - // Keep asking until valid char has been entered - while (Arrays.binarySearch(validChars, input) < 0) { - // Output message - System.out.print(message); - - // Read char - input = this.readChar(); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N - - // Return read char - return input; - } - - @Override - public Gender enterGender (final String message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("message={0} - CALLED!", message)); //NOI18N - - // Get valid chars - char[] validChars = Gender.validChars(); - - // Debug message - //* NOISY-DEBUG: */ System.out.println(validChars); - // Call inner method - char gender = this.enterChar(validChars, message); - - // Now get a Gender instance back - Gender g = Gender.fromChar(gender); - - // g must not be null - assert (g instanceof Gender) : "g is not set."; //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("g={0} - EXIT!", g)); //NOI18N - - // Return it - return g; - } - - @Override - @SuppressWarnings ("UseOfSystemOutOrSystemErr") - public int enterInt (final int minimum, final int maximum, final String message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("minimum={0},maximum={1},message={2} - CALLED!", minimum, maximum, message)); //NOI18N - - // Minimum should not be below zero - assert (minimum >= 0) : MessageFormat.format("minimum={0} is below zero", minimum); //NOI18N - assert (maximum > minimum) : MessageFormat.format("maximum {0} is smaller than minimum {1}", maximum, minimum); //NOI18N - - // Init input - int input = -1; - - while ((input < minimum) || (input > maximum)) { - // Output message - System.out.print(message); - - // Read integer from user - input = this.readInt(); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N - - // Return it - return input; - } - - @Override - @SuppressWarnings ("UseOfSystemOutOrSystemErr") - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("minLength={0},maxLength={1},message={2}allowEmpty={3} - CALLED!", minLength, maxLength, message, allowEmpty)); //NOI18N - - // Check on length, e.g. country codes are excactly 2 chars long - assert (maxLength >= minLength); - - // Init input - String input = null; - - // Check if it is to short or to long - while (((null == input) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) { - // Output message - System.out.print(message); - - // Read line - input = this.readString(); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N - - // Return it - return input; - } - - @Override - public SelectableMenuItem getMenuItem (final char accessKey, final String text) { - // Return a new console menu item - return new ConsoleMenuItem(accessKey, text); - } - - @Override - public void init () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init contact manager here - try { - this.initContactManager(); - } catch (final SQLException ex) { - // End here - this.abortProgramWithException(ex); - } - - // Fill menu map - this.fillMenuMap(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - @SuppressWarnings ("UseOfSystemOutOrSystemErr") - public void outputMessage (final String message) { - System.out.println(message); - } - - @Override - public void show (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void showCurrentMenu () { - this.showMenu(this.getCurrentMenu()); - } - - @Override - public void showEntry (final SelectableMenuItem item) { - // Access key then text - this.outputMessage(MessageFormat.format("[{0}] {1}", item.getAccessKey(), item.getText())); //NOI18N - } - - @Override - public void showWelcome () { - this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle())); //NOI18N - this.outputMessage(""); //NOI18N - this.outputMessage("Copyright(c) 2016 by Roland Häder, this is free software"); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug("Intro shown to user"); //NOI18N - } - - @Override - public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N - - // Contact must not be null - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Ask the user for editing [name], [a]ddress or [other] data - char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) "); - - // Get manager and cast it - ContactFacade manager = (ContactFacade) this.getFacade(); - - // TODO Get rid of this ugly switch block, too - switch (choice) { - case 'n': // Name data - manager.doChangeNameData(contact); - break; - - case 'a': // Address data - manager.doChangeAddressData(contact); - break; - - case 'o': // Other data - manager.doChangeOtherData(contact); - break; - - case 'x': // Exit this menu - // Ignored as it should go back - break; - - default: - // TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Reads one character - *

- * @return A single character - */ - private char readChar () { - // Read line - String input = this.readString(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("input={0}", input)); //NOI18N - - // This must be only one character - if (input.length() != 1) { - // Return zero - return 0; - } - - // Get char from first (and only) position - return input.charAt(0); - } - - /** - * Reads an integer (int) from user - *

- * @return An integer number - */ - private int readInt () { - // First read a string - String input = this.readString(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("input={0}", input)); //NOI18N - - // Init number with invalid value - int num = -1; - - // Parse number, this can be risky - try { - num = Integer.parseInt(input); - } catch (final NumberFormatException e) { - this.outputMessage("Bitte geben Sie nur Zahlen ein!"); - this.getLoggerBeanLocal().logWarning(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("num={0} - EXIT!", num)); //NOI18N - - // Return read number - return num; - } - - /** - * Reads a string from a scanner until RETURN is pressed - *

- * @return Read string from scanner - */ - private String readString () { - return this.scanner.nextLine(); - } - - @Override - protected void fillMenuMap () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Initialize first (main) menu - Menu menu = new ConsoleMenu("main", this); //NOI18N - - // Add it - this.getMenus().put("main", menu); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } -} diff --git a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java deleted file mode 100644 index 0489a6f..0000000 --- a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ /dev/null @@ -1,1023 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.client.gui; - -import java.awt.BorderLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.IOException; -import java.sql.SQLException; -import java.text.MessageFormat; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.border.TitledBorder; -import javax.swing.table.TableModel; -import org.mxchange.addressbook.BaseAddressbookSystem; -import org.mxchange.addressbook.application.AddressbookApplication; -import org.mxchange.addressbook.facade.contact.ContactFacade; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcore.application.Application; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException; -import org.mxchange.jcore.facade.Facade; -import org.mxchange.jcoreswing.client.gui.ClientFrame; -import org.mxchange.jcoreswing.model.swing.contact.ContactTableModel; - -/** - * A Swing frame for addressbook. - *

- * @author Roland Häder - */ -public class AddressbookFrame extends BaseAddressbookSystem implements ClientFrame { - - /** - * Own instance - */ - private static ClientFrame self; - - /** - * Singelton getter for this frame instance. - *

- * @param client Client instance - *

- * @return Returns a singelton instance of this frame - */ - public static ClientFrame getSelfInstance (final Client client) { - // Is it set? - if (!(self instanceof ClientFrame)) { - // Create new instance - self = new AddressbookFrame(client); - } - - // Return instance - return self; - } - - /** - * Dialog box "add contact" - */ - private JDialog addContact; - - /** - * Frame instance for "add own data" - */ - private JMenuItem addOwnItem; - - /** - * Instance to table model - */ - private TableModel dataModel; - - /** - * Table instance - */ - private JTable dataTable; - - /** - * Frame instance for "edit own data" - */ - private JMenuItem editOwnItem; - - /** - * Frame instance - */ - private final JFrame frame; - - /** - * Whether this frame has been initialized - */ - private boolean initialized; - - /** - * Status label needs to be updated - */ - private JLabel statusLabel; - - /** - * Creates an instance of this frame with a client instance - *

- * @param client - */ - private AddressbookFrame (final Client client) { - // Debug line - this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N - - // Set frame instance - this.frame = new JFrame(); - this.frame.setTitle(this.generateFrameTitle("main")); //NOI18N - - // Set client here - this.setClient(client); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public Contact doEnterOwnData () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Is the "add contact" window visible? - if (this.addContact.isVisible()) { - // Something bad happened - throw new IllegalStateException("Window addContact is already visible."); //NOI18N - } - - // Disable main window - this.frame.setEnabled(false); - - // Make other window visible - this.addContact.setVisible(true); - - // Trace message - this.getLoggerBeanLocal().logTrace("Returning null : EXIT!"); //NOI18N - - // Return value is not supported - return null; - } - - /** - * Shutdown this frame - */ - @Override - public void doShutdown () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // First only show shutdown status - this.updateStatus("shutdown"); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Enables main window (frame) - */ - @Override - public void enableMainWindow () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Enable it again - this.frame.setEnabled(true); - - // Request focus for this window - this.frame.requestFocus(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public Application getApplication () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public Client getClient () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public Facade getFacade () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public String getMessageStringFromKey (String key) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * Setups the frame, do not set isInitialized here - *

- * @param client Client instance - */ - @Override - public void setupFrame (final Client client) throws IOException { - // Debug line - this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N - - // Has the user entered own data? - if (((ContactFacade) this.getClient().getFacade()).isOwnContactAdded()) { - // Debug message - this.getLoggerBeanLocal().logDebug("Disabling menus: isOwnContactAdded()=false"); //NOI18N - - // Not entered yet, so disable "add" menu - this.addOwnItem.setEnabled(false); - } else { - // Disable "edit" - this.editOwnItem.setEnabled(false); - } - - // Make the frame visible - this.frame.setVisible(true); - - // All done here - this.updateStatus("done"); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initalizes this frame. Having initComponents() exposed (publicly - * accessible) means that any other object can initialize components which - * you may not want. - *

- * @throws org.mxchange.jcore.exceptions.FrameAlreadyInitializedException If - * this method has been called twice - */ - @Override - public void init () throws FrameAlreadyInitializedException { - // Debug line - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Has this frame been initialized? - if (this.isInitialized()) { - // Throw exception - throw new FrameAlreadyInitializedException(); - } - - // Init components - this.initComponents(); - - // Set flag - this.initialized = true; - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Returns field isInitialized. This flag indicates whether this frame has - * been initialized or not. - *

- * @return Field isInitialized - */ - @Override - public boolean isInitialized () { - return this.initialized; - } - - @Override - public void logException (final Throwable exception) { - // Yes, I know, ugly. - super.logException(exception); - } - - /** - * Shuts down the application. - */ - @Override - public void shutdownApplication () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // To do this, the frame must be initialized - if (!this.isInitialized()) { - // Not initalized, so bad call - this.getLoggerBeanLocal().logFatal("Bad call of shutdownApplication(). Please report this."); //NOI18N - return; - } - - // Call shutdown method - try { - this.getClient().getApplication().doShutdown(); - } catch (final SQLException | IOException ex) { - // Abort here - this.abortProgramWithException(ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Adds a new menu item with given key to menu instance - *

- * @param menu Menu instance to add item to - * @param key Message key part - * @param listener Listener instance - */ - private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N - - // New instance - JMenuItem item = this.initMenuItemWithTooltip(key); - - // Add listener - item.addActionListener(listener); - - // Add item -> menu - menu.add(item); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Adds a JTextField with label and tool tip to given panel - *

- * @param panel Panel instance to add text field - * @param key Part of message key from resource bundle - * @param fieldLength Length of text field - */ - private void addTextFieldWithLabelToPanel (final JPanel panel, final String key, final int fieldLength) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("panel={0},key={1},fieldLength={2} - CALLED!", panel, key, fieldLength)); //NOI18N - - // Init label for given key - JLabel label = new JLabel(this.getBundle().getString(String.format("AddressbookFrame.%s.text", key))); //NOI18N - - // And input box wih tool tip - JTextField field = new JTextField(fieldLength); - field.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.%s.toolTipText", key))); //NOI18N - - // Add both to panel - panel.add(label); - panel.add(field); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Generates a title for borders - *

- * @param key Key part to look for - *

- * @return Human-readable title - */ - private String generateBorderTitle (final String key) { - // Call bundle instance - return this.getBundle().getString(String.format("AddressbookFrame.border.%s.title.text", key)); //NOI18N - } - - /** - * Generates a title for all frames based on given sub title key. If null is - * given, the sub title is not generated. - *

- * @param subKey Key for sub title resource - *

- * @return A full application title - */ - private String generateFrameTitle (final String subKey) { - // Base title - String title = AddressbookApplication.printableTitle(); - - // Is key given? - if (subKey != null) { - // Add sub title - title = String.format("%s - %s", title, this.getBundle().getString(String.format("AddressbookFrame.%s.title.text", subKey))); //NOI18N - } - - // Return it - return title; - } - - /** - * Initializes "add" and "cancel" buttons - */ - private void initAddCancelButtons () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init panel - JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(1, 2, 10, 10)); - - // Generate "add" button - JButton addButton = new JButton(this.getBundle().getString("AddressbookFrame.button.addAddress.text")); - - // Add listener - addButton.addActionListener(new AddActionListener(this.addContact, this)); - - // Add button to panel - panel.add(addButton); - - // Generate "cancel" button - JButton cancelButton = new JButton(this.getBundle().getString("AddressbookFrame.button.cancel.text")); - - // Add listener - cancelButton.addActionListener(new CancelActionListener(this.addContact, this)); - - // Add button to panel - panel.add(cancelButton); - - // Add panel to main panel - this.addContact.add(panel); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes "add contact" dialog - */ - private void initAddContactDialog () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Instance dialog and set title - this.addContact = new JDialog(); - this.addContact.setTitle(this.generateFrameTitle("dialog.addContact")); //NOI18N - - // Set layout - this.addContact.setLayout(new GridLayout(0, 1, 2, 2)); - - // Only hide it on close and make it appear in middle of screen - this.addContact.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - this.addContact.setLocationRelativeTo(this.frame); - - // Set always on top and auto-focus - this.addContact.setAlwaysOnTop(true); - this.addContact.setAutoRequestFocus(true); - - // Initial dimension - this.addContact.setSize(500, 500); - - // And it is not resizeable - this.addContact.setResizable(false); - - /* - * Add listener which asks for confirmation, if data has been entered - * but not saved yet. The user may appriciate this ... ;-) - * - * TODO Unfinished - */ - this.addContact.addWindowListener(new WindowAdapter() { - /** - * Invoked when a window has been closed. - */ - @Override - public void windowClosed (final WindowEvent e) { - // Enable main window again - AddressbookFrame.getSelfInstance(null).enableMainWindow(); - } - - /** - * Invoked when a window is in the process of being closed. The - * close operation can be overridden at this point. - */ - @Override - public void windowClosing (final WindowEvent e) { - e.getWindow().dispose(); - } - }); - - // Init 3 panels: - // 1) "name" panel - this.initNameDataPanel(this.addContact); - - // 2) "address" panel - this.initAddressDataPanel(this.addContact); - - // 3) "other" panel - this.initOtherDataPanel(this.addContact); - - // 4) "Add" and "Cancel" buttons, combined they are unique for this dialog - this.initAddCancelButtons(); - - // x)Only for developing: - /* - * DEBUG: - */ this.addContact.setVisible(true); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes address panel - *

- * @param dialog A JDialog instance to this components to - */ - private void initAddressDataPanel (final JDialog dialog) { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Panel "address" input boxes - JPanel addressPanel = new JPanel(); - addressPanel.setLayout(new GridLayout(0, 4, 3, 3)); - - // Set border to titled version - addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address"))); //NOI18N - - // Add text field for street - this.addTextFieldWithLabelToPanel(addressPanel, "street", 20); //NOI18N - - // Number label - JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text")); - - // And text field, but only accept numbers - JFormattedTextField number = new JFormattedTextField(); - number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.toolTipText")); - - // Add both to street panel - addressPanel.add(numberLabel); - addressPanel.add(number); - - // Label for ZIP code, again numbers only - JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text")); - - // Init text field with label - JFormattedTextField zip = new JFormattedTextField(); - zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.toolTipText")); - - // Add both to street panel - addressPanel.add(zipLabel); - addressPanel.add(zip); - - // Add text field for city name - this.addTextFieldWithLabelToPanel(addressPanel, "city", 20); //NOI18N - - // Add panel to dialog - dialog.add(addressPanel); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initialize components - */ - private void initComponents () { - // Debug line - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Set default close operation - this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - // Register shutdown listener - this.frame.addWindowListener(new WindowAdapter() { - /** - * Invoked when a window has been closed. - */ - @Override - public void windowClosed (final WindowEvent e) { - // Shutdown application cleanly - self.shutdownApplication(); - } - - /** - * Invoked when a window is in the process of being closed. The - * close operation can be overridden at this point. - */ - @Override - public void windowClosing (final WindowEvent e) { - // Also shutdown cleanly here - self.shutdownApplication(); - } - }); - - // Setup layout manager - this.frame.setLayout(new BorderLayout(2, 2)); - - // Set window size - this.frame.setSize(700, 400); - - // Center window in middle of screen, instead of top-left corner - this.frame.setLocationRelativeTo(null); - - // Init menu system - this.initMenuSystem(); - - // Init table - this.initTable(); - - // Init status panel - this.initStatusPanel(); - - // Init other windows - this.initOtherDialogs(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes a menu item instance with tool tip - *

- * @param key Message key part - *

- * @return A finished JMenuItem instance - */ - private JMenuItem initMenuItemWithTooltip (final String key) { - // Debug line - this.getLoggerBeanLocal().logTrace(MessageFormat.format("key={0} - CALLED!", key)); //NOI18N - - JMenuItem item = new JMenuItem(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.text", key))); //NOI18N - item.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.toolTipText", key))); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("item={0} - EXIT!", item)); //NOI18N - - // Return it - return item; - } - - /** - * Initializes the menu system - */ - private void initMenuSystem () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init menu bar, menu and item instances - JMenuBar menuBar = new JMenuBar(); - JMenu menu; - JMenuItem item; - - // Init some menus: - // 1) File menu - menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text")); - - // Add menu items: - // 1.x) Exit program (should be last) - this.addMenuItem(menu, "exitProgram", new ActionListener() { //NOI18N - /** - * If the user has performed this action - *

- * @param e An instance of an ActionEvent class - */ - @Override - public void actionPerformed (final ActionEvent e) { - self.shutdownApplication(); - } - }); - - // Add menu -> menu bar - menuBar.add(menu); - - // Init some menus: - // 2) Addressbook menu - menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text")); - - // 2.1) Add own data - this.addOwnItem = this.initMenuItemWithTooltip("addOwnData"); //NOI18N - - // Add listener to exit menu - this.addOwnItem.addActionListener(new ActionListener() { - /** - * If the user has performed this action - *

- * @param e An instance of an ActionEvent class - */ - @Override - public void actionPerformed (final ActionEvent e) { - try { - ((ContactFacade) self.getClient().getFacade()).doEnterOwnData(); - } catch (final ContactAlreadyAddedException ex) { - // Already added, log away - // TODO maybe output message here? - self.logException(ex); - } - } - }); - - // Add item -> menu - menu.add(this.addOwnItem); - - // 2.2) Edit own data - this.editOwnItem = this.initMenuItemWithTooltip("editOwnData"); //NOI18N - - // Add listener to exit menu - this.editOwnItem.addActionListener(new ActionListener() { - /** - * If the user has performed this action - *

- * @param e An instance of an ActionEvent class - */ - @Override - public void actionPerformed (final ActionEvent e) { - ((ContactFacade) self.getClient().getFacade()).doChangeOwnData(); - } - }); - - // Add item -> menu - menu.add(this.editOwnItem); - - // Init more menus: - // 1) Add new contact - this.addMenuItem(menu, "addNewContact", new ActionListener() { //NOI18N - /** - * If the user has performed this action - *

- * @param e An instance of an ActionEvent class - */ - @Override - public void actionPerformed (final ActionEvent e) { - ((ContactFacade) self.getClient().getFacade()).doAddOtherAddress(); - } - }); - - // Add menu -> menu bar - menuBar.add(menu); - - // Add menu bar -> frame - this.frame.add(menuBar, BorderLayout.NORTH); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes name panel - *

- * @param dialog A JDialog instance to this components to - */ - private void initNameDataPanel (final JDialog dialog) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N - - // Panel "name" input boxes - JPanel namePanel = new JPanel(); - namePanel.setLayout(new GridLayout(0, 2, 3, 3)); - - // Set border to titled version - namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name"))); //NOI18N - - // Gender text field - JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text")); - - // Get all genders - Gender[] genders = Gender.values(); - - // Init gender combo box with tool tip - JComboBox gender = new JComboBox<>(new DefaultComboBoxModel<>(genders)); - gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.toolTipText")); - - // Add both to gender panel - namePanel.add(gLabel); - namePanel.add(gender); - - // Add text field for surname - this.addTextFieldWithLabelToPanel(namePanel, "surname", 20); //NOI18N - - // Add text field for family name - this.addTextFieldWithLabelToPanel(namePanel, "familyName", 20); //NOI18N - - // Finally add panel to dialog - dialog.add(namePanel); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes "other" data panel - *

- * @param dialog A JDialog instance to this components to TODO Fill this - * with life - */ - private void initOtherDataPanel (final JDialog dialog) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N - - // Panel "other" input boxes - JPanel otherPanel = new JPanel(); - otherPanel.setLayout(new GridLayout(0, 2, 3, 3)); - otherPanel.setBorder(new TitledBorder(this.generateBorderTitle("other"))); //NOI18N - - // Add text field for email address - this.addTextFieldWithLabelToPanel(otherPanel, "emailAddress", 20); //NOI18N - - // Add text field for phone number - this.addTextFieldWithLabelToPanel(otherPanel, "phoneNumber", 20); //NOI18N - - // Add text field for cellphone number - this.addTextFieldWithLabelToPanel(otherPanel, "cellphoneNumber", 20); //NOI18N - - // Add text field for fax number - this.addTextFieldWithLabelToPanel(otherPanel, "faxNumber", 20); //NOI18N - - // Init label - JLabel commentLabel = new JLabel(this.getBundle().getString("AddressbookFrame.comment.text")); - - // Init text area with tool tip - JTextArea comment = new JTextArea(5, 20); - comment.setToolTipText(this.getBundle().getString("AddressbookFrame.comment.toolTipText")); - - // Add both to panel - otherPanel.add(commentLabel); - otherPanel.add(comment); - - // Finally add panel to dialog - dialog.add(otherPanel); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initialize other dialogs (example: "Add contact") - */ - private void initOtherDialogs () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init other windows: - // 1) Add contact - this.initAddContactDialog(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes status panel - */ - private void initStatusPanel () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init status label (which needs to be updated - this.statusLabel = new JLabel(); - this.updateStatus("initializing"); //NOI18N - - // Init status bar in south - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); - panel.add(this.statusLabel); - panel.setBorder(BorderFactory.createEtchedBorder()); - - // Add panel to frame - this.frame.add(panel, BorderLayout.SOUTH); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Initializes the table which will show all contacts - */ - private void initTable () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Instance table model - this.dataModel = new ContactTableModel(this.getClient().getFacade()); - - // Instance table - this.dataTable = new JTable(this.dataModel); - - // Add mouse listener - this.dataTable.addMouseListener(new MouseAdapter() { - /** - * If the user peformed a click on a cell - *

- * @param e Mouse event instance - */ - @Override - public void mouseClicked (final MouseEvent e) { - throw new UnsupportedOperationException("Unfinished."); //NOI18N - } - }); - - // Instance scroll pane - JScrollPane scroller = new JScrollPane(); - - // Add table to scroll pane - scroller.setViewportView(this.dataTable); - scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - // Add pane to frame - this.frame.add(scroller, BorderLayout.CENTER); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Updates status to given type - *

- * @param type Status type - */ - private void updateStatus (final String type) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("type={0} - CALLED!", type)); //NOI18N - - // Set status message - this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type))); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Class for "add address" button - */ - private static class AddActionListener extends BaseAddressbookSystem implements ActionListener { - - /** - * Dialog instance - */ - private final JDialog dialog; - - /** - * Frame (not JFrame) instance - */ - private final ClientFrame frame; - - /** - * Constructor for action listener - *

- * @param dialog Dialog instance to call back - * @param frame Frame instance (not JFrame) - */ - protected AddActionListener (final JDialog dialog, final ClientFrame frame) { - // Set dialog and frame here - this.dialog = dialog; - this.frame = frame; - } - - /** - * If the action has been performed - *

- * @param e The performed action event - */ - @Override - public void actionPerformed (final ActionEvent e) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - } - - /** - * Class for "cancel address" button - */ - private static class CancelActionListener extends BaseAddressbookSystem implements ActionListener { - - /** - * Dialog instance - */ - private final JDialog dialog; - - /** - * Frame (not JFrame) instance - */ - private final ClientFrame frame; - - /** - * Constructor for action listener - *

- * @param dialog Dialog instance to call back - * @param frame Frame instance (not JFrame) - */ - protected CancelActionListener (final JDialog dialog, final ClientFrame frame) { - // Set dialog and frame here - this.dialog = dialog; - this.frame = frame; - } - - /** - * If the action has been performed - *

- * @param e The performed action event - */ - @Override - public void actionPerformed (final ActionEvent e) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - } -} diff --git a/src/org/mxchange/addressbook/client/gui/SwingClient.java b/src/org/mxchange/addressbook/client/gui/SwingClient.java deleted file mode 100644 index c2feabd..0000000 --- a/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.client.gui; - -import java.io.IOException; -import java.sql.SQLException; -import org.mxchange.addressbook.client.AddressbookClient; -import org.mxchange.addressbook.client.BaseAddressbookClient; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcore.application.Application; -import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException; -import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; -import org.mxchange.jcoreswing.client.gui.ClientFrame; - -/** - * A swing client - *

- * @author Roland Häder - */ -public class SwingClient extends BaseAddressbookClient implements AddressbookClient { - - /** - * Swing frame instance - */ - private final ClientFrame frame; - - /** - * Constructor with an Application instance. - *

- * @param application Application instance - */ - public SwingClient (final Application application) { - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Set application instance - this.setApplication(application); - - // Init frame instance - this.frame = AddressbookFrame.getSelfInstance(this); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void displayAddressBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void displayNameBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void displayOtherDataBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void doChangeOwnAddressData (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void doChangeOwnNameData (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void doChangeOwnOtherData (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - /** - * Shows dialog to enter new contact - *

- * @return Returns finished Contact instance - */ - @Override - public Contact doEnterOwnData () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Deligate this call to the frame - return this.frame.doEnterOwnData(); - } - - /** - * Shuts down this client - */ - @Override - public void doShutdown () throws SQLException, IOException { - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Parent call - super.doShutdown(); - - // Shutdown frame - this.frame.doShutdown(); - - // TODO Add other shutdown stuff - // Debug message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doUserMenuChoice () throws UnhandledUserChoiceException { - // Debug message - //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!"); - - // Not implemented here - } - - @Override - public char enterChar (final char[] validChars, String message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public Gender enterGender (final String message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public int enterInt (final int minimum, final int maximum, final String message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - /** - * Returns a Swing menu item - *

- * @param accessKey Key to access the menu - * @param text Text to show to user - *

- * @return A SelectableMenuItem - */ - @Override - public SelectableMenuItem getMenuItem (final char accessKey, final String text) { - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Returns null as the menu is now no longer controlled here. - return null; - } - - /** - * Inizializes this client - */ - @Override - public void init () { - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - try { - // Init contact manager here - this.initContactManager(); - - // Init frame - this.frame.init(); - - // Now start the frame - this.frame.setupFrame(this); - } catch (final FrameAlreadyInitializedException | IOException | SQLException ex) { - // Abort program - this.abortProgramWithException(ex); - } - - // Debug message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void outputMessage (final String message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void show (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void showCurrentMenu () { - // Debug message - //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!"); - - // Not implemented here - } - - @Override - public void showEntry (final SelectableMenuItem item) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - @Override - public void showWelcome () { - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Not implemented here - } - - @Override - public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N - } - - /** - * Fills menu map with swing menus - */ - @Override - protected void fillMenuMap () { - // Nothing to fill here as the Swing frame is handling this all - throw new UnsupportedOperationException("Not implemented."); //NOI18N - } -} diff --git a/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java b/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java deleted file mode 100644 index b6df361..0000000 --- a/src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java +++ /dev/null @@ -1,640 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.facade.contact; - -import java.io.IOException; -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import org.mxchange.addressbook.client.AddressbookClient; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; -import org.mxchange.jcore.facade.BaseFacade; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; - -/** - * A facade for contacts. - *

- * @author Roland Häder - * @version 0.0 - */ -public class AddressbookContactFacade extends BaseFacade implements ContactFacade { - - /** - * Column name list - */ - private final List columnNames; - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Translated column name list - */ - private final List translatedColumnNames; - - /** - * Constructor which accepts maxContacts for maximum (initial) contacts and - * a client instance. - *

- * @param client Client instance to use - *

- * @throws java.sql.SQLException If an SQL error occurs - */ - public AddressbookContactFacade (final Client client) throws SQLException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N - - // Make sure all parameters are set correctly - if (null == client) { - // Abort here - throw new NullPointerException("client is null"); //NOI18N - } - - // Set client instance - this.setClient(client); - - // Initialize list - this.columnNames = new ArrayList<>(15); - this.translatedColumnNames = new ArrayList<>(15); - - // And fill it - this.fillColumnNamesFromBundle(); - - // Debug message - //* NOISY-DEBUG: */ this.getLogger().logDebug("client=" + client); - } - - @Override - public void addContact (final Contact contact) throws ContactAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // Contact instance must not be null - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Add it - this.entityManager.persist(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doAddOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); //NOI18N - } - - @Override - public void doChangeAddressData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N - - // Contact must not be null - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - if (!(this.getClient() instanceof AddressbookClient)) { - // Cannot cast - throw new IllegalArgumentException(MessageFormat.format("this.getClient()={0} does not implement AddressbookClient", this.getClient())); //NOI18N - } - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - // First display it again - client.displayAddressBox(contact); - - // Is it own data? - if (contact.isOwnContact()) { - // Deligate to client - client.doChangeOwnAddressData(contact); - } else { - // Other contact's address data to change - throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeNameData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N - - // Contact must not be null - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - // First display them again - client.displayNameBox(contact); - - // Is this own data? - if (contact.isOwnContact()) { - // Re-ask own data - client.doChangeOwnNameData(contact); - } else { - // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); //NOI18N - } - - @Override - public void doChangeOtherData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N - - // Contact must not be null - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - // First display them again - client.displayOtherDataBox(contact); - - // Is this own data? - if (contact.isOwnContact()) { - // Re-ask own data - client.doChangeOwnOtherData(contact); - } else { - // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doChangeOwnData () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - /* - * First check if the user has registered own contact, before that - * nothing can be changed. - */ - if (!this.isOwnContactAdded()) { - // Not added - this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben."); //NOI18N - - // Skip any below code - return; - } - - // Instance - Contact contact = this.getOwnContact(); - - // It must be found - assert (contact instanceof Contact) : ": contact is not implementing Contact: " + contact; - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - // Display contact - client.show(contact); - - try { - // Ask user what to change - client.userChooseChangeContactData(contact); - } catch (final UnhandledUserChoiceException ex) { - this.getLoggerBeanLocal().logException(ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doDeleteOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); //NOI18N - } - - @Override - public void doEnterOwnData () throws ContactAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Is own contact already added? - if (this.isOwnContactAdded()) { - // Don't continue here - throw new ContactAlreadyAddedException(); - } - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - // Deligate this call to the client - Contact contact = client.doEnterOwnData(); - - // Is it set? - if (contact instanceof Contact) { - // Add it to contact "book" - this.registerContact(contact); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public void doListContacts () { - throw new UnsupportedOperationException("Not supported yet."); //NOI18N - } - - @Override - public void doSearchContacts () { - throw new UnsupportedOperationException("Not supported yet."); //NOI18N - } - - @Override - public void doShutdown () throws SQLException, IOException { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Shut down the database layer - this.entityManager.close(); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - @Override - public DialableMobileNumber enterOwnCellNumber () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true); - } - - @Override - public String enterOwnCity () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(3, 50, "Bitte geben Sie Ihren Wohnort ein: ", false); - } - - @Override - public String enterOwnComment () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true); - } - - @Override - public String enterOwnCompanyName () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true); - } - - @Override - public Country enterOwnCountryCode () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase(); - } - - @Override - public String enterOwnEmailAddress () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true); - } - - @Override - public String enterOwnFamilyName () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false); - } - - @Override - public DialableFaxNumber enterOwnFaxNumber () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true); - } - - @Override - public String enterOwnFirstName () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false); - } - - @Override - public Gender enterOwnGender () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): "); - } - - @Override - public DialableLandLineNumber enterOwnPhoneNumber () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true); - } - - @Override - public String enterOwnStreet () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false); - } - - @Override - public int enterOwnZipCode () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Get and cast client instance - AddressbookClient client = (AddressbookClient) this.getClient(); - - return client.enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: "); - } - - @Override - public int getColumnCount () { - assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N - - return this.columnNames.size(); - } - - @Override - public String getColumnName (final int columnIndex) { - assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N - - // Get column name at index - return this.columnNames.get(columnIndex); - } - - @Override - public String getTranslatedColumnName (final int columnIndex) { - assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N - - // Get column name at index - return this.translatedColumnNames.get(columnIndex); - } - - @Override - public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex)); //NOI18N - - // Convert column index -> name - String columnName = this.getColumnName(columnIndex); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("columnName={0}", columnName)); //NOI18N - - // Init value - Object value = null; - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N - - // Return it - return value; - } - - @Override - public boolean isOwnContactAdded () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Init variable - boolean isAdded = false; - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N - - // Return result - return isAdded; - } - - @Override - public void registerContact (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N - - // Sanity check - if (null == contact) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } - try { - // Check if contact is found - if (this.entityManager.contains(contact)) { - // Contact already added - // TODO Do something here - } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) { - // Own contact already added - // TODO Do something - } - - // Add contact to internal list - this.addContact(contact); - } catch (final ContactAlreadyAddedException ex) { - // Abort here - this.abortProgramWithException(ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Logs given exception and exits program - *

- * @param throwable Throwable - */ - private void abortProgramWithException (Throwable throwable) { - // Log exception - this.logException(throwable); - - // Abort here - System.exit(1); - } - - /** - * Fills the column names array with strings from bundle - */ - private void fillColumnNamesFromBundle () { - assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N - assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N - - // Debug message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // First get an iterator from key set to iterate over - Iterator iterator = this.getBundle().keySet().iterator(); - - // Then iterate over all - while (iterator.hasNext()) { - // Get next element - String key = iterator.next().toLowerCase(); - - // Does the key start with AddressbookContactFacade.columnName ? - if (key.startsWith("ContactManager.columnName")) { //NOI18N - // This is the wanted entry. - this.getLoggerBeanLocal().logDebug(MessageFormat.format("key={0}", key)); //NOI18N - - // Convert string to array based on delimiter '.' - String[] tokens = this.getArrayFromString(key, "."); //NOI18N - - // Token array must contain 4 elements (AddressbookContactFacade.columnName.foo.text) - assert (tokens.length == 4) : MessageFormat.format("Array tokens contains not 4 elements: {0}", Arrays.toString(tokens)); //NOI18N - - // Get pre-last element - String columnName = tokens[tokens.length - 2]; - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("columnName={0} - adding ...", columnName)); //NOI18N - - // So add it - this.columnNames.add(columnName); - this.translatedColumnNames.add(this.getBundle().getString(key)); - } - } - - // Debug message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N - } - - /** - * Getter for loggerBeanLocal instance - *

- * @return Logger instance - */ - private LoggerBeanLocal getLoggerBeanLocal () { - return this.loggerBeanLocal; - } - - /** - * "Getter" for own contact instance or null if not found - *

- * @return Contact instance or null - */ - private Contact getOwnContact () { - // Trace message - this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N - - // Deligate this call to database frontend - Contact contact = null; - //Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N - - // Return instance or null - return contact; - } - - /** - * Logs given exception - *

- * @param exception Throwable - */ - protected void logException (final Throwable exception) { - this.getLoggerBeanLocal().logException(exception); - } -} diff --git a/src/org/mxchange/addressbook/facade/contact/ContactFacade.java b/src/org/mxchange/addressbook/facade/contact/ContactFacade.java deleted file mode 100644 index e3c7244..0000000 --- a/src/org/mxchange/addressbook/facade/contact/ContactFacade.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.facade.contact; - -import java.io.IOException; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; -import org.mxchange.jcore.facade.Facade; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; - -/** - * An interface for addressbook contact manager - *

- * @author Roland Häder - */ -public interface ContactFacade extends Facade { - - /** - * Adds given Contact instance to list - *

- * @param contact Contact instance to add - *

- * @throws org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException If - * the contact is already added - */ - void addContact (final Contact contact) throws ContactAlreadyAddedException; - - /** - * Let the user add a new other address - */ - void doAddOtherAddress (); - - /** - * The user can change address data, like street, ZIP code, city and country - * of given Contact instance. - *

- * @param contact Instance to change data - */ - void doChangeAddressData (final Contact contact); - - /** - * The user can change name data, like gender, surname, family name and - * company name (if business contact). - *

- * @param contact Instance to change data - */ - void doChangeNameData (final Contact contact); - - /** - * Let the user change other address - */ - void doChangeOtherAddress (); - - /** - * The user can change other data, like phone numbers or comments. - *

- * @param contact Instance to change data - */ - void doChangeOtherData (final Contact contact); - - /** - * Let the user change own data - *

- */ - void doChangeOwnData (); - - /** - * Let the user delete other address - */ - void doDeleteOtherAddress (); - - /** - * Asks user for own data - *

- * @throws org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException If - * own contact is already added - */ - void doEnterOwnData () throws ContactAlreadyAddedException; - - /** - * List all contacts - */ - void doListContacts (); - - /** - * Searches address book for a contact - */ - void doSearchContacts (); - - /** - * Allows the user to enter own cellphone number. - *

- * @return Cellphone number - */ - DialableMobileNumber enterOwnCellNumber (); - - /** - * Allows the user to enter own city name. - *

- * @return City name - */ - String enterOwnCity (); - - /** - * Allows the user to enter comment for own entry. - *

- * @return Comment - */ - String enterOwnComment (); - - /** - * Allows the user to enter own company name. - *

- * @return Company name - */ - String enterOwnCompanyName (); - - /** - * Allows the user to enter own country code. - *

- * @return Country code - */ - Country enterOwnCountryCode (); - - /** - * Allows the user to enter own email address. - *

- * @return Email address - */ - String enterOwnEmailAddress (); - - /** - * Allows the user to enter own family name. - *

- * @return Family name - */ - String enterOwnFamilyName (); - - /** - * Allows the user to enter own fax number. - *

- * @return Fax number - */ - DialableFaxNumber enterOwnFaxNumber (); - - /** - * Allows the user to enter own surname. - *

- * @return Surname - */ - String enterOwnFirstName (); - - /** - * Allows the user to enter own gender. - *

- * @return Gender - */ - Gender enterOwnGender (); - - /** - * Allows the user to enter own phone number. - *

- * @return Phone number - */ - DialableLandLineNumber enterOwnPhoneNumber (); - - /** - * Allows the user to enter own street and house number. - *

- * @return Street and house number - */ - String enterOwnStreet (); - - /** - * Allows the user to enter own ZIP code. - *

- * @return ZIP code - */ - int enterOwnZipCode (); - - /** - * Getter for column count - *

- * @return Column count TODO: This is needed for TableModel in Swing - */ - int getColumnCount (); - - /** - * Getter for column name at given index. - *

- * @param columnIndex Column index - *

- * @return Database column name TODO: This is needed for TableModel in Swing - */ - String getColumnName (final int columnIndex); - - /** - * Getter for translated column name at given index. - *

- * @param columnIndex Column index - *

- * @return Human-readable column name TODO: This is needed for TableModel in - * Swing - */ - String getTranslatedColumnName (final int columnIndex); - - /** - * Somewhat "getter" for value from given row and column index - *

- * @param rowIndex Row index - * @param columnIndex Column index - *

- * @return Value from given row/column - */ - Object getValueFromRowColumn (final int rowIndex, final int columnIndex); - - /** - * Checks whether own contact is already added by checking all entries for - * isOwnContact flag - *

- * @return Whether own contact is already added - *

- * @throws java.io.IOException If an IO error occurs - */ - boolean isOwnContactAdded () throws IOException; - - /** - * Adds given contact to address book - *

- * @param contact Contact being added TODO Add check for book size - */ - void registerContact (final Contact contact); -} diff --git a/src/org/mxchange/addressbook/menu/AddressbookMenu.java b/src/org/mxchange/addressbook/menu/AddressbookMenu.java deleted file mode 100644 index 0732ed9..0000000 --- a/src/org/mxchange/addressbook/menu/AddressbookMenu.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import java.text.MessageFormat; -import java.util.List; -import org.mxchange.addressbook.client.AddressbookClient; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcore.client.Client; - -/** - * Utility class for menu structure - *

- * @author Roland Häder - */ -public class AddressbookMenu extends BaseMenu { - - /** - * Copies entries for given type into the menu list - *

- * @param menuList Menu list for later showing - * @param menuType Type of menu - * @param client Client instance to call back - */ - public static void addItemsToList (final List menuList, final String menuType, final Client client) { - // Some instances must be set - if (null == menuList) { - // Abort here - throw new NullPointerException("menuList is null"); //NOI18N - } else if (null == client) { - // Abort here - throw new NullPointerException("contact is null"); //NOI18N - } else if (!(client instanceof AddressbookClient)) { - // Not correct instance - throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client)); - } - - // Cast client to proper interface - AddressbookClient c = (AddressbookClient) client; - - // Get list size - int size = menuList.size(); - - // Depends on type - switch (menuType) { - case "main": // Main menu //NOI18N - // Enter own data - menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen")); - - // Change own data - menuList.add(c.getMenuItem('2', "Eigene Adresse ändern")); - - // Add new addess - menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen")); - - // List entries - menuList.add(c.getMenuItem('4', "Adressbuch anzeigen")); - - // Address search - menuList.add(c.getMenuItem('5', "Adresse suchen")); - - // Change other address - menuList.add(c.getMenuItem('6', "Adresse ändern")); - - // Delete other address - menuList.add(c.getMenuItem('7', "Adresse löschen")); - - // Always last line: Exit program - menuList.add(c.getMenuItem('0', "Programm verlassen")); - break; - - default: // Not supported - System.err.println(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N - System.exit(1); - } - - // Size must have changed to more entries than before - assert (menuList.size() > size); - } - -} diff --git a/src/org/mxchange/addressbook/menu/BaseMenu.java b/src/org/mxchange/addressbook/menu/BaseMenu.java deleted file mode 100644 index 8f1a4b8..0000000 --- a/src/org/mxchange/addressbook/menu/BaseMenu.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import org.mxchange.addressbook.BaseAddressbookSystem; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcore.client.Client; - -/** - * A general menu class - *

- * @author Roland Häder - */ -public abstract class BaseMenu extends BaseAddressbookSystem implements Menu { - - /** - * Menu list - */ - private List menuList; - - /** - * No instance from this object - */ - protected BaseMenu () { - } - - @Override - public int getMenuItemsCount () { - return this.menuList.size(); - } - - @Override - public Iterator getMenuItemsIterator () { - return this.menuList.iterator(); - } - - @Override - public void show (final Client client) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={0} CALLED!", client)); //NOI18N - - // Client must not be null - if (null == client) { - // Abort here - throw new NullPointerException("client is null"); //NOI18N - } - - // Get values - Iterator iterator = this.menuList.iterator(); - - // Debug message - this.getLoggerBeanLocal().logDebug("Showing menu with '" + this.menuList.size() + "' entries."); - - // Output all menus - while (iterator.hasNext()) { - // Get item - SelectableMenuItem item = iterator.next(); - - // Show this item - item.show(client); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - - /** - * Getter for menu list - *

- * @return menuList List of menu entries - */ - protected List getMenuList () { - return Collections.unmodifiableList(this.menuList); - } - - /** - * Initializes menu - *

- * @param menuType Menu type to initialize - * @param client CLient to call back - */ - protected void initMenu (final String menuType, final Client client) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N - - // Init menu list - this.menuList = new ArrayList<>(5); - - // Trace message - this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } -} diff --git a/src/org/mxchange/addressbook/menu/Menu.java b/src/org/mxchange/addressbook/menu/Menu.java deleted file mode 100644 index 1fe4f68..0000000 --- a/src/org/mxchange/addressbook/menu/Menu.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import java.util.Iterator; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcore.client.Client; - -/** - * An interface for menus - *

- * @author Roland Häder TODO find better name - */ -public interface Menu { - - /** - * Size of all menu items - *

- * @return - */ - int getMenuItemsCount (); - - /** - * "Getter" for an iterator on all menu items of the current menu - *

- * @return Iterator on all menu items - */ - Iterator getMenuItemsIterator (); - - /** - * Shows this menu - *

- * @param client Client instance - */ - void show (final Client client); -} diff --git a/src/org/mxchange/addressbook/menu/MenuTools.java b/src/org/mxchange/addressbook/menu/MenuTools.java deleted file mode 100644 index 9204ac1..0000000 --- a/src/org/mxchange/addressbook/menu/MenuTools.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import java.util.Iterator; -import java.util.Map; -import org.mxchange.addressbook.BaseAddressbookSystem; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.jcore.exceptions.MenuInitializationException; - -/** - * Menu utilities - *

- * @author Roland Häder - */ -public class MenuTools extends BaseAddressbookSystem { - - /** - * Gets an array with all available access keys back from given menu map. - * This can later be handle to the client's enterChar() method. - *

- * @param menus A Map with all menus and their entries - * @param menuType Menu type - *

- * @return An array with available access chars - *

- * @throws org.mxchange.jcore.exceptions.MenuInitializationException If the - * menu cannot be initialized - */ - public static char[] getAccessKeysFromMenuMap (final Map menus, final String menuType) throws MenuInitializationException { - // First search for the proper menu class - Menu menu = menus.get(menuType); - - // Is it there? - if (!(menu instanceof Menu)) { - // Not found - throw new MenuInitializationException(menu, menuType); - } - - // Get iterator - Iterator iterator = menu.getMenuItemsIterator(); - - // Init return array and counter 'i' - char[] accessKeys = new char[menu.getMenuItemsCount()]; - int i = 0; - - // Now "walk" through all menu entries - while (iterator.hasNext()) { - // Get item - SelectableMenuItem item = iterator.next(); - //* NOISY-DEBUG: */ logger.logDebug("item=" + item); - - // Get access key from item and add it to the array - accessKeys[i] = item.getAccessKey(); - //* NOISY-DEBUG: */ logger.logDebug("accessKeys[" + i + "]=" + accessKeys[i]); - - // Increment counter - i++; - } - - // Return finished array - return accessKeys; - } -} diff --git a/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java b/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java deleted file mode 100644 index 43ac0e2..0000000 --- a/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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.console; - -import java.text.MessageFormat; -import org.mxchange.addressbook.menu.AddressbookMenu; -import org.mxchange.addressbook.menu.BaseMenu; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.jcore.client.Client; - -/** - * A menu system for the console - *

- * @author Roland Häder - */ -public class ConsoleMenu extends BaseMenu implements Menu { - - /** - * Constructor for this menu - *

- * @param menuType Menu type to initialize - * @param client CLient to call back - */ - public ConsoleMenu (final String menuType, final Client client) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N - - // Client must not be null - if (null == client) { - // Abort here - throw new NullPointerException("client is null"); - } - - // Init menu - this.initMenu(menuType, client); - - // Add all items - AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client); - } -} diff --git a/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java b/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java deleted file mode 100644 index c98430f..0000000 --- a/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import org.mxchange.addressbook.BaseAddressbookSystem; - -/** - * A general menu item class - *

- * @author Roland Häder - */ -public abstract class BaseMenuItem extends BaseAddressbookSystem { - -} diff --git a/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java b/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java deleted file mode 100644 index 0d0bf36..0000000 --- a/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -import org.mxchange.jcore.FrameworkInterface; -import org.mxchange.jcore.client.Client; - -/** - * A selectable menu item intereface - *

- * @author Roland Häder - */ -public interface SelectableMenuItem extends FrameworkInterface { - - /** - * Access key - *

- * @return the accessKey - */ - char getAccessKey (); - - /** - * Text to user - *

- * @return the text - */ - String getText (); - - /** - * Shows this menu item - *

- * @param client Client instance - */ - void show (final Client client); -} diff --git a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java deleted file mode 100644 index ed301fc..0000000 --- a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * 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; - -/** - * A menu item class for the console - *

- * @author Roland Häder - */ -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); - } - - @Override - public char getAccessKey () { - return this.accessKey; - } - - /** - * Access key - *

- * @param accessKey the accessKey to set - */ - private void setAccessKey (final char accessKey) { - this.accessKey = accessKey; - } - - @Override - public String getText () { - return this.text; - } - - /** - * Text to user - *

- * @param text the text to set - */ - private void setText (final String text) { - this.text = text; - } - - @Override - public void show (final Client client) { - // Trace message - this.getLoggerBeanLocal().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.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N - } - -} diff --git a/src/org/mxchange/localization/bundle_de_DE.properties b/src/org/mxchange/localization/bundle_de_DE.properties index ee494f0..6d410df 100644 --- a/src/org/mxchange/localization/bundle_de_DE.properties +++ b/src/org/mxchange/localization/bundle_de_DE.properties @@ -12,58 +12,5 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AddressbookFrame.border.name.title.text=Anrede, Vorname, Nachname: -AddressbookFrame.border.address.title.text=Anschrift: -AddressbookFrame.border.other.title.text=Andere Angaben: -AddressbookFrame.button.addAddress.text=Adresse hinzuf\u00fcgen -AddressbookFrame.button.cancel.text=Abbrechen -AddressbookFrame.menu.file.text=Datei -AddressbookFrame.menu.addressbook.text=Adressbuch -AddressbookFrame.statusLabel.initializing.text=Initialisiere ... -AddressbookFrame.statusLabel.done.text=Fertig. -AddressbookFrame.statusLabel.shutdown.text=Shuttting down ... -AddressbookFrame.menuItem.exitProgram.text=Programm beenden -AddressbookFrame.menuItem.exitProgram.toolTipText=Beendet das Programm und speichert alle Einstellungen ab. -AddressbookFrame.menuItem.addOwnData.text=Eigene Adresse hinzuf\u00fcgen -AddressbookFrame.menuItem.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten. -AddressbookFrame.menuItem.editOwnData.text=Eigene Adresse \u00e4ndern -AddressbookFrame.menuItem.editOwnData.toolTipText=Erlaubt das \u00c4ndern eigener Daten. -AddressbookFrame.menuItem.addNewContact.text=Neue Adresse hinzuf\u00fcgen -AddressbookFrame.menuItem.addNewContact.toolTipText=Eine neue Adresse hinzuf\u00fcgen. -AddressbookFrame.dialog.addContact.title.text=Neue Adresse hinzuf\u00fcgen -AddressbookFrame.main.title.text=Adressen auflisten -AddressbookFrame.gender.text=Anrede: -AddressbookFrame.gender.toolTipText=W\u00e4hlen Sie die Anrede aus. -AddressbookFrame.surname.text=Vorname: -AddressbookFrame.surname.toolTipText=Geben Sie den Vornamen ein. -AddressbookFrame.familyName.text=Nachname: -AddressbookFrame.familyName.toolTipText=Geben Sie den Nachnamen ein. -AddressbookFrame.street.text=Stra\u00dfe: -AddressbookFrame.street.toolTipText=Geben Sie die Stra\u00dfe ein. -AddressbookFrame.number.text=Hausnummer: -AddressbookFrame.number.toolTipText=Geben Sie die Hausnummer ein. -AddressbookFrame.zip.text=PLZ: -AddressbookFrame.zip.toolTipText=Geben Sie die Postleitzahl ein. -AddressbookFrame.city.text=Stadt: -AddressbookFrame.city.toolTipText=Geben Sie die Stadt ein. -AddressbookFrame.emailAddress.text=Email-Adresse: -AddressbookFrame.emailAddress.toolTipText=Geben Sie die Email-Adresse ein. -AddressbookFrame.phoneNumber.text=Telefon: -AddressbookFrame.phoneNumber.toolTipText=Geben Sie die Telefonnummer ein. -AddressbookFrame.cellphoneNumber.text=Mobil: -AddressbookFrame.cellphoneNumber.toolTipText=Geben Sie die Handynummer ein. -AddressbookFrame.faxNumber.text=Fax: -AddressbookFrame.faxNumber.toolTipText=Geben Sie die Faxnummer ein. -AddressbookFrame.comment.text=Anmerkungen: -AddressbookFrame.comment.toolTipText=Geben Sie eine Anmerkung (Freifeld) ein. -GENDER_UNKNOWN=Unbekannt -GENDER_MALE=Herr -GENDER_FEMALE=Frau -GENDER_COMPANY=Firma -ContactManager.columnName.gender.text=Anrede -ContactManager.columnName.surname.text=Vorname -ContactManager.columnName.familyName.text=Nachname -ContactManager.columnName.street.text=Strasse -ContactManager.columnName.houseNumber.text=Hausnummer -ContactManager.columnName.zipCode.text=Postleitzahl -ContactManager.columnName.city.text=Stadt + +# ... diff --git a/src/org/mxchange/localization/bundle_en_US.properties b/src/org/mxchange/localization/bundle_en_US.properties index f5a8768..6d410df 100644 --- a/src/org/mxchange/localization/bundle_en_US.properties +++ b/src/org/mxchange/localization/bundle_en_US.properties @@ -12,58 +12,5 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AddressbookFrame.border.name.title.text=Gender, surname, family name: -AddressbookFrame.border.address.title.text=Address: -AddressbookFrame.border.other.title.text=Other data: -AddressbookFrame.button.addAddress.text=Add address -AddressbookFrame.button.cancel.text=Cancel -AddressbookFrame.menu.file.text=File -AddressbookFrame.menu.addressbook.text=Addressbook -AddressbookFrame.statusLabel.initializing.text=Initializing ... -AddressbookFrame.statusLabel.done.text=Done. -AddressbookFrame.statusLabel.shutdown.text=Shuttting down ... -AddressbookFrame.menuItem.exitProgram.toolTipText=Exits the program and saves all data. -AddressbookFrame.menuItem.exitProgram.text=Exit program -AddressbookFrame.menuItem.addOwnData.text=Add own address -AddressbookFrame.menuItem.addOwnData.toolTipText=Allows the user to add own address data -AddressbookFrame.menuItem.editOwnData.text=Edit own data -AddressbookFrame.menuItem.editOwnData.toolTipText=Allows the user to edit own address data -AddressbookFrame.menuItem.addNewContact.text=Add new address -AddressbookFrame.menuItem.addNewContact.toolTipText=Add a new address. -AddressbookFrame.dialog.addContact.title.text=Add new address -AddressbookFrame.main.title.text=List addresses -AddressbookFrame.gender.text=Gender: -AddressbookFrame.gender.toolTipText=Choose gender. -AddressbookFrame.surname.text=Surname: -AddressbookFrame.surname.toolTipText=Enter surname. -AddressbookFrame.familyName.text=Family name: -AddressbookFrame.familyName.toolTipText=Enter family name. -AddressbookFrame.street.text=Street: -AddressbookFrame.street.toolTipText=Enter street. -AddressbookFrame.number.text=Number: -AddressbookFrame.number.toolTipText=Enter number. -AddressbookFrame.zip.text=ZIP: -AddressbookFrame.zip.toolTipText=Enter zip code. -AddressbookFrame.city.text=City: -AddressbookFrame.city.toolTipText=Enter city. -AddressbookFrame.emailAddress.text=Email address: -AddressbookFrame.emailAddress.toolTipText=Enter email address. -AddressbookFrame.phoneNumber.text=Phone: -AddressbookFrame.phoneNumber.toolTipText=Enter phone number. -AddressbookFrame.cellphoneNumber.text=Mobile: -AddressbookFrame.cellphoneNumber.toolTipText=Enter mobile number. -AddressbookFrame.faxNumber.text=Fax: -AddressbookFrame.faxNumber.toolTipText=Enter fax number. -AddressbookFrame.comment.text=Note: -AddressbookFrame.comment.toolTipText=Enter a note (free field). -GENDER_UNKNOWN=Unknown -GENDER_MALE=Mr. -GENDER_FEMALE=Mrs. -GENDER_COMPANY=Company -ContactManager.columnName.gender.text=Gender -ContactManager.columnName.surname.text=Surname -ContactManager.columnName.familyName.text=Family name -ContactManager.columnName.street.text=Street -ContactManager.columnName.houseNumber.text=House number -ContactManager.columnName.zipCode.text=ZIP code -ContactManager.columnName.city.text=City + +# ... -- 2.39.5