From 397bac5b5173686c03d5504deb519bfd4560251b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Jul 2015 15:16:01 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20re-implementation=20of=20Swin?= =?utf8?q?g=20frame=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/AddressbookApplication.java | 664 +++++----- .../addressbook/client/BaseClient.java | 360 ++--- .../client/gui/AddressbookFrame.java | 401 +++--- .../addressbook/client/gui/ClientFrame.java | 106 +- .../addressbook/client/gui/SwingClient.java | 404 +++--- .../localization/bundle_de_DE.properties | 52 +- .../localization/bundle_en_US.properties | 52 +- .../manager/contact/ContactManager.java | 1166 ++++++++--------- .../menu/item/console/ConsoleMenuItem.java | 178 +-- 9 files changed, 1765 insertions(+), 1618 deletions(-) diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java index 788c940..3759d97 100644 --- a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -1,327 +1,337 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.application; - -import java.text.MessageFormat; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.client.console.ConsoleClient; -import org.mxchange.addressbook.client.gui.SwingClient; -import org.mxchange.addressbook.manager.application.ApplicationManager; - -/** - * ============================================ - * AddressbookApplication management: - * ============================================ - * - * Inernet("public" service) and Intranet - * - * Version 1.0+: - * - Single-user local application - * - Fields: - * + Gender - * + Surname - * + Family name - * + Company name - * + Street + number - * + ZIP code - * + City - * + Landline number - * + Fax number - * + Cell phone number - * + Email address - * + Birth day - * + Comment (?) - * - Edit own data - * - Add new contact - * - Edit contacts - * - Delete contacts - * - Categorization of contacts - * - * Version 1.1+: - * - Permanent storage in database - * - * Version 2.0+: - * - Multi-user web application - * - Local user registration / login / resend confirmation link / password - * recovery - * - User groups (aka. teams) - * - Administration area (user role) - * + Create/edit/delete groups - * + Edit/delete/lock/unlock user - * + Assign user roles/rights - * - Allow other users / groups to view addressbook - * + Full addressbook - * + Only some categories - * - VCard export - * + Allow users/guests (not recommended) - * - XML export of addressbook and compressable (ZIP) - * - Form to contact other user/group without need of mail program - * + User can disabled this - * - Directory for ussers/groups (who allowed to be listed) - * + Simple click to add user to own addressbook - * + Search form? - * - * Version 2.1+: - * - Multi-language support - * - * Version 2.2+:("socialized") - * - "Social login" (OpenID consumer) - * + Connect user account to social account - * + Sync own data? - * - "Social profile" - * + OpenID provider - * + RSS/activity feed - * - * ============================================ - * Time esitmation: - * ============================================ - * 1.0 (console): - * + 2 days - * - * 1.1 (database): - * + 2 day - * + Initial tables: contacts, categories, contact_category - * - * 2.0 (web): - * + 3 days - * + Additional tables: admins (?), admin_rights, groups, - * users, user_contacts, user_user_rights, user_category_rights, - * - * 2.1 (language) - * + 1 day - * + Additional tables: languages (disable, enable language "pack" ?) - * - * 2.2 (social): - * + 3 days - * + Additional tables: ??? - * - * @author Roland Haeder - * @version 0.0 - * @since 0.0 - */ -public class AddressbookApplication extends BaseFrameworkSystem implements Application { - /** - * Application title - */ - public static final String APP_TITLE = "Adressbuch"; - - /** - * Application version - */ - public static final String APP_VERSION = "0.0"; - - /** - * Console client is enabled by default - */ - private boolean consoleClient = true; - - /** - * GUI client is disabled by default - */ - private boolean guiClient = false; - - /** - * Getter for printable application name - * - * @return A printable name - */ - public static String printableTitle () { - return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); - } - - /** - * Bootstraps application - */ - @Override - public void doBootstrap () { - this.getLogger().debug("Initializing application ..."); - - // Init client variable - Client client = null; - - // Is console or Swing choosen? - if (this.isConsole()) { - // Debug message - this.getLogger().debug("Initializing console client ..."); - - // Init console client instance - client = new ConsoleClient(this); - } else if (this.isGui()) { - // Debug message - this.getLogger().debug("Initializing GUI (Swing) client ..."); - - // Init console instance - client = new SwingClient(this); - } else { - // Not client choosen - this.getLogger().error("No client choosen. Cannot launch."); - System.exit(1); - } - - // Init client - client.initClient(); - - // Set client instance - this.setClient(client); - - // The application is running at this point - this.getClient().enableIsRunning(); - } - - /** - * Main loop of the application - */ - @Override - public void doMainLoop () { - // @TODO The application should be running now - - // Output introduction - this.showIntro(); - - // Set current menu to main - this.getClient().setCurrentMenu("main"); - - // --- Main loop starts here --- - while (this.getClient().isRunning()) { - // The application is still active, show menu selection - this.getClient().showCurrentMenu(); - - try { - // Ask for user input and run proper method - this.getClient().doUserMenuChoice(); - } catch (final UnhandledUserChoiceException ex) { - this.getLogger().catching(ex); - } - } - // --- Main loop ends here --- - - // Debug message - this.getLogger().debug("Main loop exit - shutting down ..."); - } - - /** - * Enables console client by setting propper flag - */ - private void enableConsoleClient () { - this.getLogger().debug("Enabling console client (may become optional client) ..."); - this.consoleClient = true; - this.guiClient = false; - } - - /** - * Enables GUI client by setting propper flag - */ - private void enableGuiClient () { - this.getLogger().debug("Enabling GUI client (may become new default client) ..."); - this.consoleClient = false; - this.guiClient = true; - } - - /** - * 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) { - // Debug message - this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); - - for (final String arg : args) { - // Switch on it - switch (arg) { - case "-console": - enableConsoleClient(); - break; - - case "-gui": - enableGuiClient(); - break; -} - } - } - - /** - * Show introduction which depends on client - */ - private void showIntro () { - // Let the client show it - this.getClient().showWelcome(); - } - - /** - * Launches the application - * - * @param args Arguments handled to program - */ - private void start (final String args[]) { - this.getLogger().info("Program is started."); - - // Parse arguments - this.parseArguments(args); - - // Launch application - ApplicationManager.getManager(this).start(); - - // Good bye, but this should not be reached ... - this.getLogger().warn("Unusual exit reached."); - this.doShutdown(); - } - - /** - * Main method (entry point) - * - * @param args the command line arguments - */ - public static void main (String[] args) { - // Start application - new AddressbookApplication().start(args); - } - - /** - * Shuts down the application. - */ - @Override - public void doShutdown () { - // Shutdown client - this.getClient().doShutdown(); - - this.getLogger().info("End of program (last line)"); - System.exit(0); - } -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.application; + +import java.text.MessageFormat; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.client.console.ConsoleClient; +import org.mxchange.addressbook.client.gui.SwingClient; +import org.mxchange.addressbook.manager.application.ApplicationManager; + +/** + * ============================================ + * AddressbookApplication management: + * ============================================ + * + * Inernet("public" service) and Intranet + * + * Version 1.0+: + * - Single-user local application + * - Fields: + * + Gender + * + Surname + * + Family name + * + Company name + * + Street + number + * + ZIP code + * + City + * + Landline number + * + Fax number + * + Cell phone number + * + Email address + * + Birth day + * + Comment (?) + * - Edit own data + * - Add new contact + * - Edit contacts + * - Delete contacts + * - Categorization of contacts + * + * Version 1.1+: + * - Permanent storage in database + * + * Version 2.0+: + * - Multi-user web application + * - Local user registration / login / resend confirmation link / password + * recovery + * - User groups (aka. teams) + * - Administration area (user role) + * + Create/edit/delete groups + * + Edit/delete/lock/unlock user + * + Assign user roles/rights + * - Allow other users / groups to view addressbook + * + Full addressbook + * + Only some categories + * - VCard export + * + Allow users/guests (not recommended) + * - XML export of addressbook and compressable (ZIP) + * - Form to contact other user/group without need of mail program + * + User can disabled this + * - Directory for ussers/groups (who allowed to be listed) + * + Simple click to add user to own addressbook + * + Search form? + * + * Version 2.1+: + * - Multi-language support + * + * Version 2.2+:("socialized") + * - "Social login" (OpenID consumer) + * + Connect user account to social account + * + Sync own data? + * - "Social profile" + * + OpenID provider + * + RSS/activity feed + * + * ============================================ + * Time esitmation: + * ============================================ + * 1.0 (console): + * + 2 days + * + * 1.1 (database): + * + 2 day + * + Initial tables: contacts, categories, contact_category + * + * 2.0 (web): + * + 3 days + * + Additional tables: admins (?), admin_rights, groups, + * users, user_contacts, user_user_rights, user_category_rights, + * + * 2.1 (language) + * + 1 day + * + Additional tables: languages (disable, enable language "pack" ?) + * + * 2.2 (social): + * + 3 days + * + Additional tables: ??? + * + * @author Roland Haeder + * @version 0.0 + * @since 0.0 + */ +public class AddressbookApplication extends BaseFrameworkSystem implements Application { + /** + * Application title + */ + public static final String APP_TITLE = "Adressbuch"; + + /** + * Application version + */ + public static final String APP_VERSION = "0.0"; + + /** + * Console client is enabled by default + */ + private boolean consoleClient = true; + + /** + * GUI client is disabled by default + */ + private boolean guiClient = false; + + /** + * Getter for printable application name + * + * @return A printable name + */ + public static String printableTitle () { + return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); + } + + /** + * Bootstraps application + */ + @Override + public void doBootstrap () { + this.getLogger().debug("Initializing application ..."); + + // Init client variable + Client client = null; + + // Is console or Swing choosen? + if (this.isConsole()) { + // Debug message + this.getLogger().debug("Initializing console client ..."); + + // Init console client instance + client = new ConsoleClient(this); + } else if (this.isGui()) { + // Debug message + this.getLogger().debug("Initializing GUI (Swing) client ..."); + + // Init console instance + client = new SwingClient(this); + } else { + // Not client choosen + this.getLogger().error("No client choosen. Cannot launch."); + System.exit(1); + } + + // Init client + client.initClient(); + + // Set client instance + this.setClient(client); + + // The application is running at this point + this.getClient().enableIsRunning(); + } + + /** + * Main loop of the application + */ + @Override + public void doMainLoop () { + // Debug message + this.getLogger().trace("CALLED!"); + + // @TODO The application should be running now + + // Output introduction + this.showIntro(); + + // Set current menu to main + this.getClient().setCurrentMenu("main"); + + // --- Main loop starts here --- + while (this.getClient().isRunning()) { + // The application is still active, show menu selection + this.getClient().showCurrentMenu(); + + try { + // Ask for user input and run proper method + this.getClient().doUserMenuChoice(); + } catch (final UnhandledUserChoiceException ex) { + this.getLogger().catching(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.getLogger().debug("Main loop exit - shutting down ..."); + } + + /** + * Enables console client by setting propper flag + */ + private void enableConsoleClient () { + this.getLogger().debug("Enabling console client (may become optional client) ..."); + this.consoleClient = true; + this.guiClient = false; + } + + /** + * Enables GUI client by setting propper flag + */ + private void enableGuiClient () { + this.getLogger().debug("Enabling GUI client (may become new default client) ..."); + this.consoleClient = false; + this.guiClient = true; + } + + /** + * 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) { + // Debug message + this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); + + for (final String arg : args) { + // Switch on it + switch (arg) { + case "-console": + enableConsoleClient(); + break; + + case "-gui": + enableGuiClient(); + break; +} + } + } + + /** + * Show introduction which depends on client + */ + private void showIntro () { + // Let the client show it + this.getClient().showWelcome(); + } + + /** + * Launches the application + * + * @param args Arguments handled to program + */ + private void start (final String args[]) { + this.getLogger().info("Program is started."); + + // Parse arguments + this.parseArguments(args); + + // Launch application + ApplicationManager.getManager(this).start(); + + // Good bye, but this should not be reached ... + this.getLogger().warn("Unusual exit reached."); + this.doShutdown(); + } + + /** + * Main method (entry point) + * + * @param args the command line arguments + */ + public static void main (String[] args) { + // Start application + new AddressbookApplication().start(args); + } + + /** + * Shuts down the application. + */ + @Override + public void doShutdown () { + // Shutdown client + this.getClient().doShutdown(); + + this.getLogger().info("End of program (last line)"); + System.exit(0); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java index 399a6c1..0c8bba5 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java @@ -1,180 +1,180 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client; - -import java.util.HashMap; -import java.util.Map; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.manager.contact.ContactManager; -import org.mxchange.addressbook.manager.contact.ManageableContact; -import org.mxchange.addressbook.menu.Menu; - -/** - * A general client - * - * @author Roland Haeder - */ -public abstract class BaseClient extends BaseFrameworkSystem { - - /** - * Current menu choice - */ - private String currentMenu; - - /** - * Application is not running by default - */ - private boolean isRunning; - - /** - * Menu system - */ - private final Map menus; - - /** - * No instances can be created of this class - */ - protected BaseClient () { - super(); - - // Init menu map - this.menus = new HashMap<>(10); - } - - /** - * Shutdown method for all clients - */ - public void doShutdown () { - // Disable client - this.disableIsRunning(); - - // Shuts down contact manager - this.getContactManager().doShutdown(); - } - - /** - * Enables the client - */ - public final void enableIsRunning () { - this.isRunning = true; - } - - /** - * Current menu choice - * - * @return the currentMenu - */ - public final String getCurrentMenu () { - return this.currentMenu; - } - - /** - * Current menu choice - * @param currentMenu the currentMenu to set - */ - public final 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 - */ - public 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; - } - - /** - * Determines whether the application is still active by checking some - * conditions - * - * @return Whether the application is still active - */ - public final boolean isRunning () { - // In console client, 0 may have been used - return this.isRunning; - } - - /** - * Disables running state, so the main loop can abort. - */ - protected final void disableIsRunning () { - this.isRunning = false; - } - - /** - * Fills menu map with swing menus - */ - protected abstract void fillMenuMap (); - - /** - * Getter for menus map - * @return Map of all menus - */ - protected final Map getMenus () { - return this.menus; - } - - /** - * Initializes contact manager - */ - protected void initContactManager () { - // Debug message - this.getLogger().debug("Initializing contact manager ..."); - - // Init contact manager with console client - // @TODO Static initial amount of contacts - ManageableContact manager = new ContactManager (100, (Client) this); - - // Set it here - this.setContactManager(manager); - - // Debug message - this.getLogger().debug("Contact manager has been initialized."); - } - - /** - * Shows given menu - * - * @param menuType Given menu to show - */ - protected void showMenu (final String menuType) { - Menu menu = this.getMenu(menuType); - - // Is the menu set? - if (!(menu instanceof Menu)) { - // Not found - // @todo Own exception? - throw new NullPointerException("Menu '" + menuType + "' not found."); - } - - // Show menu - menu.show((Client) this); - } -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client; + +import java.util.HashMap; +import java.util.Map; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.manager.contact.ContactManager; +import org.mxchange.addressbook.manager.contact.ManageableContact; +import org.mxchange.addressbook.menu.Menu; + +/** + * A general client + * + * @author Roland Haeder + */ +public abstract class BaseClient extends BaseFrameworkSystem { + + /** + * Current menu choice + */ + private String currentMenu; + + /** + * Application is not running by default + */ + private boolean isRunning; + + /** + * Menu system + */ + private final Map menus; + + /** + * No instances can be created of this class + */ + protected BaseClient () { + super(); + + // Init menu map + this.menus = new HashMap<>(10); + } + + /** + * Shutdown method for all clients + */ + public void doShutdown () { + // Disable client + this.disableIsRunning(); + + // Shuts down contact manager + this.getContactManager().doShutdown(); + } + + /** + * Enables the client + */ + public final void enableIsRunning () { + this.isRunning = true; + } + + /** + * Current menu choice + * + * @return the currentMenu + */ + public final String getCurrentMenu () { + return this.currentMenu; + } + + /** + * Current menu choice + * @param currentMenu the currentMenu to set + */ + public final 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 + */ + public 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; + } + + /** + * Determines whether the application is still active by checking some + * conditions + * + * @return Whether the application is still active + */ + public final boolean isRunning () { + // In console client, 0 may have been used + return this.isRunning; + } + + /** + * Disables the client + */ + protected final void disableIsRunning () { + this.isRunning = false; + } + + /** + * Fills menu map with swing menus + */ + protected abstract void fillMenuMap (); + + /** + * Getter for menus map + * @return Map of all menus + */ + protected final Map getMenus () { + return this.menus; + } + + /** + * Initializes contact manager + */ + protected void initContactManager () { + // Debug message + this.getLogger().debug("Initializing contact manager ..."); + + // Init contact manager with console client + // @TODO Static initial amount of contacts + ManageableContact manager = new ContactManager (100, (Client) this); + + // Set it here + this.setContactManager(manager); + + // Debug message + this.getLogger().debug("Contact manager has been initialized."); + } + + /** + * Shows given menu + * + * @param menuType Given menu to show + */ + protected void showMenu (final String menuType) { + Menu menu = this.getMenu(menuType); + + // Is the menu set? + if (!(menu instanceof Menu)) { + // Not found + // @todo Own exception? + throw new NullPointerException("Menu '" + menuType + "' not found."); + } + + // Show menu + menu.show((Client) this); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index fe9d47b..7310100 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -1,146 +1,255 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client.gui; - -import java.text.MessageFormat; -import javax.swing.JFrame; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.FrameAlreadyInitializedException; -import org.mxchange.addressbook.application.AddressbookApplication; -import org.mxchange.addressbook.client.Client; - -/** - * - * @author Roland Haeder - */ -public class AddressbookFrame extends BaseFrameworkSystem 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 final ClientFrame getSelfInstance (final Client client) { - // Is it set? - if (!(self instanceof ClientFrame)) { - // Create new instance - self = new AddressbookFrame(client); - } - - // Return instance - return self; - } - - /** - * Frame instance - */ - private final JFrame frame; - - /** - * Whether this frame has been initialized - */ - private boolean isInitialized; - - /** - * Creates an instance of this frame with a client instance - * - * @param client - */ - private AddressbookFrame (final Client client) { - // Debug line - this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); - - // Set frame instance - this.frame = new JFrame(AddressbookApplication.printableTitle()); - - // Set client here - this.setClient(client); - } - - /** - * Setups the frame, do not set isInitialized here - * - * @param client Client instance - */ - @Override - public void setupFrame (final Client client) { - // Debug line - this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); - - // Has the user entered own data? - if (this.getClient().getContactManager().isOwnContactAdded()) { - // Debug message - this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); - - // Not entered yet, so enable menu - //addOwnData.setEnabled(false); - } - - // All done here - //statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text")); - } - - /** - * Initalizes this frame. Having initComponents() exposed (publicly - * accessible) means that any other object can initialize components which - * you may not want. - * - * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice - */ - @Override - public void initFrame () throws FrameAlreadyInitializedException { - // Debug line - this.getLogger().trace("CALLED!"); - - // Has this frame been initialized? - if (this.isInitialized()) { - // Throw exception - throw new FrameAlreadyInitializedException(); - } - - // Init components - this.initComponents(); - - // Set flag - this.isInitialized = true; - } - - /** - * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. - * - * @return Field isInitialized - */ - @Override - public final boolean isInitialized () { - return this.isInitialized; - } - - /** - * Initialize components - */ - private void initComponents () { - // Debug line - this.getLogger().trace("CALLED!"); - } - -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client.gui; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.text.MessageFormat; +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +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 org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.FrameAlreadyInitializedException; +import org.mxchange.addressbook.application.AddressbookApplication; +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public class AddressbookFrame extends BaseFrameworkSystem 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 final ClientFrame getSelfInstance (final Client client) { + // Is it set? + if (!(self instanceof ClientFrame)) { + // Create new instance + self = new AddressbookFrame(client); + } + + // Return instance + return self; + } + + /** + * Frame instance + */ + private final JFrame frame; + + /** + * Whether this frame has been initialized + */ + private boolean isInitialized; + + /** + * 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.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); + + // Set frame instance + this.frame = new JFrame(AddressbookApplication.printableTitle()); + + // Set default close operation + this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Set client here + this.setClient(client); + } + + /** + * Shutdown this frame + */ + @Override + public void doShutdown () { + // First only show shutdown status + this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel.shutdown.text")); + } + + /** + * Setups the frame, do not set isInitialized here + * + * @param client Client instance + */ + @Override + public void setupFrame (final Client client) { + // Debug line + this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); + + // Has the user entered own data? + if (this.getClient().getContactManager().isOwnContactAdded()) { + // Debug message + this.getLogger().debug("Disabling menus: isOwnContactAdded()=false"); + + // Not entered yet, so enable menu + //addOwnData.setEnabled(false); + } + + // Make the frame visible + this.frame.setVisible(true); + + // All done here + this.statusLabel.setText(this.getBundle().getString("AddressbookFrame.statusLabel.done.text")); + } + + /** + * Initalizes this frame. Having initComponents() exposed (publicly + * accessible) means that any other object can initialize components which + * you may not want. + * + * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice + */ + @Override + public void initFrame () throws FrameAlreadyInitializedException { + // Debug line + this.getLogger().trace("CALLED!"); + + // Has this frame been initialized? + if (this.isInitialized()) { + // Throw exception + throw new FrameAlreadyInitializedException(); + } + + // Init components + this.initComponents(); + + // Set flag + this.isInitialized = true; + } + + /** + * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. + * + * @return Field isInitialized + */ + @Override + public final boolean isInitialized () { + return this.isInitialized; + } + + /** + * Initialize components + */ + private void initComponents () { + // Debug line + this.getLogger().trace("CALLED!"); + + // 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.getClient().getApplication().doShutdown(); + } + + /** + * 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.getClient().getApplication().doShutdown(); + } + }); + + // 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 bar in north + JMenuBar menuBar = new JMenuBar(); + + // Init some menus: + // 1) File menu + JMenu menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.file.text")); + + // Add menu items: + // 1.x) Exit program (should be last) + JMenuItem item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text")); + item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText")); + + // Add listener to exit menu + item.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) { + self.getClient().getApplication().doShutdown(); + } + }); + + // Add item -> menu + menu.add(item); + + // Add menu -> menu bar + menuBar.add(menu); + + // Add menu bar -> frame + this.frame.add(menuBar, BorderLayout.NORTH); + + // Init status label (which needs to be updated + this.statusLabel = new JLabel(this.getBundle().getString("AddressbookFrame.statusLabel.initializing.text")); + + // Init status bar in south + JPanel statusPanel = new JPanel(); + statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); + statusPanel.add(this.statusLabel); + statusPanel.setBorder(BorderFactory.createEtchedBorder()); + + // Add panel to frame + this.frame.add(statusPanel, BorderLayout.SOUTH); + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java index 0c5ab4d..f0cc531 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -1,50 +1,56 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client.gui; - -import org.mxchange.addressbook.FrameAlreadyInitializedException; -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.client.Client; - -/** - * An interface for applications with a frame - * - * @author Roland Haeder - */ -public interface ClientFrame extends FrameworkInterface { - /** - * Setups the frame (and starts it). You have to call initFrame() before you - * can call this method. - * - * @param client Client instance - */ - public void setupFrame (final Client client); - - /** - * Initializes frame - * - * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice - */ - public void initFrame () throws FrameAlreadyInitializedException; - - /** - * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. - * - * @return Field isInitialized - */ - public boolean isInitialized (); -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client.gui; + +import org.mxchange.addressbook.FrameAlreadyInitializedException; +import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.client.Client; + +/** + * An interface for applications with a frame + * + * @author Roland Haeder + */ +public interface ClientFrame extends FrameworkInterface { + + /** + * Shutdown this frame + */ + public void doShutdown (); + + /** + * Setups the frame (and starts it). You have to call initFrame() before you + * can call this method. + * + * @param client Client instance + */ + public void setupFrame (final Client client); + + /** + * Initializes frame + * + * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice + */ + public void initFrame () throws FrameAlreadyInitializedException; + + /** + * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. + * + * @return Field isInitialized + */ + public boolean isInitialized (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index 8992b3a..c616ae9 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -1,187 +1,217 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.client.gui; - -import org.mxchange.addressbook.FrameAlreadyInitializedException; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.client.BaseClient; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - */ -public class SwingClient extends BaseClient implements Client { - /** - * Swing frame instance - */ - private final ClientFrame frame; - - /** - * Constructor with an Application instance. - * - * @param application Application instance - */ - public SwingClient (final Application application) { - super(); - - // Set application instance - this.setApplication(application); - - // Init frame instance - this.frame = AddressbookFrame.getSelfInstance(this); - } - - @Override - public void displayAddressBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void displayNameBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void displayOtherDataBox (final Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void doChangeOwnAddressData (Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void doChangeOwnNameData (Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void doChangeOwnOtherData (Contact contact) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public Contact doEnterOwnData () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void doShutdown () { - // Parent call - super.doShutdown(); - - // @TODO Add other shutdown stuff - } - - @Override - public void doUserMenuChoice () throws UnhandledUserChoiceException { - // 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. - } - - @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. - } - - @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. - } - - @Override - public Menu getMenu (final String menuType) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * 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) { - // Returns null as the menu is now no longer controlled here. - return null; - } - - /** - * Inizializes this client - */ - @Override - public void initClient () { - // Init contact manager here - this.initContactManager(); - - try { - // Init frame - this.frame.initFrame(); - } catch (final FrameAlreadyInitializedException ex) { - this.getLogger().catching(ex); - System.exit(1); - } - - // Now start the frame - this.frame.setupFrame(this); - } - - @Override - public void outputMessage (final String message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void showCurrentMenu () { - // 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. - } - - @Override - public void showWelcome () { - // 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. - } - - /** - * Fills menu map with swing menus - */ - @Override - protected final void fillMenuMap () { - // Nothing to fill here as the Swing frame is handling this all - throw new UnsupportedOperationException("Not implemented."); - } -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.client.gui; + +import org.mxchange.addressbook.FrameAlreadyInitializedException; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.client.BaseClient; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.menu.Menu; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * + * @author Roland Haeder + */ +public class SwingClient extends BaseClient implements Client { + /** + * Swing frame instance + */ + private final ClientFrame frame; + + /** + * Constructor with an Application instance. + * + * @param application Application instance + */ + public SwingClient (final Application application) { + super(); + + // Debug message + this.getLogger().trace("CALLED!"); + + // Set application instance + this.setApplication(application); + + // Init frame instance + this.frame = AddressbookFrame.getSelfInstance(this); + } + + @Override + public void displayAddressBox (final Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void displayNameBox (final Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void displayOtherDataBox (final Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void doChangeOwnAddressData (Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void doChangeOwnNameData (Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void doChangeOwnOtherData (Contact contact) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Contact doEnterOwnData () { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void doShutdown () { + // Debug message + this.getLogger().trace("CALLED!"); + + // Parent call + super.doShutdown(); + + // Shutdown frame + this.frame.doShutdown(); + + // @TODO Add other shutdown stuff + + // Debug message + this.getLogger().trace("EXIT!"); + } + + @Override + public void doUserMenuChoice () throws UnhandledUserChoiceException { + // Debug message + //* NOISY-DEBUG: */ this.getLogger().trace("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. + } + + @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. + } + + @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. + } + + @Override + public Menu getMenu (final String menuType) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + /** + * 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.getLogger().trace("CALLED!"); + + // Returns null as the menu is now no longer controlled here. + return null; + } + + /** + * Inizializes this client + */ + @Override + public void initClient () { + // Debug message + this.getLogger().trace("CALLED!"); + + // Init contact manager here + this.initContactManager(); + + try { + // Init frame + this.frame.initFrame(); + } catch (final FrameAlreadyInitializedException ex) { + this.getLogger().catching(ex); + System.exit(1); + } + + // Now start the frame + this.frame.setupFrame(this); + + // Debug message + this.getLogger().trace("EXIT!"); + } + + @Override + public void outputMessage (final String message) { + 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().trace("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. + } + + @Override + public void showWelcome () { + // Debug message + this.getLogger().trace("CALLED!"); + + // 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. + } + + /** + * Fills menu map with swing menus + */ + @Override + protected final void fillMenuMap () { + // Nothing to fill here as the Swing frame is handling this all + throw new UnsupportedOperationException("Not implemented."); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties index bbc3dbb..1a68562 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties @@ -1,28 +1,24 @@ -# Copyright (C) 2015 Roland Haeder -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -AddressbookFrame.addOwn.text=Eigene Adresse hinzuf\u00fcgen -AddressbookFrame.text=Datei -AddressbookFrame.statusLabel.text=Initialisiere ... -AddressbookFrame.status.text=Willkommen ... -AddressbookFrame.status.AccessibleContext.accessibleName= -AddressbookFrame.status.AccessibleContext.accessibleDescription= -AddressbookFrame.exitProgram.toolTipText=Beendet das Programm sauber -AddressbookFrame.exitProgram.text=Programm beenden -AddressbookFrame.addressbookMenu.text=Adressbuch -AddressbookFrame.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten -AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn -AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription= -AddressbookFrame.status.done.text=Fertig. +# Copyright (C) 2015 Roland Haeder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +AddressbookFrame.addOwn.text=Eigene Adresse hinzuf\u00fcgen +AddressbookFrame.menu.file.text=Datei +AddressbookFrame.statusLabel.initializing.text=Initialisiere ... +AddressbookFrame.statusLabel.done.text=Fertig. +AddressbookFrame.statusLabel.shutdown.text=Shuttting down ... +AddressbookFrame.menuItem.exitProgram.toolTipText=Beendet das Programm und speichert alle Einstellungen ab. +AddressbookFrame.menuItem.exitProgram.text=Programm beenden +AddressbookFrame.menu.addressbook.text=Adressbuch +AddressbookFrame.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten. diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties index 8d314b9..b3853fb 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties @@ -1,28 +1,24 @@ -# Copyright (C) 2015 Roland Haeder -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -AddressbookFrame.addOwn.text=Add own address -AddressbookFrame.text=File -AddressbookFrame.statusLabel.text=Initializing ... -AddressbookFrame.status.text=Welcome ... -AddressbookFrame.status.AccessibleContext.accessibleName= -AddressbookFrame.status.AccessibleContext.accessibleDescription= -AddressbookFrame.exitProgram.toolTipText=Exits the program cleanly. -AddressbookFrame.exitProgram.text=Exit program -AddressbookFrame.addressbookMenu.text=Addressbook -AddressbookFrame.addOwnData.toolTipText=Allows the user to add own address data -AddressbookFrame.addOwnData.AccessibleContext.accessibleName=addOwn -AddressbookFrame.addOwnData.AccessibleContext.accessibleDescription= -AddressbookFrame.status.done.text=Done. +# Copyright (C) 2015 Roland Haeder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +AddressbookFrame.addOwn.text=Add own address +AddressbookFrame.menu.file.text=File +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.addressbookMenu.text=Addressbook +AddressbookFrame.addOwnData.toolTipText=Allows the user to add own address data diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index 709f6f9..5c4f54e 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -1,583 +1,583 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.manager.contact; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend; -import org.mxchange.addressbook.database.frontend.contact.ContactWrapper; -import org.mxchange.addressbook.manager.BaseManager; - -/** - * A manager for contacts, please note that this implementation loads the whole - * list into RAM. - * - * @author Roland Haeder - * @version 0.0 - */ -public class ContactManager extends BaseManager implements ManageableContact { - /** - * Column name list - */ - private final List columnNames; - - /** - * A ContactWrapper instance - */ - private final ContactWrapper contactDatabase; - - /** - * A list of all contacts - */ - private final List contacts; - - - /** - * @param maxContacts Maximum allowed contacts - * @param client Client instance to use - */ - public ContactManager (final int maxContacts, final Client client) { - // Always call super constructor first - super(); - - // Set client instance - this.setClient(client); - - // Init contacts - this.contacts = new ArrayList<>(maxContacts); - - // Init database connection - this.contactDatabase = new ContactDatabaseFrontend(this); - - // Initialize list - this.columnNames = new ArrayList<>(15); - - // And fill it - this.fillColumnNamesFromBundle(); - - // Read all entries - this.contactDatabase.readAllContacts(); - - // Debug message - //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client); - } - - /** - * Adds given Contact instance to list - * - * @param contact Contact instance to add - */ - @Override - public void addContact (final Contact contact) { - this.contacts.add(contact); - } - - /** - * Let the user add a new other address - */ - @Override - public void addOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); - } - - /** - * Let the user change other address - */ - @Override - public void changeOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); - } - - /** - * Allows the user to change his/her own data - */ - @Override - public void changeOwnData () { - /* - * 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."); - - // Skip any below code - return; - } - - // Instance - Contact contact = this.getOwnContact(); - - // It must be found - assert(contact instanceof Contact); - - // Display contact - contact.show(this.getClient()); - - try { - // Ask user what to change - this.getClient().userChooseChangeContactData(contact); - } catch (final UnhandledUserChoiceException ex) { - this.getLogger().catching(ex); - } - } - - /** - * Let the user delete other address - */ - @Override - public void deleteOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); - } - - /** - * Let the user change address data - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - @Override - public void doChangeAddressData (final Contact contact, final Client client) { - // First display it again - client.displayAddressBox(contact); - - // Is it own data? - if (contact.isOwnContact()) { - // Deligate to client - this.getClient().doChangeOwnAddressData(contact); - } else { - // Other contact's address data to change - throw new UnsupportedOperationException("Changing contact entries not finished."); - } - - // Flush whole list - this.flush(); - } - - /** - * Let the user change "name data" - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - @Override - public void doChangeNameData (final Contact contact, final Client client) { - // First display them again - client.displayNameBox(contact); - - // Is this own data? - if (contact.isOwnContact()) { - // Re-ask own data - this.getClient().doChangeOwnNameData(contact); - } else { - // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); - } - - // Flush whole list - this.flush(); - } - - /** - * Let the user change other data - * - * @param contact Instance to change data - * @param client Client instance to call back - * @todo Didn't handle birthday - */ - @Override - public void doChangeOtherData (final Contact contact, final Client client) { - // First display them again - this.getClient().displayOtherDataBox(contact); - - // Is this own data? - if (contact.isOwnContact()) { - // Re-ask own data - this.getClient().doChangeOwnOtherData(contact); - } else { - // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); - } - - // Flush whole list - this.flush(); - } - - /** - * Asks user for own data - */ - @Override - public void doEnterOwnData () { - // Deligate this call to the client - Contact contact = this.getClient().doEnterOwnData(); - - // Add it to contact "book" - this.registerContact(contact); - } - - /** - * Shuts down this contact manager - */ - @Override - public void doShutdown () { - // Shut down the database layer - this.getContactDatabase().doShutdown(); - } - - /** - * Asks the user for his/her cellphone number - * - * @return User's cellphone number - */ - @Override - public String enterOwnCellNumber () { - return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true); - } - - /** - * Asks the user for his/her city's name - * - * @return City's name of the user - */ - @Override - public String enterOwnCity () { - return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false); - } - - /** - * Asks the user for his/her city's name - * - * @return City's name of the user - */ - @Override - public String enterOwnComment () { - return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true); - } - - /** - * Asks the user for his/her company name - * - * @return User's company name - */ - @Override - public String enterOwnCompanyName () { - return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true); - } - - /** - * Asks user for his/her own country code - * - * @return User's own country code - */ - @Override - public String enterOwnCountryCode () { - return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase(); - } - - /** - * Asks user for his/her own country code - * - * @return User's own country code - */ - @Override - public String enterOwnEmailAddress () { - return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true); - } - - /** - * Asks the user for family name - * - * @return Family name of the user - */ - @Override - public String enterOwnFamilyName () { - return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false); - } - - /** - * Asks the user for family name - * - * @return Family name of the user - */ - @Override - public String enterOwnFaxNumber () { - return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true); - } - - /** - * Asks the user for gender, until a valid has been entered - * - * @return Gender of the user - */ - @Override - public char enterOwnGender () { - return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): "); - } - - /** - * Asks the user for phone number - * - * @return Phone number of the user - */ - @Override - public String enterOwnPhoneNumber () { - return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true); - } - - /** - * Asks the user for own street (including number) - * @return Own street an number - */ - @Override - public String enterOwnStreet () { - return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false); - } - - /** - * Asks the user for surname - * @return Surname of the user - */ - @Override - public String enterOwnSurname () { - return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false); - } - - /** - * Asks the user for own ZIP code - * - * @return ZIP code - */ - @Override - public int enterOwnZipCode () { - return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: "); - } - - @Override - public final int getColumnCount () { - return this.columnNames.size(); - } - - /** - * Getter for whole contact list - * - * @return List of all contacts - */ - @Override - public List getList () { - return Collections.unmodifiableList(this.contacts); - } - - /** - * Checks whether own contact is already added by checking all entries for - * isOwnContact flag - * - * @return Whether own contact is already added - */ - @Override - public boolean isOwnContactAdded () { - // Default is not added - boolean isAdded = false; - - // Now get it back from address book, first get an iterator - Iterator iterator = this.contacts.iterator(); - - // Check entries - while (iterator.hasNext()) { - // Get next entry - Contact contact = iterator.next(); - - // Is it valid? - if (contact instanceof Contact) { - // Get flag - isAdded = contact.isOwnContact(); - - // Is this own contact? - if (isAdded) { - // Then abort loop - break; - } - } - } - // Return result - return isAdded; - } - - @Override - public void listContacts () { - throw new UnsupportedOperationException("Not supported yet."); - } - - /** - * Adds given contact to address book and flushes all entries to database - * - * @param contact Contact being added - * @todo Add check for book size - */ - @Override - public void registerContact (final Contact contact) { - // Check if contact is found - if (this.isContactAlreadyAdded(contact)) { - // Contact already added - // @todo Do something here - } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) { - // Own contact already added - // @todo Do something - } - - // Debug message - /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); - - // Add contact to internal list - this.addContact(contact); - - // Flush whole list - this.flush(); - } - - @Override - public void searchContacts () { - throw new UnsupportedOperationException("Not supported yet."); - } - - /** - * Getter for size - * - * @return size of contact "book" - */ - @Override - public final int size () { - return this.contacts.size(); - } - - /** - * Fills the column names array with strings from bundle - */ - private void fillColumnNamesFromBundle () { - // Debug message - this.getLogger().trace("CALLED!"); - - // 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(); - - // Does the key start with ContactManager.columnName ? - if (key.startsWith("ContactManager.columnName")) { - // This is the wanted entry. - this.getLogger().debug(MessageFormat.format("key={0}", key)); - - // So add it - this.columnNames.add(this.getBundle().getString(key)); - } - } - - // Debug message - this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); - } - - /** - * Flushes all entries by calling database backend - */ - private void flush () { - // Flusgh all - this.getContactDatabase().flushAllContacts(); - } - - /** - * A ContactWrapper instance - * - * @return the database - */ - private ContactWrapper getContactDatabase () { - return this.contactDatabase; - } - - /** - * "Getter" for own contact instance or null if not found - * - * @return Contact instance or null - */ - private Contact getOwnContact () { - // Now get it back from address book, first get an iterator - Iterator iterator = this.contacts.iterator(); - - // Init instance - Contact contact = null; - - // Search all contact - while (iterator.hasNext()) { - // Get next instance - Contact next = iterator.next(); - - // Is this own contact? - if (next.isOwnContact()) { - // Found it - contact = next; - break; - - } - } - - // Return instance or null - return contact; - } - - /** - * Checks whether given contact was found in "address book" - * - * @param checkContact Contact to be checked - * @return TRUE if found, FALSE if not found - */ - private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException { - // Default is not found - boolean isFound = false; - - // Debug message - //* NOISY-DEBUG: */ this.getLogger().debug("Checking '" + this.contacts.length + "' entries..."); - - // Now get it back from address book, first get an iterator - Iterator iterator = this.contacts.iterator(); - - // Check entries - while (iterator.hasNext()) { - // Get next entry - Contact contact = iterator.next(); - - // Debug message - //* NOISY-DEBUG: */ this.getLogger().debug("contact=" + contact + ",checkContent=" + checkContact); - - // Is it valid? - if ((contact instanceof Contact) && ((contact.equals(checkContact)))) { - // Found matching entry - isFound = true; - break; - } - } - - // Return result - return isFound; - } -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.manager.contact; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend; +import org.mxchange.addressbook.database.frontend.contact.ContactWrapper; +import org.mxchange.addressbook.manager.BaseManager; + +/** + * A manager for contacts, please note that this implementation loads the whole + * list into RAM. + * + * @author Roland Haeder + * @version 0.0 + */ +public class ContactManager extends BaseManager implements ManageableContact { + /** + * Column name list + */ + private final List columnNames; + + /** + * A ContactWrapper instance + */ + private final ContactWrapper contactDatabase; + + /** + * A list of all contacts + */ + private final List contacts; + + + /** + * @param maxContacts Maximum allowed contacts + * @param client Client instance to use + */ + public ContactManager (final int maxContacts, final Client client) { + // Always call super constructor first + super(); + + // Set client instance + this.setClient(client); + + // Init contacts + this.contacts = new ArrayList<>(maxContacts); + + // Init database connection + this.contactDatabase = new ContactDatabaseFrontend(this); + + // Initialize list + this.columnNames = new ArrayList<>(15); + + // And fill it + this.fillColumnNamesFromBundle(); + + // Read all entries + this.contactDatabase.readAllContacts(); + + // Debug message + //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client); + } + + /** + * Adds given Contact instance to list + * + * @param contact Contact instance to add + */ + @Override + public void addContact (final Contact contact) { + this.contacts.add(contact); + } + + /** + * Let the user add a new other address + */ + @Override + public void addOtherAddress () { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Let the user change other address + */ + @Override + public void changeOtherAddress () { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Allows the user to change his/her own data + */ + @Override + public void changeOwnData () { + /* + * 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."); + + // Skip any below code + return; + } + + // Instance + Contact contact = this.getOwnContact(); + + // It must be found + assert(contact instanceof Contact); + + // Display contact + contact.show(this.getClient()); + + try { + // Ask user what to change + this.getClient().userChooseChangeContactData(contact); + } catch (final UnhandledUserChoiceException ex) { + this.getLogger().catching(ex); + } + } + + /** + * Let the user delete other address + */ + @Override + public void deleteOtherAddress () { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Let the user change address data + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + @Override + public void doChangeAddressData (final Contact contact, final Client client) { + // First display it again + client.displayAddressBox(contact); + + // Is it own data? + if (contact.isOwnContact()) { + // Deligate to client + this.getClient().doChangeOwnAddressData(contact); + } else { + // Other contact's address data to change + throw new UnsupportedOperationException("Changing contact entries not finished."); + } + + // Flush whole list + this.flush(); + } + + /** + * Let the user change "name data" + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + @Override + public void doChangeNameData (final Contact contact, final Client client) { + // First display them again + client.displayNameBox(contact); + + // Is this own data? + if (contact.isOwnContact()) { + // Re-ask own data + this.getClient().doChangeOwnNameData(contact); + } else { + // Then re-ask them ... + throw new UnsupportedOperationException("Changing contact entries not finished."); + } + + // Flush whole list + this.flush(); + } + + /** + * Let the user change other data + * + * @param contact Instance to change data + * @param client Client instance to call back + * @todo Didn't handle birthday + */ + @Override + public void doChangeOtherData (final Contact contact, final Client client) { + // First display them again + this.getClient().displayOtherDataBox(contact); + + // Is this own data? + if (contact.isOwnContact()) { + // Re-ask own data + this.getClient().doChangeOwnOtherData(contact); + } else { + // Then re-ask them ... + throw new UnsupportedOperationException("Changing contact entries not finished."); + } + + // Flush whole list + this.flush(); + } + + /** + * Asks user for own data + */ + @Override + public void doEnterOwnData () { + // Deligate this call to the client + Contact contact = this.getClient().doEnterOwnData(); + + // Add it to contact "book" + this.registerContact(contact); + } + + /** + * Shuts down this contact manager + */ + @Override + public void doShutdown () { + // Shut down the database layer + this.getContactDatabase().doShutdown(); + } + + /** + * Asks the user for his/her cellphone number + * + * @return User's cellphone number + */ + @Override + public String enterOwnCellNumber () { + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true); + } + + /** + * Asks the user for his/her city's name + * + * @return City's name of the user + */ + @Override + public String enterOwnCity () { + return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false); + } + + /** + * Asks the user for his/her city's name + * + * @return City's name of the user + */ + @Override + public String enterOwnComment () { + return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true); + } + + /** + * Asks the user for his/her company name + * + * @return User's company name + */ + @Override + public String enterOwnCompanyName () { + return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true); + } + + /** + * Asks user for his/her own country code + * + * @return User's own country code + */ + @Override + public String enterOwnCountryCode () { + return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase(); + } + + /** + * Asks user for his/her own country code + * + * @return User's own country code + */ + @Override + public String enterOwnEmailAddress () { + return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true); + } + + /** + * Asks the user for family name + * + * @return Family name of the user + */ + @Override + public String enterOwnFamilyName () { + return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false); + } + + /** + * Asks the user for family name + * + * @return Family name of the user + */ + @Override + public String enterOwnFaxNumber () { + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true); + } + + /** + * Asks the user for gender, until a valid has been entered + * + * @return Gender of the user + */ + @Override + public char enterOwnGender () { + return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): "); + } + + /** + * Asks the user for phone number + * + * @return Phone number of the user + */ + @Override + public String enterOwnPhoneNumber () { + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true); + } + + /** + * Asks the user for own street (including number) + * @return Own street an number + */ + @Override + public String enterOwnStreet () { + return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false); + } + + /** + * Asks the user for surname + * @return Surname of the user + */ + @Override + public String enterOwnSurname () { + return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false); + } + + /** + * Asks the user for own ZIP code + * + * @return ZIP code + */ + @Override + public int enterOwnZipCode () { + return this.getClient().enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: "); + } + + @Override + public final int getColumnCount () { + return this.columnNames.size(); + } + + /** + * Getter for whole contact list + * + * @return List of all contacts + */ + @Override + public List getList () { + return Collections.unmodifiableList(this.contacts); + } + + /** + * Checks whether own contact is already added by checking all entries for + * isOwnContact flag + * + * @return Whether own contact is already added + */ + @Override + public boolean isOwnContactAdded () { + // Default is not added + boolean isAdded = false; + + // Now get it back from address book, first get an iterator + Iterator iterator = this.contacts.iterator(); + + // Check entries + while (iterator.hasNext()) { + // Get next entry + Contact contact = iterator.next(); + + // Is it valid? + if (contact instanceof Contact) { + // Get flag + isAdded = contact.isOwnContact(); + + // Is this own contact? + if (isAdded) { + // Then abort loop + break; + } + } + } + // Return result + return isAdded; + } + + @Override + public void listContacts () { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Adds given contact to address book and flushes all entries to database + * + * @param contact Contact being added + * @todo Add check for book size + */ + @Override + public void registerContact (final Contact contact) { + // Check if contact is found + if (this.isContactAlreadyAdded(contact)) { + // Contact already added + // @todo Do something here + } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) { + // Own contact already added + // @todo Do something + } + + // Debug message + /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); + + // Add contact to internal list + this.addContact(contact); + + // Flush whole list + this.flush(); + } + + @Override + public void searchContacts () { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * Getter for size + * + * @return size of contact "book" + */ + @Override + public final int size () { + return this.contacts.size(); + } + + /** + * Fills the column names array with strings from bundle + */ + private void fillColumnNamesFromBundle () { + // Debug message + this.getLogger().trace("CALLED!"); + + // 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(); + + // Does the key start with ContactManager.columnName ? + if (key.startsWith("ContactM,anager.columnName")) { + // This is the wanted entry. + this.getLogger().debug(MessageFormat.format("key={0}", key)); + + // So add it + this.columnNames.add(this.getBundle().getString(key)); + } + } + + // Debug message + this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); + } + + /** + * Flushes all entries by calling database backend + */ + private void flush () { + // Flusgh all + this.getContactDatabase().flushAllContacts(); + } + + /** + * A ContactWrapper instance + * + * @return the database + */ + private ContactWrapper getContactDatabase () { + return this.contactDatabase; + } + + /** + * "Getter" for own contact instance or null if not found + * + * @return Contact instance or null + */ + private Contact getOwnContact () { + // Now get it back from address book, first get an iterator + Iterator iterator = this.contacts.iterator(); + + // Init instance + Contact contact = null; + + // Search all contact + while (iterator.hasNext()) { + // Get next instance + Contact next = iterator.next(); + + // Is this own contact? + if (next.isOwnContact()) { + // Found it + contact = next; + break; + + } + } + + // Return instance or null + return contact; + } + + /** + * Checks whether given contact was found in "address book" + * + * @param checkContact Contact to be checked + * @return TRUE if found, FALSE if not found + */ + private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException { + // Default is not found + boolean isFound = false; + + // Debug message + //* NOISY-DEBUG: */ this.getLogger().debug("Checking '" + this.contacts.length + "' entries..."); + + // Now get it back from address book, first get an iterator + Iterator iterator = this.contacts.iterator(); + + // Check entries + while (iterator.hasNext()) { + // Get next entry + Contact contact = iterator.next(); + + // Debug message + //* NOISY-DEBUG: */ this.getLogger().debug("contact=" + contact + ",checkContent=" + checkContact); + + // Is it valid? + if ((contact instanceof Contact) && ((contact.equals(checkContact)))) { + // Found matching entry + isFound = true; + break; + } + } + + // Return result + return isFound; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java index 37f9c7c..82dd838 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java @@ -1,89 +1,89 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.menu.item.console; - -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.item.BaseMenuItem; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - */ -public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem { - /** - * Access key - */ - private char accessKey; - - /** - * Text to user - */ - private String text; - - /** - * Constructor for building a console menu with access key and text - * - * @param accessKey Access key for this menu entry - * @param text Text to show to user - */ - public ConsoleMenuItem (final char accessKey, final String text) { - this.accessKey = accessKey; - this.text = text; - } - - /** - * Access key - * @return the accessKey - */ - @Override - public char getAccessKey () { - return this.accessKey; - } - - /** - * Access key - * @param accessKey the accessKey to set - */ - private void setAccessKey (char accessKey) { - this.accessKey = accessKey; - } - - /** - * Text to user - * @return the text - */ - @Override - public String getText () { - return this.text; - } - - /** - * Text to user - * @param text the text to set - */ - private void setText (String text) { - this.text = text; - } - - @Override - public void show (final Client client) { - // Call-back client over menu - client.showEntry(this); - } - -} +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.menu.item.console; + +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.menu.item.BaseMenuItem; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * + * @author Roland Haeder + */ +public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem { + /** + * Access key + */ + private char accessKey; + + /** + * Text to user + */ + private String text; + + /** + * Constructor for building a console menu with access key and text + * + * @param accessKey Access key for this menu entry + * @param text Text to show to user + */ + public ConsoleMenuItem (final char accessKey, final String text) { + this.accessKey = accessKey; + this.text = text; + } + + /** + * Access key + * @return the accessKey + */ + @Override + public final char getAccessKey () { + return this.accessKey; + } + + /** + * Text to user + * @return the text + */ + @Override + public String getText () { + return this.text; + } + + @Override + public void show (final Client client) { + // Call-back client over menu + client.showEntry(this); + } + + /** + * Text to user + * @param text the text to set + */ + private void setText (String text) { + this.text = text; + } + + /** + * Access key + * @param accessKey the accessKey to set + */ + private void setAccessKey (char accessKey) { + this.accessKey = accessKey; + } + +} -- 2.39.5