From: Roland Haeder Date: Thu, 23 Jul 2015 07:08:58 +0000 (+0200) Subject: Bah, bad bad NetBeans. Why the f**k does it need to have a sub directory??? Why not... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=00c8762778cdc63923406bb356f3c922326a8030;p=jfinancials-swing.git Bah, bad bad NetBeans. Why the f**k does it need to have a sub directory??? Why not plainly in main directory? But who knows ... Signed-off-by: Roland Häder --- diff --git a/.gitignore b/.gitignore index d401dc5..bf94222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/nbproject/ -/manifest.mf -/build/ -/data/*.* -/dist/ +/Addressbook/nbproject/ +/Addressbook/manifest.mf +/Addressbook/build/ +/Addressbook/data/*.* +/Addressbook/dist/ diff --git a/Addressbook/build.xml b/Addressbook/build.xml new file mode 100644 index 0000000..c24405d --- /dev/null +++ b/Addressbook/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Addressbook. + + + diff --git a/Addressbook/lib/log4j-api-2.3.jar b/Addressbook/lib/log4j-api-2.3.jar new file mode 100644 index 0000000..2a61bbe Binary files /dev/null and b/Addressbook/lib/log4j-api-2.3.jar differ diff --git a/Addressbook/lib/log4j-core-2.3.jar b/Addressbook/lib/log4j-core-2.3.jar new file mode 100644 index 0000000..5438b0b Binary files /dev/null and b/Addressbook/lib/log4j-core-2.3.jar differ diff --git a/Addressbook/src/log4j2.xml b/Addressbook/src/log4j2.xml new file mode 100644 index 0000000..65614c6 --- /dev/null +++ b/Addressbook/src/log4j2.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/Addressbook/src/org/mxchange/addressbook/BadTokenException.java b/Addressbook/src/org/mxchange/addressbook/BadTokenException.java new file mode 100644 index 0000000..ce02e50 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/BadTokenException.java @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * + * @author Roland Haeder + */ +public class BadTokenException extends Exception { + + public BadTokenException (final String str) { + super(str); + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java new file mode 100644 index 0000000..e34fe66 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java @@ -0,0 +1,156 @@ +/* + * 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; + +import java.util.ResourceBundle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.manager.contact.ManageableContact; + +/** + * General class + * + * @author Roland Haeder + */ +public class BaseFrameworkSystem implements FrameworkInterface { + /** + * Class' logger + */ + private final Logger LOG; + + /** + * Application instance + */ + private Application application; + + /** + * Client instance + */ + private Client client; + + /** + * Contact manager instance + */ + private ManageableContact contactManager; + + /** + * Name of used database table, handled over to backend + */ + private String tableName; + + /** + * Bundle instance + */ + private final ResourceBundle bundle; + + /** + * Initialize object + */ + { + LOG = LogManager.getLogger(this); + bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N + } + + /** + * No instances can be created of this class + */ + protected BaseFrameworkSystem () { + } + + /** + * Application instance + * + * @return the application + */ + @Override + public final Application getApplication () { + return this.application; + } + + /** + * Client instance + * + * @return the client + */ + @Override + public final Client getClient () { + return this.client; + } + + /** + * Contact manager instance + * @return the contactManager + */ + @Override + public final ManageableContact getContactManager () { + return this.contactManager; + } + + /** + * Contact manager instance + * @param contactManager the contactManager to set + */ + protected final void setContactManager (final ManageableContact contactManager) { + this.contactManager = contactManager; + } + + /** + * Client instance + * @param client the client to set + */ + protected final void setClient (final Client client) { + this.client = client; + } + + /** + * Application instance + * + * @param application the application to set + */ + protected final void setApplication(final Application application) { + this.application = application; + } + + /** + * Getter for logger + * + * @return Logger + */ + protected final Logger getLogger () { + return this.LOG; + } + + /** + * Name of used database table, handled over to backend + * + * @return the tableName + */ + protected final String getTableName () { + return this.tableName; + } + + /** + * Name of used database table, handled over to backend + * + * @param tableName the tableName to set + */ + protected final void setTableName (final String tableName) { + this.tableName = tableName; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java new file mode 100644 index 0000000..ae1c570 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 KLC + * + * 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; + +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.manager.contact.ManageableContact; + +/** + * + * @author KLC + */ +public interface FrameworkInterface { + + /** + * Getter for contact manager + * @return Contact manager instance + */ + public ManageableContact getContactManager(); + + /** + * Client instance + * + * @return the client + */ + public Client getClient (); + + /** + * Application instance + * + * @return the application + */ + public Application getApplication (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/UnhandledUserChoiceException.java b/Addressbook/src/org/mxchange/addressbook/UnhandledUserChoiceException.java new file mode 100644 index 0000000..e97f20a --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/UnhandledUserChoiceException.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * This exception is thrown when the user made a valid choice but it was not + * handled by the program. + * + * @author Roland Haeder + */ +public class UnhandledUserChoiceException extends Exception { + + public UnhandledUserChoiceException (final String message) { + super(message); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java new file mode 100644 index 0000000..788c940 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -0,0 +1,327 @@ +/* + * 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); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/application/Application.java b/Addressbook/src/org/mxchange/addressbook/application/Application.java new file mode 100644 index 0000000..aa773e5 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/application/Application.java @@ -0,0 +1,40 @@ +/* + * 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 org.mxchange.addressbook.FrameworkInterface; + +/** + * + * @author Roland Haeder + */ +public interface Application extends FrameworkInterface { + /** + * Bootstraps the application + */ + public void doBootstrap(); + + /** + * Run the main loop + */ + public void doMainLoop(); + + /** + * Shutdown the application + */ + public void doShutdown (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java new file mode 100644 index 0000000..0282c91 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java @@ -0,0 +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 void enableIsRunning () { + this.isRunning = true; + } + + /** + * Current menu choice + * + * @return the currentMenu + */ + public String getCurrentMenu () { + return this.currentMenu; + } + + /** + * Current menu choice + * @param currentMenu the currentMenu to set + */ + public void setCurrentMenu (final String currentMenu) { + this.currentMenu = currentMenu; + } + + /** + * "Getter" for given menu type + * + * @param menuType Menu type instance to return + * @return Menu or null if not found + */ + 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 boolean isRunning () { + // In console client, 0 may have been used + return this.isRunning; + } + + /** + * Disables running state, so the main loop can abort. + */ + protected 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/Client.java b/Addressbook/src/org/mxchange/addressbook/client/Client.java new file mode 100644 index 0000000..136c95a --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/Client.java @@ -0,0 +1,189 @@ +/* + * 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 org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * An interface for application clients + * + * @author Roland Haeder + */ +public interface Client extends FrameworkInterface { + + /** + * Displays a "box" for the address + * + * @param contact Contact to show address from + */ + public void displayAddressBox (final Contact contact); + + /** + * The user changes own name data + * @param contact + */ + public void doChangeOwnNameData (final Contact contact); + + /** + * The user changes own address data + * + * @param contact Contact instance to change + */ + public void doChangeOwnAddressData (final Contact contact); + + /** + * The user changes own other data + * + * @param contact Constact instance to change + */ + public void doChangeOwnOtherData (final Contact contact); + + /** + * Allows the user to enter own data + * + * @return Finished Contact instance + */ + public Contact doEnterOwnData (); + + /** + * Shuts down the client and therefore whole application + */ + public void doShutdown (); + + /** + * Displays a message to the user + * + * @param message Message to show to the user + */ + public void outputMessage (final String message); + + /** + * Displays a "box" for the name + * + * @param contact Contact to show name from + */ + public void displayNameBox (final Contact contact); + + /** + * Displays a "box" for other data + * + * @param contact Contact to show other data from + */ + public void displayOtherDataBox (final Contact contact); + + /** + * Let the user choose what to change on the address: [n]ame, [a]ddress, + * [o]ther + * + * @param contact Contact instance to let the user change data + * @throws UnhandledUserChoiceException If choice is not supported + */ + public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException; + + /** + * Asks the user for a choice and proceeds accordingly + * + * @throws UnhandledUserChoiceException If choice is not supported + */ + public void doUserMenuChoice () throws UnhandledUserChoiceException ; + + /** + * Enables isRunning attribute which singals that the client is running + */ + public void enableIsRunning(); + + /** + * Asks the the user to enter a single character which must match validChars + * + * @param validChars Valid chars that are accepted + * @param message Message to user + * @return Allowed character + */ + public char enterChar (final char[] validChars, final String message); + + /** + * Reads a string of minimum and maximum length from the user. An empty + * string should be generally not allowed, but might be okay for e.g. + * company name. + * + * @param minLength Minimum length of the string to read + * @param maxLength Maximum length of the string to read + * @param message Message to user + * @param allowEmpty Whether empty strings are allowed + * @return Entered string by user or null if empty string is allowed + */ + public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty); + + /** + * Reads an integer (int) from the user + * + * @param minimum Minimum allowed number + * @param maximum Maximum allowed number + * @param message Message to user + * @return Entered string by user or null if empty string is allowed + */ + public int enterInt (final int minimum, final int maximum, final String message); + + /** + * Setter for current menu choice + * + * @param currentMenu Current menu choice + */ + public void setCurrentMenu (final String currentMenu); + + /** + * Some "Getter" for menu item + * + * @param accessKey Key to press to access this menu + * @param text Text to show to user + * @return + */ + public SelectableMenuItem getMenuItem (final char accessKey, final String text); + + /** + * Determines whether the client is still active by checking some + * conditions + * + * @return Whether the client is still active + */ + public boolean isRunning(); + + /** + * Shows given menu entry in client + * + * @param item Menu item to show + */ + public void showEntry (final SelectableMenuItem item); + + /** + * Shows introduction to user + */ + public void showWelcome(); + + /** + * Shows current menu selection to the user + */ + public void showCurrentMenu(); + + /** + * Inizializes this client + */ + public void initClient (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java new file mode 100644 index 0000000..b97600e --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -0,0 +1,505 @@ +/* + * 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.console; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Scanner; +import org.mxchange.addressbook.UnhandledUserChoiceException; +import org.mxchange.addressbook.application.AddressbookApplication; +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.contact.user.UserContact; +import org.mxchange.addressbook.menu.Menu; +import org.mxchange.addressbook.menu.MenuTools; +import org.mxchange.addressbook.menu.console.ConsoleMenu; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; +import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; + +/** + * A client for the console + * + * @author Roland Haeder + */ +public class ConsoleClient extends BaseClient implements Client { + /** + * Scanner instance for reading data from console input + */ + private final Scanner scanner; + + /** + * Parameterless constructor + * @param application An instance of an Application class + */ + public ConsoleClient (final Application application) { + super(); + + // Set application instance + this.setApplication(application); + + // Init scanner instance + this.scanner = new Scanner(System.in); + } + + /** + * Displays a textual address "box" of given contact + * + * @param contact Contact to show address for + */ + @Override + public void displayAddressBox (final Contact contact) { + // Simple display ... + this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode())); + } + + /** + * Displays a textual name "box" of given contact + * + * @param contact Contact to show name for + */ + @Override + public void displayNameBox (final Contact contact) { + // Get translated gender as the user may want to see "Mr.", "Mrs." + String gender = contact.getTranslatedGender(); + + // Get company name + String companyName = contact.getCompanyName(); + + // If it is empty/null, then assume private contact + if ((companyName == null) || (companyName.isEmpty())) { + // Now put all together: gender, surname, family name + // @todo Use mask + this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName())); + } else { + // Company contact + this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName())); + } + } + + /** + * Displays a textual other data "box" of given contact + * + * @param contact Contact to show other data for + */ + @Override + public void displayOtherDataBox (final Contact contact) { + // Cellphone and such ... + this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment())); + } + + @Override + public void doChangeOwnAddressData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Own address data + String street = this.getContactManager().enterOwnStreet(); + + // Get zip code + int zipCode = this.getContactManager().enterOwnZipCode(); + + // Get city name + String city = this.getContactManager().enterOwnCity(); + + // Get country code + String countryCode = this.getContactManager().enterOwnCountryCode(); + + // Update address data + contact.updateAddressData(street, zipCode, city, countryCode); + } + + @Override + public void doChangeOwnNameData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Gender: + char gender = this.getContactManager().enterOwnGender(); + + // Surname + String surname = this.getContactManager().enterOwnSurname(); + + // Family name + String familyName = this.getContactManager().enterOwnFamilyName(); + + // And company + String companyName = this.getContactManager().enterOwnCompanyName(); + + // Update contact instance + contact.updateNameData(gender, surname, familyName, companyName); + } + + @Override + public void doChangeOwnOtherData (final Contact contact) { + // Make sure it is own contact + if (!contact.isOwnContact()) { + // Not own contact + throw new IllegalArgumentException("Contact is not own data."); + } + + // Phone number + String phoneNumber = this.getContactManager().enterOwnPhoneNumber(); + + // Phone number + String cellNumber = this.getContactManager().enterOwnCellNumber(); + + // Fax number + String faxNumber = this.getContactManager().enterOwnFaxNumber(); + + // Email address + String email = this.getContactManager().enterOwnEmailAddress(); + + // Comment + String comment = this.getContactManager().enterOwnComment(); + + // Update contact instance + contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment); + } + + @Override + public Contact doEnterOwnData () { + // First ask for gender + char gender = this.getContactManager().enterOwnGender(); + + // 2nd for surname + String surname = this.getContactManager().enterOwnSurname(); + + // And 3rd for family name + String familyName = this.getContactManager().enterOwnFamilyName(); + + // Company name ... + String companyName = this.getContactManager().enterOwnCompanyName(); + + // Construct UserContact instance + Contact contact = new UserContact(gender, surname, familyName, companyName); + + // And return object + return contact; + } + + /** + * Shutdown this client + */ + @Override + public void doShutdown () { + // Parent call + super.doShutdown(); + + // @TODO Add other shutdown stuff + } + + @Override + public void doUserMenuChoice () throws UnhandledUserChoiceException { + // Get all access keys from menu + char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu()); + + // Output textural message and ask for a char as input + char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); + + // @TODO Rewrite this ugly switch() block + switch (choice) { + case '1': // Enter/add own data + this.getContactManager().doEnterOwnData(); + break; + + case '2': // Change own data + this.getContactManager().changeOwnData(); + break; + + case '3': // Add new addess + this.getContactManager().addOtherAddress(); + break; + + case '4': // List contacts + this.getContactManager().listContacts(); + break; + + case '5': // Search addresses + this.getContactManager().searchContacts(); + break; + + case '6': // Change other addess + this.getContactManager().changeOtherAddress(); + break; + + case '7': // Delete other address + this.getContactManager().deleteOtherAddress(); + break; + + case '0': // Program exit + this.getApplication().doShutdown(); + break; + + default: + // @TODO throw own exception + throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); + } + } + + /** + * Asks the the user to enter a single character which must match validChars + * @param validChars Valid chars that are accepted + * @param message Message to user + * @return Allowed character + */ + @Override + public char enterChar (final char[] validChars, final String message) { + char input = 0; + + // Sort array, else binarySearch() won't work + Arrays.sort(validChars); + + // Keep asking until valid char has been entered + while (Arrays.binarySearch(validChars, input) < 0) { + // Output message + System.out.print(message); + + // Read char + input = this.readChar(); + } + + // Return read char + return input; + } + + /** + * Reads an integer (int) with a textural message from the user + * + * @param minimum Minimum allowed number + * @param maximum Maximum allowed number + * @param message Messager to display in console + * @return + */ + @Override + public int enterInt (final int minimum, final int maximum, final String message) { + // Minimum should not be below zero + assert(minimum >= 0); + assert(maximum > minimum); + + // Init input + int input = -1; + + while ((input < minimum) || (input > maximum)) { + // Output message + System.out.print(message); + + // Read integer from user + input = this.readInt(); + } + + // Return it + return input; + } + + /** + * Reads a string of minimum and maximum length from the user + * + * @param minLength Minimum length of the string to read + * @param maxLength Maximum length of the string to read + * @param message Message to user + * @param allowEmpty Whether to allow empty string + * @return Entered string by user or null for empty strings + */ + @Override + public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { + // Check on length, e.g. country codes are excactly 2 chars long + assert(maxLength >= minLength); + + // Init input + String input = null; + + // Check if it is to short or to long + while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) { + // Output message + System.out.print(message); + + // Read line + input = this.readString(); + } + + // Return it + return input; + } + + /** + * Returns a console menu item + * + * @param accessKey Key to access the menu + * @param text Text to show to user + * @return A SelectableMenuItem + * @todo Make sure the access key is unique + */ + @Override + public SelectableMenuItem getMenuItem (final char accessKey, final String text) { + // Return a new console menu item + return new ConsoleMenuItem(accessKey,text); + } + + /** + * Inizializes this client + */ + @Override + public void initClient () { + // Init contact manager here + this.initContactManager(); + + // Fill menu map + this.fillMenuMap(); + } + + /** + * Displays textural message to the user + * @param message + */ + @Override + public void outputMessage (final String message) { + System.out.println(message); + } + + /** + * Shows textural menu on console + */ + @Override + public void showCurrentMenu () { + this.showMenu(this.getCurrentMenu()); + } + + /** + * Shows given menu entry to user + * + * @param item Menu entry + */ + @Override + public void showEntry (final SelectableMenuItem item) { + // Access key then text + this.outputMessage("[" + item.getAccessKey() + "] " + item.getText()); + } + + /** + * Shows a textural message to the user + */ + @Override + public void showWelcome () { + this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle())); + this.outputMessage(""); + this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software"); + + // Debug message + this.getLogger().debug("Intro shown to user"); + } + + @Override + public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { + // Ask the user for editing [name], [a]ddress or [other] data + char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) "); + + // @TODO Get rid of this ugly switch block, too + switch (choice) { + case 'n': // Name data + this.getContactManager().doChangeNameData(contact, this); + break; + + case 'a': // Address data + this.getContactManager().doChangeAddressData(contact, this); + break; + + case 'o': // Other data + this.getContactManager().doChangeOtherData(contact, this); + break; + + case 'x': // Exit this menu + // Ignored as it should go back + break; + + default: + // @TODO throw own exception + throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); + } + } + + /** + * Reads one character + * + * @return A single character + */ + private char readChar () { + // Read line + String input = this.scanner.nextLine(); + + // This must be only one character + if (input.length() != 1) { + // Return zero + return 0; + } + + // Get char from first (and only) position + return input.charAt(0); + } + + /** + * Reads an integer (int) from user + * + * @return An integer number + */ + private int readInt () { + // First read a string + String input = this.readString(); + + // Init number with invalid value + int num = -1; + + // Parse number, this can be risky + try { + num = Integer.parseInt(input); + } catch (final NumberFormatException e) { + this.outputMessage("Bitte geben Sie nur Zahlen ein!"); + this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); + } + + // Return read number + return num; + } + + /** + * Reads a string from a scanner until RETURN is pressed + * + * @return Read string from scanner + */ + private String readString () { + return this.scanner.nextLine(); + } + + /** + * Fills menu map with menu entries + */ + @Override + protected final void fillMenuMap () { + // Initialize first (main) menu + Menu menu = new ConsoleMenu("main", this); + + // Add it + this.getMenus().put("main", menu); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form new file mode 100644 index 0000000..d6899f3 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form @@ -0,0 +1,197 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java new file mode 100644 index 0000000..451d525 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -0,0 +1,355 @@ +/* + * 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.Color; +import java.awt.Cursor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ResourceBundle; +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.GroupLayout; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.KeyStroke; +import javax.swing.LayoutStyle; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.WindowConstants; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.mxchange.addressbook.application.AddressbookApplication; +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.manager.contact.ManageableContact; +import org.mxchange.addressbook.model.address.AddressTableModel; + +/** + * + * @author Roland Haeder + */ +public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame { + /** + * Class' logger + */ + private final Logger LOG; + + /** + * Client instance + */ + private final Client client; + + /** + * Own instance + */ + private static ClientFrame self; + + /** + * Bundle instance + */ + private final ResourceBundle bundle; + + /** + * Initialize object + */ + { + LOG = LogManager.getLogger(this); + bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N + } + + /** + * Creates an instance of this frame with a client instance + * @param client + */ + private AddressbookFrame (final Client client) { + // Debug line + this.getLogger().debug("Initializing Swing frame ..."); + + // Set client here + this.client = client; + } + + @Override + public Application getApplication () { + throw new UnsupportedOperationException("Not implemented."); + } + + @Override + public final Client getClient () { + return this.client; + } + + @Override + public ManageableContact getContactManager () { + throw new UnsupportedOperationException("Not implemented."); + } + + @Override + public void initFrame () { + // Init components + this.initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings ("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + statusPanel = new JPanel(); + statusLabel = new JLabel(); + listAddressesPanel = new JScrollPane(); + addressesTable = new JTable(); + toolBar = new JToolBar(); + menuBar = new JMenuBar(); + mainMenu = new JMenu(); + exitProgram = new JMenuItem(); + addressbookMenu = new JMenu(); + addOwnData = new JMenuItem(); + + setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + setTitle(AddressbookApplication.printableTitle()); + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + setName("main"); // NOI18N + addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent evt) { + exitProgram(evt); + } + public void windowClosing(WindowEvent evt) { + AddressbookFrame.this.windowClosing(evt); + } + }); + + statusPanel.setBorder(BorderFactory.createEtchedBorder(Color.lightGray, new Color(153, 153, 153))); + statusPanel.setAutoscrolls(true); + statusPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + statusPanel.setFocusable(false); + statusPanel.setName("status"); // NOI18N + statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); + + ResourceBundle bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N + statusLabel.setText(bundle.getString("AddressbookFrame.statusLabel.text_1")); // NOI18N + statusLabel.setHorizontalTextPosition(SwingConstants.LEFT); + statusLabel.setName("statusLabel"); // NOI18N + statusPanel.add(statusLabel); + + listAddressesPanel.setName("listAddressesPanel"); // NOI18N + + addressesTable.setModel(new AddressTableModel(this.getClient())); + addressesTable.setColumnSelectionAllowed(true); + addressesTable.setFillsViewportHeight(true); + addressesTable.setFocusable(false); + addressesTable.setName("addressesTable"); // NOI18N + listAddressesPanel.setViewportView(addressesTable); + addressesTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + + toolBar.setFloatable(false); + toolBar.setRollover(true); + toolBar.setName("toolBar"); // NOI18N + + menuBar.setName("menuBar"); // NOI18N + + ResourceBundle bundle1 = ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N + mainMenu.setText(bundle1.getString("AddressbookFrame.text")); // NOI18N + mainMenu.setFocusable(false); + mainMenu.setName(""); // NOI18N + + exitProgram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK)); + exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text_1")); // NOI18N + exitProgram.setName("exitProgram"); // NOI18N + exitProgram.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + exitProgramActionPerformed(evt); + } + }); + mainMenu.add(exitProgram); + + menuBar.add(mainMenu); + + addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text_1")); // NOI18N + addressbookMenu.setName("addressbookMenu"); // NOI18N + + addOwnData.setText(bundle1.getString("AddressbookFrame.addOwn.text")); // NOI18N + addOwnData.setName("addOwn"); // NOI18N + addOwnData.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + addOwnDataActionPerformed(evt); + } + }); + addressbookMenu.add(addOwnData); + addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1")); // NOI18N + + menuBar.add(addressbookMenu); + + setJMenuBar(menuBar); + + GroupLayout layout = new GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(statusPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(listAddressesPanel, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE) + .addComponent(toolBar, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(toolBar, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(listAddressesPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGap(1, 1, 1) + .addComponent(statusPanel, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)) + ); + + statusPanel.getAccessibleContext().setAccessibleName(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N + statusPanel.getAccessibleContext().setAccessibleDescription(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleDescription")); // NOI18N + + pack(); + }// //GEN-END:initComponents + + private void exitProgramActionPerformed(ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed + // Close application instance + dispose(); + }//GEN-LAST:event_exitProgramActionPerformed + + private void addOwnDataActionPerformed(ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed + // Asks the user to enter own data + this.getClient().getContactManager().doEnterOwnData(); + }//GEN-LAST:event_addOwnDataActionPerformed + + private void windowClosing(WindowEvent evt) {//GEN-FIRST:event_windowClosing + // TODO add your handling code here: + dispose(); + }//GEN-LAST:event_windowClosing + + private void exitProgram(WindowEvent evt) {//GEN-FIRST:event_exitProgram + // TODO add your handling code here: + this.getClient().getApplication().doShutdown(); + }//GEN-LAST:event_exitProgram + + /** + * Setups the frame + * + * @param client Client instance + */ + @Override + public void setupFrame (final Client 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); + } + + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (final ClassNotFoundException ex) { + this.getLogger().catching(ex); + } catch (final InstantiationException ex) { + this.getLogger().catching(ex); + } catch (final IllegalAccessException ex) { + this.getLogger().catching(ex); + } catch (final javax.swing.UnsupportedLookAndFeelException ex) { + this.getLogger().catching(ex); + } + // + + // All done here + statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text")); + + // Debug line + this.getLogger().debug("Displaying form ..."); + + /* + * Create and display the form + */ + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run () { + AddressbookFrame.getSelfInstance(client).setVisible(true); + } + }); + } + + /** + * 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; + } + + /** + * Getter for logger + * + * @return Logger + */ + protected final Logger getLogger () { + return this.LOG; + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private JMenuItem addOwnData; + private JMenu addressbookMenu; + private JTable addressesTable; + private JMenuItem exitProgram; + private JScrollPane listAddressesPanel; + private JMenu mainMenu; + private JMenuBar menuBar; + private JLabel statusLabel; + private JPanel statusPanel; + private JToolBar toolBar; + // End of variables declaration//GEN-END:variables +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java new file mode 100644 index 0000000..17318d4 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -0,0 +1,47 @@ +/* + * 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.FrameworkInterface; +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public interface ClientFrame extends FrameworkInterface { + + /** + * From JFrame + * + * @param visible Set visibility + */ + public void setVisible (boolean visible); + + /** + * 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 + */ + public void initFrame (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java new file mode 100644 index 0000000..9ea4e88 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -0,0 +1,181 @@ +/* + * 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.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(); + + // Init frame + this.frame.initFrame(); + + // 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."); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java new file mode 100644 index 0000000..78d4f07 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -0,0 +1,600 @@ +/* + * 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.contact; + +import java.util.Objects; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.client.Client; + +/** + * A general contact + * + * @author Roland Haeder + * @version 0.0 + * @since 0.0 + */ +public class BaseContact extends BaseFrameworkSystem { + /** + * Amount of columns + */ + public static final int COLUMN_COUNT = 14; + + /** + * Birth day + */ + private String birthday; + + /** + * Cellphone number + */ + private String cellphoneNumber; + + /** + * City + */ + private String city; + + /** + * Optional comments + */ + private String comment; + + /** + * Companyname + */ + private String companyName; + + /** + * Country code + */ + private String countryCode; + + /** + * Email address + */ + private String emailAddress; + + /** + * Family name + */ + private String familyName; + + /** + * Fax number + */ + private String faxNumber; + + /** + * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C = + * Company + */ + private char gender; + + /** + * House number + */ + private int houseNumber; + + /** + * Marker whether this contact is user's own data + */ + private boolean ownContact; + + /** + * Phone number + */ + private String phoneNumber; + + /** + * Street + */ + private String street; + + /** + * Surname + */ + private String surname; + + /** + * ZIP code + */ + private long zipCode; + + /** + * No instances can be created of this class + */ + protected BaseContact () { + super(); + } + + /** + * Check if contacts are same or throw an exception + * + * @param object Other possible contact class + * @return Whether both contacts are same + * @todo Needs a lot improvements + */ + @Override + public boolean equals (Object object) { + // Is it same type? + if (!(object instanceof BaseContact)) { + // Not equal types + return false; + } else if (!(object instanceof Contact)) { + // Not correct interface + return false; + } + + // Try to cast + Contact contact = (Contact) object; + + // Now test some data @todo Definedly needs improvement + return ((this.getGender() == contact.getGender()) + && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase())) + && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); + } + + /** + * Birth day + * + * @return the birthday + */ + public String getBirthday () { + return this.birthday; + } + + /** + * Birth day + * + * @param birthday the birthday to set + */ + public void setBirthday (final String birthday) { + this.birthday = birthday; + } + + /** + * Cellphone number + * + * @return the cellphoneNumber + */ + public String getCellphoneNumber () { + return this.cellphoneNumber; + } + + /** + * Cellphone number + * + * @param cellphoneNumber the cellphoneNumber to set + */ + public void setCellphoneNumber (final String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + /** + * City + * + * @return the city + */ + public String getCity () { + return this.city; + } + + /** + * City + * + * @param city the city to set + */ + public void setCity (final String city) { + this.city = city; + } + + /** + * Comments + * + * @return the comment + */ + public String getComment () { + return this.comment; + } + + /** + * Comments + * + * @param comment the comment to set + */ + public void setComment (final String comment) { + this.comment = comment; + } + + /** + * Companyname + * + * @return the companyName + */ + public String getCompanyName () { + return this.companyName; + } + + /** + * Companyname + * + * @param companyName the companyName to set + */ + public void setCompanyName (final String companyName) { + this.companyName = companyName; + } + + /** + * Country code + * + * @return the countryCode + */ + public String getCountryCode () { + return this.countryCode; + } + + /** + * Country code + * + * @param countryCode the countryCode to set + */ + public void setCountryCode (final String countryCode) { + this.countryCode = countryCode; + } + + /** + * "Serializes" this object into a CSV string (this time with semicolons) + * + * @return "CSV-serialized" version of the stored data + */ + public String getCsvStringFromStoreableObject () { + // Get all together + String csvString = String.format( + "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n", + this.isOwnContact(), + this.getGender(), + this.getSurname(), + this.getFamilyName(), + this.getCompanyName(), + this.getStreet(), + this.getZipCode(), + this.getCity(), + this.getCountryCode(), + this.getPhoneNumber(), + this.getFaxNumber(), + this.getCellphoneNumber(), + this.getEmailAddress(), + this.getBirthday(), + this.getComment() + ); + + // Then return it + return csvString; + } + + /** + * Email address + * + * @return the emailAddress + */ + public String getEmailAddress () { + return this.emailAddress; + } + + /** + * Email address + * + * @param emailAddress the emailAddress to set + */ + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Family name + * + * @return the familyName + */ + public String getFamilyName () { + return this.familyName; + } + + /** + * Family name + * + * @param familyName the familyName to set + */ + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + /** + * Fax number + * + * @return the faxNumber + */ + public String getFaxNumber () { + return this.faxNumber; + } + + /** + * Fax number + * + * @param faxNumber the faxNumber to set + */ + public void setFaxNumber (final String faxNumber) { + this.faxNumber = faxNumber; + } + + /** + * Gender of the contact + * + * @return the gender + */ + public char getGender () { + return this.gender; + } + + /** + * Gender of the contact + * + * @param gender the gender to set + */ + public void setGender (final char gender) { + this.gender = gender; + } + + /** + * House number + * + * @return the houseNumber + */ + public int getHouseNumber () { + return this.houseNumber; + } + + /** + * House number + * + * @param houseNumber the houseNumber to set + */ + public void setHouseNumber (final int houseNumber) { + this.houseNumber = houseNumber; + } + + /** + * Phone number + * + * @return the phoneNumber + */ + public String getPhoneNumber () { + return this.phoneNumber; + } + + /** + * Phone number + * + * @param phoneNumber the phoneNumber to set + */ + public void setPhoneNumber (final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /** + * Street + * + * @return the street + */ + public String getStreet () { + return this.street; + } + + /** + * Street + * + * @param street the street to set + */ + public void setStreet (final String street) { + this.street = street; + } + + /** + * Surname + * + * @return the surname + */ + public String getSurname () { + return this.surname; + } + + /** + * Surname + * + * @param surname the surname to set + */ + public void setSurname (final String surname) { + this.surname = surname; + } + + /** + * Some "getter" for a translated/human-readable gender + * @return gender Human-readable gender + */ + public String getTranslatedGender () { + // Default init + String translated = null; + + // "Translate" it + switch (this.getGender()) { + case 'M': // Mr. + translated = "Herr"; + break; + + case 'F': // Mrs. + translated = "Frau"; + break; + + case 'C': // "Company" + translated = "Firma"; + break; + + default: // Unsupported + this.getLogger().error("Gender " + this.getGender() + " not supported."); + break; + } + + // Return it + return translated; + } + + /** + * ZIP code + * + * @return the zipCode + */ + public long getZipCode () { + return this.zipCode; + } + + /** + * ZIP code + * + * @param zipCode the zipCode to set + */ + public void setZipCode (final long zipCode) { + this.zipCode = zipCode; + } + + @Override + public int hashCode () { + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.getFamilyName()); + hash = 79 * hash + this.getGender(); + hash = 79 * hash + Objects.hashCode(this.getSurname()); + return hash; + } + + /** + * Checks whether the contact is user's own data + * + * @return Own data? + */ + public boolean isOwnContact () { + return this.ownContact; + } + + /** + * Shows this contact to the user + * + * @param client Client instance to use + */ + public void show (final Client client) { + // Display name "box" + client.displayNameBox((Contact) this); + + // Display address "box" + client.displayAddressBox((Contact) this); + + // Display other data "box" + client.displayOtherDataBox((Contact) this); + } + + /** + * Updates address data in this Contact instance + * + * @param street Street + * @param zipCode ZIP code + * @param city City + * @param countryCode Country code + */ + public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) { + // Set all + if (street != null) { + this.setStreet(street); + } + if (zipCode > 0) { + this.setZipCode(zipCode); + } + if (city != null) { + this.setCity(city); + } + if (countryCode != null) { + this.setCountryCode(countryCode); + } + } + + /** + * Updates name data in this Contact instance + * @param gender Gender (M, F, C) + * @param surname Surname + * @param familyName Family name + * @param companyName Company name + */ + public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) { + // Set all + this.setGender(gender); + if (surname != null) { + this.setSurname(surname); + } + if (familyName != null) { + this.setFamilyName(familyName); + } + if (companyName != null) { + this.setCompanyName(companyName); + } + } + + /** + * Updates other data in this Contact instance + * + * @param phoneNumber Phone number + * @param cellphoneNumber Cellphone number + * @param faxNumber Fax number + * @param emailAddress Email address + * @param birthday Birth day + * @param comment Comments + */ + public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) { + // Set all + if (phoneNumber != null) { + this.setPhoneNumber(phoneNumber); + } + if (cellphoneNumber != null) { + this.setCellphoneNumber(cellphoneNumber); + } + if (faxNumber != null) { + this.setFaxNumber(faxNumber); + } + if (emailAddress != null) { + this.setEmailAddress(emailAddress); + } + if (birthday != null) { + this.setBirthday(birthday); + } + if (comment != null) { + this.setComment(comment); + } + } + + /** + * Enables the flag "own data" which signals that this contact is the user's + * own data. + */ + protected void enableFlagOwnContact () { + this.ownContact = true; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/contact/Contact.java b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java new file mode 100644 index 0000000..2860ee2 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java @@ -0,0 +1,184 @@ +/* + * 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.contact; + +import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public interface Contact extends FrameworkInterface { + + /** + * Some "getter" for translated gender of the contact + * @return Translated / human-readable gender + */ + public String getTranslatedGender(); + + /** + * Checks whether the contact is user's own data + * + * @return Own data? + */ + public boolean isOwnContact(); + + /** + * Gender of the contact + * + * @return the gender + */ + public char getGender(); + + /** + * Surname + * + * @return the surname + */ + public String getSurname(); + + /** + * Family name + * + * @return the familyName + */ + public String getFamilyName(); + + /** + * Companyname + * + * @return the companyName + */ + public String getCompanyName(); + + /** + * Street + * + * @return the street + */ + public String getStreet(); + + /** + * House number + * + * @return the houseNumber + */ + public int getHouseNumber(); + + /** + * ZIP code + * + * @return the zipCode + */ + public long getZipCode(); + + /** + * City + * + * @return the city + */ + public String getCity(); + + /** + * Country code + * + * @return the countryCode + */ + public String getCountryCode(); + + /** + * Email address + * + * @return the emailAddress + */ + public String getEmailAddress(); + + /** + * Phone number + * + * @return the phoneNumber + */ + public String getPhoneNumber(); + + /** + * Fax number + * + * @return the faxNumber + */ + public String getFaxNumber(); + + /** + * Cellphone number + * + * @return the cellphoneNumber + */ + public String getCellphoneNumber(); + + /** + * Birth day + * + * @return the birthday + */ + public String getBirthday(); + + /** + * Comments + * + * @return the comment + */ + public String getComment(); + + /** + * Shows the contact to the user + * + * @param client Client instance to call back + */ + public void show (final Client client); + + /** + * Updates address data in this Contact instance + * + * @param street Street + * @param zipCode ZIP code + * @param city City + * @param countryCode Country code + */ + public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode); + + /** + * Updates name data in this Contact instance + * + * @param gender Gender (M, F, C) + * @param surname Surname + * @param familyName Family name + * @param companyName Company name + */ + public void updateNameData (final char gender, final String surname, final String familyName, final String companyName); + + /** + * Updates other data in this Contact instance + * + * @param phoneNumber Phone number + * @param cellNumber Cellphone number + * @param faxNumber Fax number + * @param email Email address + * @param birthday Birthday + * @param comment Comments + */ + public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String birthday, final String comment); +} diff --git a/Addressbook/src/org/mxchange/addressbook/contact/book/BookContact.java b/Addressbook/src/org/mxchange/addressbook/contact/book/BookContact.java new file mode 100644 index 0000000..02d4218 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/contact/book/BookContact.java @@ -0,0 +1,38 @@ +/* + * 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.contact.book; + +import org.mxchange.addressbook.contact.BaseContact; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.database.storage.csv.StoreableCsv; + +/** + * A contact that can be placed into "contact books" + * + * @author Roland Haeder + * @version 0.0 + * @since 0.0 + */ +public class BookContact extends BaseContact implements Contact, StoreableCsv { + + /** + * Default constructor, may only be used from database backend + */ + public BookContact () { + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java new file mode 100644 index 0000000..1f9b141 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java @@ -0,0 +1,55 @@ +/* + * 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.contact.user; + +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.contact.book.BookContact; +import org.mxchange.addressbook.database.storage.csv.StoreableCsv; + +/** + * + * @author Roland Haeder + * @todo After a Collection has been used in ContactManager, change to BaseContact + */ +public class UserContact extends BookContact implements Contact, StoreableCsv { + + /** + * Creates own contact entry + * + * @param gender Gender to be set + * @param surname Surname to be set + * @param familyName Family name to be set + * @param companyName Company name + * @todo Add validation of data + */ + public UserContact (final char gender, final String surname, final String familyName, final String companyName) { + // Make sure all constructors are called + this(); + + this.setGender(gender); + this.setSurname(surname); + this.setFamilyName(familyName); + this.setCompanyName(companyName); + } + + /** + * Default constructor, may only be used from database backend + */ + public UserContact () { + this.enableFlagOwnContact(); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java new file mode 100644 index 0000000..539f6d2 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java @@ -0,0 +1,32 @@ +/* + * 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.database.backend; + +import org.mxchange.addressbook.BaseFrameworkSystem; + +/** + * Generall database backend + * + * @author Roland Haeder + */ +public class BaseDatabaseBackend extends BaseFrameworkSystem { + /** + * No instances from this class + */ + protected BaseDatabaseBackend () { + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java new file mode 100644 index 0000000..5b2d42d --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java @@ -0,0 +1,54 @@ +/* + * 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.database.backend; + +import java.io.IOException; +import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.database.storage.Storeable; + +/** + * A generic interface for database frontends + * + * @author Roland Haeder + */ +public interface DatabaseBackend extends FrameworkInterface { + + /** + * Shuts down this backend + */ + public void doShutdown (); + + /** + * Rewinds backend + */ + public void rewind (); + + /** + * Get length of underlaying file + * + * @return Length of underlaying file + */ + public long length (); + + /** + * Stores an object in the database. + * + * @param object Object to store in database + * @throws java.io.IOException From inner class + */ + public void store (final Storeable object) throws IOException; +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java new file mode 100644 index 0000000..704cbb6 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java @@ -0,0 +1,36 @@ +/* + * 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.database.backend.csv; + +import java.util.Iterator; +import org.mxchange.addressbook.BadTokenException; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.database.backend.DatabaseBackend; + +/** + * + * @author Roland Haeder + */ +public interface CsvBackend extends DatabaseBackend { + + /** + * Gets an iterator for contacts + * + * @return Iterator for contacts + */ + public Iterator contactIterator () throws BadTokenException; +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java new file mode 100644 index 0000000..0bc97f3 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java @@ -0,0 +1,492 @@ +/* + * 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.database.backend.csv; + +import java.io.DataOutput; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; +import org.mxchange.addressbook.BadTokenException; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.contact.book.BookContact; +import org.mxchange.addressbook.contact.user.UserContact; +import org.mxchange.addressbook.database.backend.BaseDatabaseBackend; +import org.mxchange.addressbook.database.storage.Storeable; +import org.mxchange.addressbook.database.storage.csv.StoreableCsv; + +/** + * A database backend with CSV file as storage implementation + * + * @author Roland Haeder + */ +public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend { + /** + * Output stream for this storage engine + */ + private RandomAccessFile storageFile; + + /** + * Constructor with table name + * + * @param tableName Name of "table" + */ + public CsvDatabaseBackend (final String tableName) { + // Debug message + this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName)); + + // Set table name here, too + this.setTableName(tableName); + + // Construct file name + String fileName = String.format("data/table_%s.csv", tableName); + + // Debug message + this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName)); + + try { + // Try to initialize the storage (file instance) + this.storageFile = new RandomAccessFile(fileName, "rw"); + } catch (final FileNotFoundException ex) { + // Did not work + this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString())); + System.exit(1); + } + + // Output message + this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName)); + } + + /** + * Gets an iterator for contacts + * + * @return Iterator for contacts + * @throws org.mxchange.addressbook.BadTokenException If the underlaying method has found an invalid token + */ + @Override + public Iterator contactIterator () throws BadTokenException { + /* + * Then read the file into RAM (yes, not perfect for >1000 entries ...) + * and get a List back. + */ + List list = this.readContactList(); + + // Get iterator from list and return it + return list.iterator(); + } + + /** + * Shuts down this backend + */ + @Override + public void doShutdown () { + try { + // Close file + this.storageFile.close(); + } catch (final IOException ex) { + this.getLogger().catching(ex); + System.exit(1); + } + } + + /** + * Get length of underlaying file + * + * @return Length of underlaying file + */ + @Override + public long length () { + long length = 0; + + try { + length = this.storageFile.length(); + this.getLogger().debug(MessageFormat.format("length={0}", length)); + } catch (final IOException ex) { + // Length cannot be determined + this.getLogger().catching(ex); + System.exit(1); + } + + // Return result + this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); + return length; + } + + /** + * Rewinds backend + */ + @Override + public void rewind (){ + this.getLogger().trace("CALLED!"); + + try { + // Rewind underlaying database file + this.storageFile.seek(0); + } catch (final IOException ex) { + this.getLogger().catching(ex); + System.exit(1); + } + + this.getLogger().trace("EXIT!"); + } + + /** + * Stores given object by "visiting" it + * + * @param object An object implementing Storeable + * @throws java.io.IOException From "inner" class + */ + @Override + public void store (final Storeable object) throws IOException { + // Make sure the instance is there (DataOutput flawor) + assert(this.storageFile instanceof DataOutput); + + // Try to cast it, this will fail if the interface is not implemented + StoreableCsv csv = (StoreableCsv) object; + + // Now get a string from the object that needs to be stored + String str = csv.getCsvStringFromStoreableObject(); + + // Debug message + this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str)); + + // The string is now a valid CSV string + this.storageFile.writeBytes(str); + } + + /** + * Adds given contact to list + * + * @param contact Contact instance to add + * @param list List instance + */ + private void addContactToList (final Contact contact, final List list) { + // Debug message + this.getLogger().debug(MessageFormat.format("contact={0}", contact)); + + // Is the contact read? + if (contact instanceof Contact) { + // Then add it + boolean added = list.add(contact); + + // Debug message + this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); + + // Has it been added? + if (!added) { + // Not added + this.getLogger().warn("Contact object has not been added."); + } + } + } + + /** + * Checks whether end of file has been reached + * + * @return Whether lines are left to read + */ + private boolean isEndOfFile () { + // Default is EOF + boolean isEof = true; + + try { + isEof = (this.storageFile.getFilePointer() >= this.length()); + } catch (final IOException ex) { + // Length cannot be determined + this.getLogger().catching(ex); + } + + // Return status + this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof)); + return isEof; + } + + /** + * Reads the database file, if available, and adds all read lines into + * the list. + * + * @return A list with Contact instances + */ + private List readContactList () throws BadTokenException { + this.getLogger().trace("CALLED!"); + + // First rewind + this.rewind(); + + // Get file size and divide it by 140 (possible average length of one line) + int lines = Math.round(this.length() / 140 + 0.5f); + + // Debug message + this.getLogger().debug(MessageFormat.format("lines={0}", lines)); + + // Instance list + // @TODO The maximum length could be guessed from file size? + List list = new ArrayList<>(lines); + + // Init variables + StringTokenizer tokenizer; + String line; + + // Read all lines + while (!this.isEndOfFile()) { + // Then read a line + line = this.readLine(); + + // Debug message + this.getLogger().debug(MessageFormat.format("line={0}", line)); + + // Then tokenize it + // @TODO Move this into separate method + tokenizer = new StringTokenizer(line, ";"); + + // Count round + int count = 0; + + // Init contact object + Contact contact = null; + + // The tokens are now available, so get all + while (tokenizer.hasMoreElements()) { + // Get next token + String token = tokenizer.nextToken(); + + // Debug message + this.getLogger().debug(MessageFormat.format("token={0}", token)); + + // Verify token, it must have double-quotes on each side + if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { + // Something bad was read + throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token)); + } + + // All fine, so remove it + String strippedToken = token.substring(1, token.length() - 1); + + // Is the string's content "null"? + if (strippedToken.equals("null")) { + // Debug message + this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken)); + + // This needs to be set to null + strippedToken = null; + } + + // Debug message + this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken)); + + // Init number/string data values + String strData = strippedToken; + Long num = null; + Boolean bool = null; + char gender = '?'; + + // Now, let's try a number check, if no null + if (strippedToken != null) { + // Okay, no null, maybe the string bears a decimal number? + try { + num = Long.valueOf(strippedToken); + + // Debug message + this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); + } catch (final NumberFormatException ex) { + // No number, then set default + num = null; + } + } + + // Now, let's try a boolean check, if no null + if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { + // Debug message + this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken)); + + // parseBoolean() is relaxed, so no exceptions + bool = Boolean.valueOf(strippedToken); + } + + // Now, let's try a boolean check, if no null + if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) { + // Get first character + gender = strippedToken.charAt(0); + } + + // Now it depends on the counter which position we need to check + switch (count) { + case 0: // isOwnContact + assert((bool instanceof Boolean)); + + // Debug message + this.getLogger().debug(MessageFormat.format("bool={0}", bool)); + + // Is it own contact? + if (true == bool) { + // Debug message + this.getLogger().debug("Creating UserContact object ..."); + + // Own entry + contact = new UserContact(); + } else { + // Debug message + this.getLogger().debug("Creating BookContact object ..."); + + // Other contact + contact = new BookContact(); + } + break; + + case 1: // Gender + assert(contact instanceof Contact) : "First token was not boolean"; + assert(gender != '?') : "Gender is not detected."; + + // Update data + contact.updateNameData(gender, null, null, null); + break; + + case 2: // Surname + assert(contact instanceof Contact) : "First token was not boolean"; + assert(gender != '?') : "Gender is not detected."; + + // Update data + contact.updateNameData(gender, strippedToken, null, null); + break; + + case 3: // Family name + assert(contact instanceof Contact) : "First token was not boolean"; + assert(gender != '?') : "Gender is not detected."; + + // Update data + contact.updateNameData(gender, null, strippedToken, null); + break; + + case 4: // Company name + assert(contact instanceof Contact) : "First token was not boolean"; + assert(gender != '?') : "Gender is not detected."; + + // Update data + contact.updateNameData(gender, null, null, strippedToken); + break; + + case 5: // Street number + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateAddressData(strippedToken, 0, null, null); + break; + + case 6: // ZIP code + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateAddressData(null, num, null, null); + break; + + case 7: // City name + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateAddressData(null, 0, strippedToken, null); + break; + + case 8: // Country code + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateAddressData(null, 0, null, strippedToken); + break; + + case 9: // Phone number + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(strippedToken, null, null, null, null, null); + break; + + case 10: // Fax number + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(null, strippedToken, null, null, null, null); + break; + + case 11: // Cellphone number + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(null, null, strippedToken, null, null, null); + break; + + case 12: // Email address + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(null, null, null, strippedToken, null, null); + break; + + case 13: // Birthday + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(null, null, null, null, strippedToken, null); + break; + + case 14: // Birthday + assert(contact instanceof Contact) : "First token was not boolean"; + + // Update data + contact.updateOtherData(null, null, null, null, null, strippedToken); + break; + + default: // New data entry + this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); + break; + } + + // Increment counter for next round + count++; + } + + // Add contact + this.addContactToList(contact, list); + } + + // Return finished list + this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); + return list; + } + + /** + * Reads a line from file base + * + * @return Read line from file + */ + private String readLine () { + // Init input + String input = null; + + try { + input = this.storageFile.readLine(); + } catch (final IOException ex) { + this.getLogger().catching(ex); + } + + // Return read string or null + return input; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java new file mode 100644 index 0000000..de208ba --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java @@ -0,0 +1,66 @@ +/* + * 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.database.frontend; + +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.database.backend.DatabaseBackend; +import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend; + +/** + * General database frontend class + * + * @author Roland Haeder + */ +public class BaseDatabaseFrontend extends BaseFrameworkSystem { + + /** + * Instance for database backend + */ + private DatabaseBackend backend; + + /** + * No instances from this class + */ + protected BaseDatabaseFrontend () { + } + + /** + * Instance for database backend + * + * @return the backend + */ + protected DatabaseBackend getBackend () { + return this.backend; + } + + /** + * Instance for database backend + * + * @param backend the backend to set + */ + protected void setBackend (final DatabaseBackend backend) { + this.backend = backend; + } + + /** + * Initialize backend + */ + protected void initBackend () { + // Instance backend + this.backend = new CsvDatabaseBackend(this.getTableName()); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java new file mode 100644 index 0000000..0bf6cc3 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java @@ -0,0 +1,27 @@ +/* + * 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.database.frontend; + +import org.mxchange.addressbook.FrameworkInterface; + +/** + * A generic interface for database frontends + * + * @author Roland Haeder + */ +public interface DatabaseWrapper extends FrameworkInterface { +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java new file mode 100644 index 0000000..df1854c --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java @@ -0,0 +1,129 @@ +/* + * 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.database.frontend.contact; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import org.mxchange.addressbook.BadTokenException; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.database.backend.csv.CsvBackend; +import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend; +import org.mxchange.addressbook.database.storage.Storeable; +import org.mxchange.addressbook.manager.contact.ContactManager; + +/** + * Stores and retrieves Contact instances + * + * @author Roland Haeder + */ +public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper { + /** + * Constructor which accepts a contact manager + * @param manager + */ + public ContactDatabaseFrontend (final ContactManager manager) { + // Call own constructor + this(); + + // Set contact manager + this.setContactManager(manager); + } + + /** + * Basic constrcutor + */ + protected ContactDatabaseFrontend () { + super(); + + // Set "table" name + this.setTableName("contacts"); + + // Initalize backend + this.initBackend(); + } + + /** + * Shuts down the database layer + */ + @Override + public void doShutdown () { + // Shutdown backend + this.getBackend().doShutdown(); + } + + /** + * Flushes all contact entries to database + */ + @Override + public void flushAllContacts () { + // Get full list + List contacts = this.getContactManager().getList(); + + // Get iterator + Iterator iterator = contacts.iterator(); + + // Rewind backend + this.getBackend().rewind(); + + // Get all entries + while (iterator.hasNext()) { + // Get next entry + Contact contact = iterator.next(); + + try { + // Store this entry + this.getBackend().store((Storeable) contact); + } catch (final IOException ex) { + // Should not happen? + this.getLogger().catching(ex); + System.exit(1); + } + } + } + + /** + * Reads all contacts from database backend and handles them over to the + * contact manager + */ + @Override + public void readAllContacts () { + // Get iterator and case it + CsvBackend backend = (CsvBackend) this.getBackend(); + + // First rewind to beginning + this.getBackend().rewind(); + + // Get backend iterator + Iterator iterator = null; + try { + iterator = backend.contactIterator(); + } catch (final BadTokenException ex) { + this.getLogger().catching(ex); + System.exit(1); + } + + // Read all entries + while (iterator.hasNext()) { + // Get next entry + Contact contact = iterator.next(); + + // Add contact instance to manager + this.getContactManager().addContact(contact); + } + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java new file mode 100644 index 0000000..c14a3c3 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.database.frontend.contact; + +import org.mxchange.addressbook.database.frontend.DatabaseWrapper; + +/** + * + * @author Roland Häder + */ +public interface ContactWrapper extends DatabaseWrapper { + + /** + * Shuts down the database layer + */ + public void doShutdown (); + + /** + * Flushes all contact entries to database + */ + public void flushAllContacts (); + + /** + * Reads all contacts from database backend and handles them over to the + * contact manager + */ + public void readAllContacts (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/storage/Storeable.java b/Addressbook/src/org/mxchange/addressbook/database/storage/Storeable.java new file mode 100644 index 0000000..cd68048 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/storage/Storeable.java @@ -0,0 +1,27 @@ +/* + * 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.database.storage; + +import org.mxchange.addressbook.FrameworkInterface; + +/** + *An interface for objects being stored in databases + * + * @author Roland Haeder + */ +public interface Storeable extends FrameworkInterface { +} diff --git a/Addressbook/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java b/Addressbook/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java new file mode 100644 index 0000000..6a5915e --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 KLC + * + * 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.database.storage.csv; + +import org.mxchange.addressbook.database.storage.Storeable; + +/** + * + * @author KLC + */ +public interface StoreableCsv extends Storeable { + /** + * Getter for a CSV-formated string from object + * @return + */ + public String getCsvStringFromStoreableObject (); +} diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties new file mode 100644 index 0000000..e4c5738 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties @@ -0,0 +1,32 @@ +# 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. +AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1=null +AddressbookFrame.addressbookMenu.text_1=null +AddressbookFrame.exitProgram.text_1=null +AddressbookFrame.statusLabel.text_1=null diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties new file mode 100644 index 0000000..8d314b9 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties @@ -0,0 +1,28 @@ +# 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. diff --git a/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java b/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java new file mode 100644 index 0000000..2790075 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java @@ -0,0 +1,36 @@ +/* + * 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; + +import org.mxchange.addressbook.BaseFrameworkSystem; + +/** + * A general manager + * + * @author Roland Haeder + * @version 0.0 + * @since 0.0 + */ +public class BaseManager extends BaseFrameworkSystem { + /** + * No instances can be created of this class + */ + protected BaseManager () { + // Call any other super constructors + super(); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/manager/Manageable.java b/Addressbook/src/org/mxchange/addressbook/manager/Manageable.java new file mode 100644 index 0000000..af3cc6c --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/Manageable.java @@ -0,0 +1,26 @@ +/* + * 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; + +import org.mxchange.addressbook.FrameworkInterface; + +/** + * + * @author Roland Haeder + */ +public interface Manageable extends FrameworkInterface { +} diff --git a/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java b/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java new file mode 100644 index 0000000..9afad3a --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java @@ -0,0 +1,60 @@ +/* + * 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.application; + +import org.mxchange.addressbook.application.Application; +import org.mxchange.addressbook.manager.BaseManager; + +/** + * + * @author Roland Haeder + */ +public class ApplicationManager extends BaseManager implements ManageableApplication { + + /** + * Getter for application manager + * @param application An instance of a Application class + * @return + */ + public static final ManageableApplication getManager (final Application application) { + // Get manager + ManageableApplication manager = new ApplicationManager(application); + + // Return manager + return manager; + } + + /** + * Constructor for this manager + * @param application An instance of an Application class + */ + private ApplicationManager (final Application application) { + super(); + + // Set application instance + this.setApplication (application); + } + + @Override + public void start () { + // Bootstrap application + this.getApplication().doBootstrap(); + + // Run the main loop + this.getApplication().doMainLoop(); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/manager/application/ManageableApplication.java b/Addressbook/src/org/mxchange/addressbook/manager/application/ManageableApplication.java new file mode 100644 index 0000000..325f83c --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/application/ManageableApplication.java @@ -0,0 +1,30 @@ +/* + * 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.application; + +import org.mxchange.addressbook.manager.Manageable; + +/** + * + * @author Roland Haeder + */ +public interface ManageableApplication extends Manageable { + /** + * Launches application + */ + public void start(); +} diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java new file mode 100644 index 0000000..e89b708 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -0,0 +1,548 @@ +/* + * 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.BaseContact; +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 { + + /** + * 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(); + + // Init contacts + this.contacts = new ArrayList<>(maxContacts); + + // Init database connection + this.contactDatabase = new ContactDatabaseFrontend(this); + + // Read all entries + this.contactDatabase.readAllContacts(); + + // Debug message + //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client); + + // Init client + this.setClient(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.contactDatabase.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 int getColumnCount () { + /* + * Return constant, may look useful. But without this, e.g. the + * AddressTableModel have a hard-coded value. + */ + return BaseContact.COLUMN_COUNT; + } + + /** + * 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 int size () { + return this.contacts.size(); + } + + /** + * 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/manager/contact/ManageableContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java new file mode 100644 index 0000000..736053d --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java @@ -0,0 +1,229 @@ +/* + * 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.util.List; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.contact.Contact; +import org.mxchange.addressbook.manager.Manageable; + +/** + * + * @author Roland Haeder + */ +public interface ManageableContact extends Manageable { + + /** + * Shuts down this contact manager + */ + public void doShutdown (); + + /** + * Allows the user to enter own cellphone number. + * + * @return Cellphone number + */ + public String enterOwnCellNumber (); + + /** + * Allows the user to enter own city name. + * + * @return City name + */ + public String enterOwnCity (); + + /** + * Allows the user to enter comment for own entry. + * + * @return Comment + */ + public String enterOwnComment (); + + /** + * Allows the user to enter own company name. + * + * @return Company name + */ + public String enterOwnCompanyName (); + + /** + * Allows the user to enter own country code. + * + * @return Country code + */ + public String enterOwnCountryCode (); + + /** + * Allows the user to enter own email address. + * + * @return Email address + */ + public String enterOwnEmailAddress (); + + /** + * Allows the user to enter own family name. + * + * @return Family name + */ + public String enterOwnFamilyName (); + + /** + * Allows the user to enter own fax number. + * + * @return Fax number + */ + public String enterOwnFaxNumber (); + + /** + * Allows the user to enter own gender. + * + * @return Gender + */ + public char enterOwnGender (); + + /** + * Allows the user to enter own phone number. + * + * @return Phone number + */ + public String enterOwnPhoneNumber (); + + /** + * Allows the user to enter own street and house number. + * + * @return Street and house number + */ + public String enterOwnStreet (); + + /** + * Allows the user to enter own surname. + * + * @return Surname + */ + public String enterOwnSurname (); + + /** + * Allows the user to enter own ZIP code. + * + * @return ZIP code + */ + public int enterOwnZipCode (); + + /** + * Getter for column count + * + * @return Column count + */ + public int getColumnCount (); + + /** + * List all contacts + */ + public void listContacts (); + + /** + * Adds given contact to address book + * + * @param contact Contact being added + * @todo Add check for book size + */ + public void registerContact (final Contact contact); + + /** + * Adds given Contact instance to list + * + * @param contact Contact instance to add + */ + public void addContact (final Contact contact); + + /** + * Let the user add a new other address + */ + public void addOtherAddress(); + + /** + * The user can change address data, like street, ZIP code, city and country + * of given Contact instance. + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeAddressData (final Contact contact, final Client client); + + /** + * The user can change name data, like gender, surname, family name and + * company name (if business contact). + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeNameData (final Contact contact, final Client client); + + /** + * Let the user change other address + */ + public void changeOtherAddress(); + + /** + * The user can change other data, like phone numbers or comments. + * + * @param contact Instance to change data + * @param client Client instance to call back + */ + public void doChangeOtherData (final Contact contact, final Client client); + + /** + * Let the user change own data + */ + public void changeOwnData(); + + /** + * Let the user delete other address + */ + public void deleteOtherAddress(); + + /** + * Asks user for own data + */ + public void doEnterOwnData(); + + /** + * Getter for whole list + * @return List of all contacts + */ + public List getList (); + + /** + * Searches address book for a contact + */ + public void searchContacts (); + + /** + * Checks whether own contact is already added by checking all entries for + * isOwnContact flag + * + * @return Whether own contact is already added + */ + public boolean isOwnContactAdded (); + + /** + * Getter for size + * + * @return size of contact "book" + */ + public int size(); +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java new file mode 100644 index 0000000..02d00b6 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java @@ -0,0 +1,85 @@ +/* + * 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; + +import java.util.List; +import org.apache.logging.log4j.Logger; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * Utility class for menu structure + * + * @author Roland Haeder + */ +public class AddressbookMenu extends BaseFrameworkSystem { + /** + * Copies entries for given type into the menu list + * + * @param menuList Menu list for later showing + * @param menuType Type of menu + * @param client Client instance to call back + */ + public static void addItemsToList (final List menuList, final String menuType, final Client client) { + // Get logger + Logger log = new AddressbookMenu().getLogger(); + + // Get list size + int size = menuList.size(); + + // Debug message + log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ..."); + + // Depends on type + switch (menuType) { + case "main": // Main menu + // Enter own data + menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen")); + + // Change own data + menuList.add(client.getMenuItem('2', "Eigene Adresse ändern")); + + // Add new addess + menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen")); + + // List entries + menuList.add(client.getMenuItem('4', "Adressbuch anzeigen")); + + // Address search + menuList.add(client.getMenuItem('5', "Adresse suchen")); + + // Change other address + menuList.add(client.getMenuItem('6', "Adresse ändern")); + + // Delete other address + menuList.add(client.getMenuItem('7', "Adresse löschen")); + + // Always last line: Exit program + menuList.add(client.getMenuItem('0', "Programm verlassen")); + break; + + default: // Not supported + log.error("Menu type '" + menuType + "' ont supported"); + System.exit(1); + } + + // Size must have changed to more entries than before + assert(menuList.size() > size); + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java new file mode 100644 index 0000000..d81c071 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java @@ -0,0 +1,100 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * + * @author Roland Haeder + */ +public class BaseMenu extends BaseFrameworkSystem { + /** + * Menu list + */ + private List menuList; + + /** + * No instance from this object + */ + protected BaseMenu () { + super(); + } + + /** + * Size of menu items + * @return Count of menu items + */ + public int getMenuItemsCount () { + return this.menuList.size(); + } + + /** + * "Getter" for an iterator of this menu's items + * + * @return An iterator of all menu items + */ + public Iterator getMenuItemsIterator () { + return this.menuList.iterator(); + } + + /** + * Shows this menu + * + * @param client Client instance to call back + */ + public void show (final Client client) { + // Get values + Iterator iterator = this.menuList.iterator(); + + // Debug message + this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries."); + + // Output all menus + while (iterator.hasNext()) { + // Get item + SelectableMenuItem item = iterator.next(); + + // Show this item + item.show(client); + } + } + + /** + * Getter for menu list + * + * @return menuList List of menu entries + */ + protected final List getMenuList () { + return this.menuList; + } + + /** + * Initializes menu + * @param menuType Menu type to initialize + * @param client CLient to call back + */ + protected void initMenu (final String menuType, final Client client) { + // Init menu list + this.menuList = new ArrayList<>(5); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/Menu.java b/Addressbook/src/org/mxchange/addressbook/menu/Menu.java new file mode 100644 index 0000000..4a13bdb --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/Menu.java @@ -0,0 +1,47 @@ +/* + * 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; + +import java.util.Iterator; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * + * @author Roland Haeder + * @todo find better name + */ +public interface Menu { + + /** + * "Getter" for an iterator on all menu items of the current menu + * @return Iterator on all menu items + */ + public Iterator getMenuItemsIterator(); + + /** + * Shows this menu + * @param client Client instance + */ + public void show (final Client client); + + /** + * Size of all menu items + * @return + */ + public int getMenuItemsCount(); +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java b/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java new file mode 100644 index 0000000..75bfb7e --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java @@ -0,0 +1,78 @@ +/* + * 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; + +import java.util.Iterator; +import java.util.Map; +import org.apache.logging.log4j.Logger; +import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.menu.item.SelectableMenuItem; + +/** + * + * @author Roland Haeder + */ +public class MenuTools extends BaseFrameworkSystem { + + /** + * Gets an array with all available access keys back from given menu map. + * This can later be handle to the client's enterChar() method. + * + * @param menus A Map with all menus and their entries + * @param menuType Menu type + * @return An array with available access chars + */ + public static char[] getAccessKeysFromMenuMap (final Map menus, final String menuType) { + // Get logger + Logger logger = new MenuTools().getLogger(); + + // First search for the proper menu class + Menu menu = menus.get(menuType); + + // Is it there? + if (!(menu instanceof Menu)) { + // Not found + // @todo Rewrite to exception + logger.error("Menu '" + menuType + "' not found."); + System.exit(1); + } + + // Get iterator + Iterator iterator = menu.getMenuItemsIterator(); + + // Init return array and counter 'i' + char[] accessKeys = new char[menu.getMenuItemsCount()]; + int i = 0; + + // Now "walk" through all menu entries + while (iterator.hasNext()) { + // Get item + SelectableMenuItem item = iterator.next(); + //* NOISY-DEBUG: */ logger.debug("item=" + item); + + // Get access key from item and add it to the array + accessKeys[i] = item.getAccessKey(); + //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]); + + // Increment counter + i++; + } + + // Return finished array + return accessKeys; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java new file mode 100644 index 0000000..cefa2c5 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java @@ -0,0 +1,40 @@ +/* + * 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.console; + +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.menu.AddressbookMenu; +import org.mxchange.addressbook.menu.BaseMenu; +import org.mxchange.addressbook.menu.Menu; + +/** + * + * @author Roland Haeder + */ +public class ConsoleMenu extends BaseMenu implements Menu { + /** + * Constructor for this menu + * @param menuType Menu type to initialize + * @param client CLient to call back + */ + public ConsoleMenu (final String menuType, final Client client) { + this.initMenu(menuType, client); + + // Add all items + AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java b/Addressbook/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java new file mode 100644 index 0000000..bc1bba7 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java @@ -0,0 +1,27 @@ +/* + * 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; + +import org.mxchange.addressbook.BaseFrameworkSystem; + +/** + * + * @author Roland Haeder + */ +public class BaseMenuItem extends BaseFrameworkSystem { + +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java b/Addressbook/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java new file mode 100644 index 0000000..efbce50 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java @@ -0,0 +1,44 @@ +/* + * 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; + +import org.mxchange.addressbook.client.Client; + +/** + * + * @author Roland Haeder + */ +public interface SelectableMenuItem { + + /** + * Shows this menu item + * @param client Client instance + */ + public void show (final Client client); + + /** + * Access key + * @return the accessKey + */ + public char getAccessKey(); + + /** + * Text to user + * @return the text + */ + public String getText(); +} diff --git a/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java new file mode 100644 index 0000000..37f9c7c --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java @@ -0,0 +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); + } + +} diff --git a/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java b/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java new file mode 100644 index 0000000..54aa507 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java @@ -0,0 +1,65 @@ +/* + * 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.model; + +import java.text.MessageFormat; +import javax.swing.event.EventListenerList; +import javax.swing.event.TableModelListener; +import org.mxchange.addressbook.BaseFrameworkSystem; + +/** + * + * @author Roland Haeder + */ +public class BaseModel extends BaseFrameworkSystem { + /** List of listeners */ + private final EventListenerList listenerList; + + /** + * Protected constructor + */ + protected BaseModel () { + // Init listener list + this.listenerList = new EventListenerList(); + } + + /** + * Adds a TableModel listener instance to the event list. + * + * @param listener Lister instance + */ + public void addTableModelListener (final TableModelListener listener) { + // Debug message + this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass())); + + // Add listener + this.listenerList.add(TableModelListener.class, listener); + } + + /** + * Removes a TableModel listener instance from the event list. + * + * @param listener Listener instance + */ + public void removeTableModelListener (final TableModelListener listener) { + // Debug message + this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass())); + + // Remove listener + this.listenerList.remove(TableModelListener.class, listener); + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java b/Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java new file mode 100644 index 0000000..d386b95 --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/model/address/AddressTableModel.java @@ -0,0 +1,77 @@ +/* + * 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.model.address; + +import javax.swing.table.TableModel; +import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.model.BaseModel; + +/** + * + * @author Roland Haeder + */ +public class AddressTableModel extends BaseModel implements TableModel { + + /** + * Constructor with Client instance which holds the contact manager + * + * @param client Client instance + */ + public AddressTableModel (final Client client) { + // Parent super constructor + super(); + + // Set client + this.setClient(client); + } + + @Override + public Class getColumnClass (final int columnIndex) { + throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int getColumnCount () { + // Deligate this call to the contact manager + return this.getClient().getContactManager().getColumnCount(); + } + + @Override + public String getColumnName (final int columnIndex) { + throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int getRowCount () { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Object getValueAt (final int rowIndex, final int columnIndex) { + throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean isCellEditable (final int rowIndex, final int columnIndex) { + throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setValueAt (final Object value, final int rowIndex, final int columnIndex) { + throw new UnsupportedOperationException("Not supported yet. value=" + value + ",rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. + } +} diff --git a/lib/log4j-api-2.3.jar b/lib/log4j-api-2.3.jar deleted file mode 100644 index 2a61bbe..0000000 Binary files a/lib/log4j-api-2.3.jar and /dev/null differ diff --git a/lib/log4j-core-2.3.jar b/lib/log4j-core-2.3.jar deleted file mode 100644 index 5438b0b..0000000 Binary files a/lib/log4j-core-2.3.jar and /dev/null differ diff --git a/src/log4j2.xml b/src/log4j2.xml deleted file mode 100644 index 65614c6..0000000 --- a/src/log4j2.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/org/mxchange/addressbook/BadTokenException.java b/src/org/mxchange/addressbook/BadTokenException.java deleted file mode 100644 index ce02e50..0000000 --- a/src/org/mxchange/addressbook/BadTokenException.java +++ /dev/null @@ -1,29 +0,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; - -/** - * - * @author Roland Haeder - */ -public class BadTokenException extends Exception { - - public BadTokenException (final String str) { - super(str); - } - -} diff --git a/src/org/mxchange/addressbook/BaseFrameworkSystem.java b/src/org/mxchange/addressbook/BaseFrameworkSystem.java deleted file mode 100644 index e34fe66..0000000 --- a/src/org/mxchange/addressbook/BaseFrameworkSystem.java +++ /dev/null @@ -1,156 +0,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; - -import java.util.ResourceBundle; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.manager.contact.ManageableContact; - -/** - * General class - * - * @author Roland Haeder - */ -public class BaseFrameworkSystem implements FrameworkInterface { - /** - * Class' logger - */ - private final Logger LOG; - - /** - * Application instance - */ - private Application application; - - /** - * Client instance - */ - private Client client; - - /** - * Contact manager instance - */ - private ManageableContact contactManager; - - /** - * Name of used database table, handled over to backend - */ - private String tableName; - - /** - * Bundle instance - */ - private final ResourceBundle bundle; - - /** - * Initialize object - */ - { - LOG = LogManager.getLogger(this); - bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N - } - - /** - * No instances can be created of this class - */ - protected BaseFrameworkSystem () { - } - - /** - * Application instance - * - * @return the application - */ - @Override - public final Application getApplication () { - return this.application; - } - - /** - * Client instance - * - * @return the client - */ - @Override - public final Client getClient () { - return this.client; - } - - /** - * Contact manager instance - * @return the contactManager - */ - @Override - public final ManageableContact getContactManager () { - return this.contactManager; - } - - /** - * Contact manager instance - * @param contactManager the contactManager to set - */ - protected final void setContactManager (final ManageableContact contactManager) { - this.contactManager = contactManager; - } - - /** - * Client instance - * @param client the client to set - */ - protected final void setClient (final Client client) { - this.client = client; - } - - /** - * Application instance - * - * @param application the application to set - */ - protected final void setApplication(final Application application) { - this.application = application; - } - - /** - * Getter for logger - * - * @return Logger - */ - protected final Logger getLogger () { - return this.LOG; - } - - /** - * Name of used database table, handled over to backend - * - * @return the tableName - */ - protected final String getTableName () { - return this.tableName; - } - - /** - * Name of used database table, handled over to backend - * - * @param tableName the tableName to set - */ - protected final void setTableName (final String tableName) { - this.tableName = tableName; - } -} diff --git a/src/org/mxchange/addressbook/FrameworkInterface.java b/src/org/mxchange/addressbook/FrameworkInterface.java deleted file mode 100644 index ae1c570..0000000 --- a/src/org/mxchange/addressbook/FrameworkInterface.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2015 KLC - * - * 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; - -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.manager.contact.ManageableContact; - -/** - * - * @author KLC - */ -public interface FrameworkInterface { - - /** - * Getter for contact manager - * @return Contact manager instance - */ - public ManageableContact getContactManager(); - - /** - * Client instance - * - * @return the client - */ - public Client getClient (); - - /** - * Application instance - * - * @return the application - */ - public Application getApplication (); -} diff --git a/src/org/mxchange/addressbook/UnhandledUserChoiceException.java b/src/org/mxchange/addressbook/UnhandledUserChoiceException.java deleted file mode 100644 index e97f20a..0000000 --- a/src/org/mxchange/addressbook/UnhandledUserChoiceException.java +++ /dev/null @@ -1,30 +0,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; - -/** - * This exception is thrown when the user made a valid choice but it was not - * handled by the program. - * - * @author Roland Haeder - */ -public class UnhandledUserChoiceException extends Exception { - - public UnhandledUserChoiceException (final String message) { - super(message); - } -} diff --git a/src/org/mxchange/addressbook/application/AddressbookApplication.java b/src/org/mxchange/addressbook/application/AddressbookApplication.java deleted file mode 100644 index 788c940..0000000 --- a/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ /dev/null @@ -1,327 +0,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 () { - // @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); - } -} diff --git a/src/org/mxchange/addressbook/application/Application.java b/src/org/mxchange/addressbook/application/Application.java deleted file mode 100644 index aa773e5..0000000 --- a/src/org/mxchange/addressbook/application/Application.java +++ /dev/null @@ -1,40 +0,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 org.mxchange.addressbook.FrameworkInterface; - -/** - * - * @author Roland Haeder - */ -public interface Application extends FrameworkInterface { - /** - * Bootstraps the application - */ - public void doBootstrap(); - - /** - * Run the main loop - */ - public void doMainLoop(); - - /** - * Shutdown the application - */ - public void doShutdown (); -} diff --git a/src/org/mxchange/addressbook/client/BaseClient.java b/src/org/mxchange/addressbook/client/BaseClient.java deleted file mode 100644 index 0282c91..0000000 --- a/src/org/mxchange/addressbook/client/BaseClient.java +++ /dev/null @@ -1,180 +0,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.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 void enableIsRunning () { - this.isRunning = true; - } - - /** - * Current menu choice - * - * @return the currentMenu - */ - public String getCurrentMenu () { - return this.currentMenu; - } - - /** - * Current menu choice - * @param currentMenu the currentMenu to set - */ - public void setCurrentMenu (final String currentMenu) { - this.currentMenu = currentMenu; - } - - /** - * "Getter" for given menu type - * - * @param menuType Menu type instance to return - * @return Menu or null if not found - */ - 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 boolean isRunning () { - // In console client, 0 may have been used - return this.isRunning; - } - - /** - * Disables running state, so the main loop can abort. - */ - protected 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/src/org/mxchange/addressbook/client/Client.java b/src/org/mxchange/addressbook/client/Client.java deleted file mode 100644 index 136c95a..0000000 --- a/src/org/mxchange/addressbook/client/Client.java +++ /dev/null @@ -1,189 +0,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.client; - -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * An interface for application clients - * - * @author Roland Haeder - */ -public interface Client extends FrameworkInterface { - - /** - * Displays a "box" for the address - * - * @param contact Contact to show address from - */ - public void displayAddressBox (final Contact contact); - - /** - * The user changes own name data - * @param contact - */ - public void doChangeOwnNameData (final Contact contact); - - /** - * The user changes own address data - * - * @param contact Contact instance to change - */ - public void doChangeOwnAddressData (final Contact contact); - - /** - * The user changes own other data - * - * @param contact Constact instance to change - */ - public void doChangeOwnOtherData (final Contact contact); - - /** - * Allows the user to enter own data - * - * @return Finished Contact instance - */ - public Contact doEnterOwnData (); - - /** - * Shuts down the client and therefore whole application - */ - public void doShutdown (); - - /** - * Displays a message to the user - * - * @param message Message to show to the user - */ - public void outputMessage (final String message); - - /** - * Displays a "box" for the name - * - * @param contact Contact to show name from - */ - public void displayNameBox (final Contact contact); - - /** - * Displays a "box" for other data - * - * @param contact Contact to show other data from - */ - public void displayOtherDataBox (final Contact contact); - - /** - * Let the user choose what to change on the address: [n]ame, [a]ddress, - * [o]ther - * - * @param contact Contact instance to let the user change data - * @throws UnhandledUserChoiceException If choice is not supported - */ - public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException; - - /** - * Asks the user for a choice and proceeds accordingly - * - * @throws UnhandledUserChoiceException If choice is not supported - */ - public void doUserMenuChoice () throws UnhandledUserChoiceException ; - - /** - * Enables isRunning attribute which singals that the client is running - */ - public void enableIsRunning(); - - /** - * Asks the the user to enter a single character which must match validChars - * - * @param validChars Valid chars that are accepted - * @param message Message to user - * @return Allowed character - */ - public char enterChar (final char[] validChars, final String message); - - /** - * Reads a string of minimum and maximum length from the user. An empty - * string should be generally not allowed, but might be okay for e.g. - * company name. - * - * @param minLength Minimum length of the string to read - * @param maxLength Maximum length of the string to read - * @param message Message to user - * @param allowEmpty Whether empty strings are allowed - * @return Entered string by user or null if empty string is allowed - */ - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty); - - /** - * Reads an integer (int) from the user - * - * @param minimum Minimum allowed number - * @param maximum Maximum allowed number - * @param message Message to user - * @return Entered string by user or null if empty string is allowed - */ - public int enterInt (final int minimum, final int maximum, final String message); - - /** - * Setter for current menu choice - * - * @param currentMenu Current menu choice - */ - public void setCurrentMenu (final String currentMenu); - - /** - * Some "Getter" for menu item - * - * @param accessKey Key to press to access this menu - * @param text Text to show to user - * @return - */ - public SelectableMenuItem getMenuItem (final char accessKey, final String text); - - /** - * Determines whether the client is still active by checking some - * conditions - * - * @return Whether the client is still active - */ - public boolean isRunning(); - - /** - * Shows given menu entry in client - * - * @param item Menu item to show - */ - public void showEntry (final SelectableMenuItem item); - - /** - * Shows introduction to user - */ - public void showWelcome(); - - /** - * Shows current menu selection to the user - */ - public void showCurrentMenu(); - - /** - * Inizializes this client - */ - public void initClient (); -} diff --git a/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/src/org/mxchange/addressbook/client/console/ConsoleClient.java deleted file mode 100644 index b97600e..0000000 --- a/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ /dev/null @@ -1,505 +0,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.client.console; - -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Scanner; -import org.mxchange.addressbook.UnhandledUserChoiceException; -import org.mxchange.addressbook.application.AddressbookApplication; -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.contact.user.UserContact; -import org.mxchange.addressbook.menu.Menu; -import org.mxchange.addressbook.menu.MenuTools; -import org.mxchange.addressbook.menu.console.ConsoleMenu; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; -import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; - -/** - * A client for the console - * - * @author Roland Haeder - */ -public class ConsoleClient extends BaseClient implements Client { - /** - * Scanner instance for reading data from console input - */ - private final Scanner scanner; - - /** - * Parameterless constructor - * @param application An instance of an Application class - */ - public ConsoleClient (final Application application) { - super(); - - // Set application instance - this.setApplication(application); - - // Init scanner instance - this.scanner = new Scanner(System.in); - } - - /** - * Displays a textual address "box" of given contact - * - * @param contact Contact to show address for - */ - @Override - public void displayAddressBox (final Contact contact) { - // Simple display ... - this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode())); - } - - /** - * Displays a textual name "box" of given contact - * - * @param contact Contact to show name for - */ - @Override - public void displayNameBox (final Contact contact) { - // Get translated gender as the user may want to see "Mr.", "Mrs." - String gender = contact.getTranslatedGender(); - - // Get company name - String companyName = contact.getCompanyName(); - - // If it is empty/null, then assume private contact - if ((companyName == null) || (companyName.isEmpty())) { - // Now put all together: gender, surname, family name - // @todo Use mask - this.outputMessage(MessageFormat.format("Anrede, Vorname, Name: {0} {1} {2}", gender, contact.getSurname(), contact.getFamilyName())); - } else { - // Company contact - this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName())); - } - } - - /** - * Displays a textual other data "box" of given contact - * - * @param contact Contact to show other data for - */ - @Override - public void displayOtherDataBox (final Contact contact) { - // Cellphone and such ... - this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment())); - } - - @Override - public void doChangeOwnAddressData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Own address data - String street = this.getContactManager().enterOwnStreet(); - - // Get zip code - int zipCode = this.getContactManager().enterOwnZipCode(); - - // Get city name - String city = this.getContactManager().enterOwnCity(); - - // Get country code - String countryCode = this.getContactManager().enterOwnCountryCode(); - - // Update address data - contact.updateAddressData(street, zipCode, city, countryCode); - } - - @Override - public void doChangeOwnNameData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Gender: - char gender = this.getContactManager().enterOwnGender(); - - // Surname - String surname = this.getContactManager().enterOwnSurname(); - - // Family name - String familyName = this.getContactManager().enterOwnFamilyName(); - - // And company - String companyName = this.getContactManager().enterOwnCompanyName(); - - // Update contact instance - contact.updateNameData(gender, surname, familyName, companyName); - } - - @Override - public void doChangeOwnOtherData (final Contact contact) { - // Make sure it is own contact - if (!contact.isOwnContact()) { - // Not own contact - throw new IllegalArgumentException("Contact is not own data."); - } - - // Phone number - String phoneNumber = this.getContactManager().enterOwnPhoneNumber(); - - // Phone number - String cellNumber = this.getContactManager().enterOwnCellNumber(); - - // Fax number - String faxNumber = this.getContactManager().enterOwnFaxNumber(); - - // Email address - String email = this.getContactManager().enterOwnEmailAddress(); - - // Comment - String comment = this.getContactManager().enterOwnComment(); - - // Update contact instance - contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment); - } - - @Override - public Contact doEnterOwnData () { - // First ask for gender - char gender = this.getContactManager().enterOwnGender(); - - // 2nd for surname - String surname = this.getContactManager().enterOwnSurname(); - - // And 3rd for family name - String familyName = this.getContactManager().enterOwnFamilyName(); - - // Company name ... - String companyName = this.getContactManager().enterOwnCompanyName(); - - // Construct UserContact instance - Contact contact = new UserContact(gender, surname, familyName, companyName); - - // And return object - return contact; - } - - /** - * Shutdown this client - */ - @Override - public void doShutdown () { - // Parent call - super.doShutdown(); - - // @TODO Add other shutdown stuff - } - - @Override - public void doUserMenuChoice () throws UnhandledUserChoiceException { - // Get all access keys from menu - char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu()); - - // Output textural message and ask for a char as input - char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); - - // @TODO Rewrite this ugly switch() block - switch (choice) { - case '1': // Enter/add own data - this.getContactManager().doEnterOwnData(); - break; - - case '2': // Change own data - this.getContactManager().changeOwnData(); - break; - - case '3': // Add new addess - this.getContactManager().addOtherAddress(); - break; - - case '4': // List contacts - this.getContactManager().listContacts(); - break; - - case '5': // Search addresses - this.getContactManager().searchContacts(); - break; - - case '6': // Change other addess - this.getContactManager().changeOtherAddress(); - break; - - case '7': // Delete other address - this.getContactManager().deleteOtherAddress(); - break; - - case '0': // Program exit - this.getApplication().doShutdown(); - break; - - default: - // @TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); - } - } - - /** - * Asks the the user to enter a single character which must match validChars - * @param validChars Valid chars that are accepted - * @param message Message to user - * @return Allowed character - */ - @Override - public char enterChar (final char[] validChars, final String message) { - char input = 0; - - // Sort array, else binarySearch() won't work - Arrays.sort(validChars); - - // Keep asking until valid char has been entered - while (Arrays.binarySearch(validChars, input) < 0) { - // Output message - System.out.print(message); - - // Read char - input = this.readChar(); - } - - // Return read char - return input; - } - - /** - * Reads an integer (int) with a textural message from the user - * - * @param minimum Minimum allowed number - * @param maximum Maximum allowed number - * @param message Messager to display in console - * @return - */ - @Override - public int enterInt (final int minimum, final int maximum, final String message) { - // Minimum should not be below zero - assert(minimum >= 0); - assert(maximum > minimum); - - // Init input - int input = -1; - - while ((input < minimum) || (input > maximum)) { - // Output message - System.out.print(message); - - // Read integer from user - input = this.readInt(); - } - - // Return it - return input; - } - - /** - * Reads a string of minimum and maximum length from the user - * - * @param minLength Minimum length of the string to read - * @param maxLength Maximum length of the string to read - * @param message Message to user - * @param allowEmpty Whether to allow empty string - * @return Entered string by user or null for empty strings - */ - @Override - public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) { - // Check on length, e.g. country codes are excactly 2 chars long - assert(maxLength >= minLength); - - // Init input - String input = null; - - // Check if it is to short or to long - while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) { - // Output message - System.out.print(message); - - // Read line - input = this.readString(); - } - - // Return it - return input; - } - - /** - * Returns a console menu item - * - * @param accessKey Key to access the menu - * @param text Text to show to user - * @return A SelectableMenuItem - * @todo Make sure the access key is unique - */ - @Override - public SelectableMenuItem getMenuItem (final char accessKey, final String text) { - // Return a new console menu item - return new ConsoleMenuItem(accessKey,text); - } - - /** - * Inizializes this client - */ - @Override - public void initClient () { - // Init contact manager here - this.initContactManager(); - - // Fill menu map - this.fillMenuMap(); - } - - /** - * Displays textural message to the user - * @param message - */ - @Override - public void outputMessage (final String message) { - System.out.println(message); - } - - /** - * Shows textural menu on console - */ - @Override - public void showCurrentMenu () { - this.showMenu(this.getCurrentMenu()); - } - - /** - * Shows given menu entry to user - * - * @param item Menu entry - */ - @Override - public void showEntry (final SelectableMenuItem item) { - // Access key then text - this.outputMessage("[" + item.getAccessKey() + "] " + item.getText()); - } - - /** - * Shows a textural message to the user - */ - @Override - public void showWelcome () { - this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle())); - this.outputMessage(""); - this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software"); - - // Debug message - this.getLogger().debug("Intro shown to user"); - } - - @Override - public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { - // Ask the user for editing [name], [a]ddress or [other] data - char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) "); - - // @TODO Get rid of this ugly switch block, too - switch (choice) { - case 'n': // Name data - this.getContactManager().doChangeNameData(contact, this); - break; - - case 'a': // Address data - this.getContactManager().doChangeAddressData(contact, this); - break; - - case 'o': // Other data - this.getContactManager().doChangeOtherData(contact, this); - break; - - case 'x': // Exit this menu - // Ignored as it should go back - break; - - default: - // @TODO throw own exception - throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); - } - } - - /** - * Reads one character - * - * @return A single character - */ - private char readChar () { - // Read line - String input = this.scanner.nextLine(); - - // This must be only one character - if (input.length() != 1) { - // Return zero - return 0; - } - - // Get char from first (and only) position - return input.charAt(0); - } - - /** - * Reads an integer (int) from user - * - * @return An integer number - */ - private int readInt () { - // First read a string - String input = this.readString(); - - // Init number with invalid value - int num = -1; - - // Parse number, this can be risky - try { - num = Integer.parseInt(input); - } catch (final NumberFormatException e) { - this.outputMessage("Bitte geben Sie nur Zahlen ein!"); - this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); - } - - // Return read number - return num; - } - - /** - * Reads a string from a scanner until RETURN is pressed - * - * @return Read string from scanner - */ - private String readString () { - return this.scanner.nextLine(); - } - - /** - * Fills menu map with menu entries - */ - @Override - protected final void fillMenuMap () { - // Initialize first (main) menu - Menu menu = new ConsoleMenu("main", this); - - // Add it - this.getMenus().put("main", menu); - } -} diff --git a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form b/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form deleted file mode 100644 index d6899f3..0000000 --- a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.form +++ /dev/null @@ -1,197 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java deleted file mode 100644 index 451d525..0000000 --- a/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ /dev/null @@ -1,355 +0,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.client.gui; - -import java.awt.Color; -import java.awt.Cursor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ResourceBundle; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.GroupLayout; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JToolBar; -import javax.swing.KeyStroke; -import javax.swing.LayoutStyle; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; -import javax.swing.UIManager; -import javax.swing.WindowConstants; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.mxchange.addressbook.application.AddressbookApplication; -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.manager.contact.ManageableContact; -import org.mxchange.addressbook.model.address.AddressTableModel; - -/** - * - * @author Roland Haeder - */ -public class AddressbookFrame extends javax.swing.JFrame implements ClientFrame { - /** - * Class' logger - */ - private final Logger LOG; - - /** - * Client instance - */ - private final Client client; - - /** - * Own instance - */ - private static ClientFrame self; - - /** - * Bundle instance - */ - private final ResourceBundle bundle; - - /** - * Initialize object - */ - { - LOG = LogManager.getLogger(this); - bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N - } - - /** - * Creates an instance of this frame with a client instance - * @param client - */ - private AddressbookFrame (final Client client) { - // Debug line - this.getLogger().debug("Initializing Swing frame ..."); - - // Set client here - this.client = client; - } - - @Override - public Application getApplication () { - throw new UnsupportedOperationException("Not implemented."); - } - - @Override - public final Client getClient () { - return this.client; - } - - @Override - public ManageableContact getContactManager () { - throw new UnsupportedOperationException("Not implemented."); - } - - @Override - public void initFrame () { - // Init components - this.initComponents(); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings ("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - statusPanel = new JPanel(); - statusLabel = new JLabel(); - listAddressesPanel = new JScrollPane(); - addressesTable = new JTable(); - toolBar = new JToolBar(); - menuBar = new JMenuBar(); - mainMenu = new JMenu(); - exitProgram = new JMenuItem(); - addressbookMenu = new JMenu(); - addOwnData = new JMenuItem(); - - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - setTitle(AddressbookApplication.printableTitle()); - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - setName("main"); // NOI18N - addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent evt) { - exitProgram(evt); - } - public void windowClosing(WindowEvent evt) { - AddressbookFrame.this.windowClosing(evt); - } - }); - - statusPanel.setBorder(BorderFactory.createEtchedBorder(Color.lightGray, new Color(153, 153, 153))); - statusPanel.setAutoscrolls(true); - statusPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - statusPanel.setFocusable(false); - statusPanel.setName("status"); // NOI18N - statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); - - ResourceBundle bundle = ResourceBundle.getBundle("org/mxchange/addressbook/localization/bundle"); // NOI18N - statusLabel.setText(bundle.getString("AddressbookFrame.statusLabel.text_1")); // NOI18N - statusLabel.setHorizontalTextPosition(SwingConstants.LEFT); - statusLabel.setName("statusLabel"); // NOI18N - statusPanel.add(statusLabel); - - listAddressesPanel.setName("listAddressesPanel"); // NOI18N - - addressesTable.setModel(new AddressTableModel(this.getClient())); - addressesTable.setColumnSelectionAllowed(true); - addressesTable.setFillsViewportHeight(true); - addressesTable.setFocusable(false); - addressesTable.setName("addressesTable"); // NOI18N - listAddressesPanel.setViewportView(addressesTable); - addressesTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - - toolBar.setFloatable(false); - toolBar.setRollover(true); - toolBar.setName("toolBar"); // NOI18N - - menuBar.setName("menuBar"); // NOI18N - - ResourceBundle bundle1 = ResourceBundle.getBundle("org/mxchange/addressbook/client/gui/Bundle"); // NOI18N - mainMenu.setText(bundle1.getString("AddressbookFrame.text")); // NOI18N - mainMenu.setFocusable(false); - mainMenu.setName(""); // NOI18N - - exitProgram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK)); - exitProgram.setText(bundle.getString("AddressbookFrame.exitProgram.text_1")); // NOI18N - exitProgram.setName("exitProgram"); // NOI18N - exitProgram.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - exitProgramActionPerformed(evt); - } - }); - mainMenu.add(exitProgram); - - menuBar.add(mainMenu); - - addressbookMenu.setText(bundle.getString("AddressbookFrame.addressbookMenu.text_1")); // NOI18N - addressbookMenu.setName("addressbookMenu"); // NOI18N - - addOwnData.setText(bundle1.getString("AddressbookFrame.addOwn.text")); // NOI18N - addOwnData.setName("addOwn"); // NOI18N - addOwnData.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - addOwnDataActionPerformed(evt); - } - }); - addressbookMenu.add(addOwnData); - addOwnData.getAccessibleContext().setAccessibleName(bundle.getString("AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1")); // NOI18N - - menuBar.add(addressbookMenu); - - setJMenuBar(menuBar); - - GroupLayout layout = new GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(statusPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(listAddressesPanel, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE) - .addComponent(toolBar, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(toolBar, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(listAddressesPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGap(1, 1, 1) - .addComponent(statusPanel, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)) - ); - - statusPanel.getAccessibleContext().setAccessibleName(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleName")); // NOI18N - statusPanel.getAccessibleContext().setAccessibleDescription(bundle1.getString("AddressbookFrame.status.AccessibleContext.accessibleDescription")); // NOI18N - - pack(); - }// //GEN-END:initComponents - - private void exitProgramActionPerformed(ActionEvent evt) {//GEN-FIRST:event_exitProgramActionPerformed - // Close application instance - dispose(); - }//GEN-LAST:event_exitProgramActionPerformed - - private void addOwnDataActionPerformed(ActionEvent evt) {//GEN-FIRST:event_addOwnDataActionPerformed - // Asks the user to enter own data - this.getClient().getContactManager().doEnterOwnData(); - }//GEN-LAST:event_addOwnDataActionPerformed - - private void windowClosing(WindowEvent evt) {//GEN-FIRST:event_windowClosing - // TODO add your handling code here: - dispose(); - }//GEN-LAST:event_windowClosing - - private void exitProgram(WindowEvent evt) {//GEN-FIRST:event_exitProgram - // TODO add your handling code here: - this.getClient().getApplication().doShutdown(); - }//GEN-LAST:event_exitProgram - - /** - * Setups the frame - * - * @param client Client instance - */ - @Override - public void setupFrame (final Client 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); - } - - /* - * Set the Nimbus look and feel - */ - // - /* - * If Nimbus (introduced in Java SE 6) is not available, stay with the - * default look and feel. For details see - * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try { - for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (final ClassNotFoundException ex) { - this.getLogger().catching(ex); - } catch (final InstantiationException ex) { - this.getLogger().catching(ex); - } catch (final IllegalAccessException ex) { - this.getLogger().catching(ex); - } catch (final javax.swing.UnsupportedLookAndFeelException ex) { - this.getLogger().catching(ex); - } - // - - // All done here - statusLabel.setText(bundle.getString("AddressbookFrame.status.done.text")); - - // Debug line - this.getLogger().debug("Displaying form ..."); - - /* - * Create and display the form - */ - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run () { - AddressbookFrame.getSelfInstance(client).setVisible(true); - } - }); - } - - /** - * 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; - } - - /** - * Getter for logger - * - * @return Logger - */ - protected final Logger getLogger () { - return this.LOG; - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private JMenuItem addOwnData; - private JMenu addressbookMenu; - private JTable addressesTable; - private JMenuItem exitProgram; - private JScrollPane listAddressesPanel; - private JMenu mainMenu; - private JMenuBar menuBar; - private JLabel statusLabel; - private JPanel statusPanel; - private JToolBar toolBar; - // End of variables declaration//GEN-END:variables -} diff --git a/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/src/org/mxchange/addressbook/client/gui/ClientFrame.java deleted file mode 100644 index 17318d4..0000000 --- a/src/org/mxchange/addressbook/client/gui/ClientFrame.java +++ /dev/null @@ -1,47 +0,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.client.gui; - -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.client.Client; - -/** - * - * @author Roland Haeder - */ -public interface ClientFrame extends FrameworkInterface { - - /** - * From JFrame - * - * @param visible Set visibility - */ - public void setVisible (boolean visible); - - /** - * 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 - */ - public void initFrame (); -} diff --git a/src/org/mxchange/addressbook/client/gui/SwingClient.java b/src/org/mxchange/addressbook/client/gui/SwingClient.java deleted file mode 100644 index 9ea4e88..0000000 --- a/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ /dev/null @@ -1,181 +0,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.client.gui; - -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(); - - // Init frame - this.frame.initFrame(); - - // 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."); - } -} diff --git a/src/org/mxchange/addressbook/contact/BaseContact.java b/src/org/mxchange/addressbook/contact/BaseContact.java deleted file mode 100644 index 78d4f07..0000000 --- a/src/org/mxchange/addressbook/contact/BaseContact.java +++ /dev/null @@ -1,600 +0,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.contact; - -import java.util.Objects; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.client.Client; - -/** - * A general contact - * - * @author Roland Haeder - * @version 0.0 - * @since 0.0 - */ -public class BaseContact extends BaseFrameworkSystem { - /** - * Amount of columns - */ - public static final int COLUMN_COUNT = 14; - - /** - * Birth day - */ - private String birthday; - - /** - * Cellphone number - */ - private String cellphoneNumber; - - /** - * City - */ - private String city; - - /** - * Optional comments - */ - private String comment; - - /** - * Companyname - */ - private String companyName; - - /** - * Country code - */ - private String countryCode; - - /** - * Email address - */ - private String emailAddress; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number - */ - private String faxNumber; - - /** - * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C = - * Company - */ - private char gender; - - /** - * House number - */ - private int houseNumber; - - /** - * Marker whether this contact is user's own data - */ - private boolean ownContact; - - /** - * Phone number - */ - private String phoneNumber; - - /** - * Street - */ - private String street; - - /** - * Surname - */ - private String surname; - - /** - * ZIP code - */ - private long zipCode; - - /** - * No instances can be created of this class - */ - protected BaseContact () { - super(); - } - - /** - * Check if contacts are same or throw an exception - * - * @param object Other possible contact class - * @return Whether both contacts are same - * @todo Needs a lot improvements - */ - @Override - public boolean equals (Object object) { - // Is it same type? - if (!(object instanceof BaseContact)) { - // Not equal types - return false; - } else if (!(object instanceof Contact)) { - // Not correct interface - return false; - } - - // Try to cast - Contact contact = (Contact) object; - - // Now test some data @todo Definedly needs improvement - return ((this.getGender() == contact.getGender()) - && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase())) - && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); - } - - /** - * Birth day - * - * @return the birthday - */ - public String getBirthday () { - return this.birthday; - } - - /** - * Birth day - * - * @param birthday the birthday to set - */ - public void setBirthday (final String birthday) { - this.birthday = birthday; - } - - /** - * Cellphone number - * - * @return the cellphoneNumber - */ - public String getCellphoneNumber () { - return this.cellphoneNumber; - } - - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set - */ - public void setCellphoneNumber (final String cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - /** - * City - * - * @return the city - */ - public String getCity () { - return this.city; - } - - /** - * City - * - * @param city the city to set - */ - public void setCity (final String city) { - this.city = city; - } - - /** - * Comments - * - * @return the comment - */ - public String getComment () { - return this.comment; - } - - /** - * Comments - * - * @param comment the comment to set - */ - public void setComment (final String comment) { - this.comment = comment; - } - - /** - * Companyname - * - * @return the companyName - */ - public String getCompanyName () { - return this.companyName; - } - - /** - * Companyname - * - * @param companyName the companyName to set - */ - public void setCompanyName (final String companyName) { - this.companyName = companyName; - } - - /** - * Country code - * - * @return the countryCode - */ - public String getCountryCode () { - return this.countryCode; - } - - /** - * Country code - * - * @param countryCode the countryCode to set - */ - public void setCountryCode (final String countryCode) { - this.countryCode = countryCode; - } - - /** - * "Serializes" this object into a CSV string (this time with semicolons) - * - * @return "CSV-serialized" version of the stored data - */ - public String getCsvStringFromStoreableObject () { - // Get all together - String csvString = String.format( - "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n", - this.isOwnContact(), - this.getGender(), - this.getSurname(), - this.getFamilyName(), - this.getCompanyName(), - this.getStreet(), - this.getZipCode(), - this.getCity(), - this.getCountryCode(), - this.getPhoneNumber(), - this.getFaxNumber(), - this.getCellphoneNumber(), - this.getEmailAddress(), - this.getBirthday(), - this.getComment() - ); - - // Then return it - return csvString; - } - - /** - * Email address - * - * @return the emailAddress - */ - public String getEmailAddress () { - return this.emailAddress; - } - - /** - * Email address - * - * @param emailAddress the emailAddress to set - */ - public void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - /** - * Family name - * - * @return the familyName - */ - public String getFamilyName () { - return this.familyName; - } - - /** - * Family name - * - * @param familyName the familyName to set - */ - public void setFamilyName (final String familyName) { - this.familyName = familyName; - } - - /** - * Fax number - * - * @return the faxNumber - */ - public String getFaxNumber () { - return this.faxNumber; - } - - /** - * Fax number - * - * @param faxNumber the faxNumber to set - */ - public void setFaxNumber (final String faxNumber) { - this.faxNumber = faxNumber; - } - - /** - * Gender of the contact - * - * @return the gender - */ - public char getGender () { - return this.gender; - } - - /** - * Gender of the contact - * - * @param gender the gender to set - */ - public void setGender (final char gender) { - this.gender = gender; - } - - /** - * House number - * - * @return the houseNumber - */ - public int getHouseNumber () { - return this.houseNumber; - } - - /** - * House number - * - * @param houseNumber the houseNumber to set - */ - public void setHouseNumber (final int houseNumber) { - this.houseNumber = houseNumber; - } - - /** - * Phone number - * - * @return the phoneNumber - */ - public String getPhoneNumber () { - return this.phoneNumber; - } - - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ - public void setPhoneNumber (final String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - /** - * Street - * - * @return the street - */ - public String getStreet () { - return this.street; - } - - /** - * Street - * - * @param street the street to set - */ - public void setStreet (final String street) { - this.street = street; - } - - /** - * Surname - * - * @return the surname - */ - public String getSurname () { - return this.surname; - } - - /** - * Surname - * - * @param surname the surname to set - */ - public void setSurname (final String surname) { - this.surname = surname; - } - - /** - * Some "getter" for a translated/human-readable gender - * @return gender Human-readable gender - */ - public String getTranslatedGender () { - // Default init - String translated = null; - - // "Translate" it - switch (this.getGender()) { - case 'M': // Mr. - translated = "Herr"; - break; - - case 'F': // Mrs. - translated = "Frau"; - break; - - case 'C': // "Company" - translated = "Firma"; - break; - - default: // Unsupported - this.getLogger().error("Gender " + this.getGender() + " not supported."); - break; - } - - // Return it - return translated; - } - - /** - * ZIP code - * - * @return the zipCode - */ - public long getZipCode () { - return this.zipCode; - } - - /** - * ZIP code - * - * @param zipCode the zipCode to set - */ - public void setZipCode (final long zipCode) { - this.zipCode = zipCode; - } - - @Override - public int hashCode () { - int hash = 7; - hash = 79 * hash + Objects.hashCode(this.getFamilyName()); - hash = 79 * hash + this.getGender(); - hash = 79 * hash + Objects.hashCode(this.getSurname()); - return hash; - } - - /** - * Checks whether the contact is user's own data - * - * @return Own data? - */ - public boolean isOwnContact () { - return this.ownContact; - } - - /** - * Shows this contact to the user - * - * @param client Client instance to use - */ - public void show (final Client client) { - // Display name "box" - client.displayNameBox((Contact) this); - - // Display address "box" - client.displayAddressBox((Contact) this); - - // Display other data "box" - client.displayOtherDataBox((Contact) this); - } - - /** - * Updates address data in this Contact instance - * - * @param street Street - * @param zipCode ZIP code - * @param city City - * @param countryCode Country code - */ - public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) { - // Set all - if (street != null) { - this.setStreet(street); - } - if (zipCode > 0) { - this.setZipCode(zipCode); - } - if (city != null) { - this.setCity(city); - } - if (countryCode != null) { - this.setCountryCode(countryCode); - } - } - - /** - * Updates name data in this Contact instance - * @param gender Gender (M, F, C) - * @param surname Surname - * @param familyName Family name - * @param companyName Company name - */ - public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) { - // Set all - this.setGender(gender); - if (surname != null) { - this.setSurname(surname); - } - if (familyName != null) { - this.setFamilyName(familyName); - } - if (companyName != null) { - this.setCompanyName(companyName); - } - } - - /** - * Updates other data in this Contact instance - * - * @param phoneNumber Phone number - * @param cellphoneNumber Cellphone number - * @param faxNumber Fax number - * @param emailAddress Email address - * @param birthday Birth day - * @param comment Comments - */ - public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) { - // Set all - if (phoneNumber != null) { - this.setPhoneNumber(phoneNumber); - } - if (cellphoneNumber != null) { - this.setCellphoneNumber(cellphoneNumber); - } - if (faxNumber != null) { - this.setFaxNumber(faxNumber); - } - if (emailAddress != null) { - this.setEmailAddress(emailAddress); - } - if (birthday != null) { - this.setBirthday(birthday); - } - if (comment != null) { - this.setComment(comment); - } - } - - /** - * Enables the flag "own data" which signals that this contact is the user's - * own data. - */ - protected void enableFlagOwnContact () { - this.ownContact = true; - } -} diff --git a/src/org/mxchange/addressbook/contact/Contact.java b/src/org/mxchange/addressbook/contact/Contact.java deleted file mode 100644 index 2860ee2..0000000 --- a/src/org/mxchange/addressbook/contact/Contact.java +++ /dev/null @@ -1,184 +0,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.contact; - -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.client.Client; - -/** - * - * @author Roland Haeder - */ -public interface Contact extends FrameworkInterface { - - /** - * Some "getter" for translated gender of the contact - * @return Translated / human-readable gender - */ - public String getTranslatedGender(); - - /** - * Checks whether the contact is user's own data - * - * @return Own data? - */ - public boolean isOwnContact(); - - /** - * Gender of the contact - * - * @return the gender - */ - public char getGender(); - - /** - * Surname - * - * @return the surname - */ - public String getSurname(); - - /** - * Family name - * - * @return the familyName - */ - public String getFamilyName(); - - /** - * Companyname - * - * @return the companyName - */ - public String getCompanyName(); - - /** - * Street - * - * @return the street - */ - public String getStreet(); - - /** - * House number - * - * @return the houseNumber - */ - public int getHouseNumber(); - - /** - * ZIP code - * - * @return the zipCode - */ - public long getZipCode(); - - /** - * City - * - * @return the city - */ - public String getCity(); - - /** - * Country code - * - * @return the countryCode - */ - public String getCountryCode(); - - /** - * Email address - * - * @return the emailAddress - */ - public String getEmailAddress(); - - /** - * Phone number - * - * @return the phoneNumber - */ - public String getPhoneNumber(); - - /** - * Fax number - * - * @return the faxNumber - */ - public String getFaxNumber(); - - /** - * Cellphone number - * - * @return the cellphoneNumber - */ - public String getCellphoneNumber(); - - /** - * Birth day - * - * @return the birthday - */ - public String getBirthday(); - - /** - * Comments - * - * @return the comment - */ - public String getComment(); - - /** - * Shows the contact to the user - * - * @param client Client instance to call back - */ - public void show (final Client client); - - /** - * Updates address data in this Contact instance - * - * @param street Street - * @param zipCode ZIP code - * @param city City - * @param countryCode Country code - */ - public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode); - - /** - * Updates name data in this Contact instance - * - * @param gender Gender (M, F, C) - * @param surname Surname - * @param familyName Family name - * @param companyName Company name - */ - public void updateNameData (final char gender, final String surname, final String familyName, final String companyName); - - /** - * Updates other data in this Contact instance - * - * @param phoneNumber Phone number - * @param cellNumber Cellphone number - * @param faxNumber Fax number - * @param email Email address - * @param birthday Birthday - * @param comment Comments - */ - public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String birthday, final String comment); -} diff --git a/src/org/mxchange/addressbook/contact/book/BookContact.java b/src/org/mxchange/addressbook/contact/book/BookContact.java deleted file mode 100644 index 02d4218..0000000 --- a/src/org/mxchange/addressbook/contact/book/BookContact.java +++ /dev/null @@ -1,38 +0,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.contact.book; - -import org.mxchange.addressbook.contact.BaseContact; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.database.storage.csv.StoreableCsv; - -/** - * A contact that can be placed into "contact books" - * - * @author Roland Haeder - * @version 0.0 - * @since 0.0 - */ -public class BookContact extends BaseContact implements Contact, StoreableCsv { - - /** - * Default constructor, may only be used from database backend - */ - public BookContact () { - } - -} diff --git a/src/org/mxchange/addressbook/contact/user/UserContact.java b/src/org/mxchange/addressbook/contact/user/UserContact.java deleted file mode 100644 index 1f9b141..0000000 --- a/src/org/mxchange/addressbook/contact/user/UserContact.java +++ /dev/null @@ -1,55 +0,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.contact.user; - -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.contact.book.BookContact; -import org.mxchange.addressbook.database.storage.csv.StoreableCsv; - -/** - * - * @author Roland Haeder - * @todo After a Collection has been used in ContactManager, change to BaseContact - */ -public class UserContact extends BookContact implements Contact, StoreableCsv { - - /** - * Creates own contact entry - * - * @param gender Gender to be set - * @param surname Surname to be set - * @param familyName Family name to be set - * @param companyName Company name - * @todo Add validation of data - */ - public UserContact (final char gender, final String surname, final String familyName, final String companyName) { - // Make sure all constructors are called - this(); - - this.setGender(gender); - this.setSurname(surname); - this.setFamilyName(familyName); - this.setCompanyName(companyName); - } - - /** - * Default constructor, may only be used from database backend - */ - public UserContact () { - this.enableFlagOwnContact(); - } -} diff --git a/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java b/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java deleted file mode 100644 index 539f6d2..0000000 --- a/src/org/mxchange/addressbook/database/backend/BaseDatabaseBackend.java +++ /dev/null @@ -1,32 +0,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.database.backend; - -import org.mxchange.addressbook.BaseFrameworkSystem; - -/** - * Generall database backend - * - * @author Roland Haeder - */ -public class BaseDatabaseBackend extends BaseFrameworkSystem { - /** - * No instances from this class - */ - protected BaseDatabaseBackend () { - } -} diff --git a/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java b/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java deleted file mode 100644 index 5b2d42d..0000000 --- a/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java +++ /dev/null @@ -1,54 +0,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.database.backend; - -import java.io.IOException; -import org.mxchange.addressbook.FrameworkInterface; -import org.mxchange.addressbook.database.storage.Storeable; - -/** - * A generic interface for database frontends - * - * @author Roland Haeder - */ -public interface DatabaseBackend extends FrameworkInterface { - - /** - * Shuts down this backend - */ - public void doShutdown (); - - /** - * Rewinds backend - */ - public void rewind (); - - /** - * Get length of underlaying file - * - * @return Length of underlaying file - */ - public long length (); - - /** - * Stores an object in the database. - * - * @param object Object to store in database - * @throws java.io.IOException From inner class - */ - public void store (final Storeable object) throws IOException; -} diff --git a/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java b/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java deleted file mode 100644 index 704cbb6..0000000 --- a/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java +++ /dev/null @@ -1,36 +0,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.database.backend.csv; - -import java.util.Iterator; -import org.mxchange.addressbook.BadTokenException; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.database.backend.DatabaseBackend; - -/** - * - * @author Roland Haeder - */ -public interface CsvBackend extends DatabaseBackend { - - /** - * Gets an iterator for contacts - * - * @return Iterator for contacts - */ - public Iterator contactIterator () throws BadTokenException; -} diff --git a/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java b/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java deleted file mode 100644 index 0bc97f3..0000000 --- a/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java +++ /dev/null @@ -1,492 +0,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.database.backend.csv; - -import java.io.DataOutput; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; -import org.mxchange.addressbook.BadTokenException; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.contact.book.BookContact; -import org.mxchange.addressbook.contact.user.UserContact; -import org.mxchange.addressbook.database.backend.BaseDatabaseBackend; -import org.mxchange.addressbook.database.storage.Storeable; -import org.mxchange.addressbook.database.storage.csv.StoreableCsv; - -/** - * A database backend with CSV file as storage implementation - * - * @author Roland Haeder - */ -public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend { - /** - * Output stream for this storage engine - */ - private RandomAccessFile storageFile; - - /** - * Constructor with table name - * - * @param tableName Name of "table" - */ - public CsvDatabaseBackend (final String tableName) { - // Debug message - this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName)); - - // Set table name here, too - this.setTableName(tableName); - - // Construct file name - String fileName = String.format("data/table_%s.csv", tableName); - - // Debug message - this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName)); - - try { - // Try to initialize the storage (file instance) - this.storageFile = new RandomAccessFile(fileName, "rw"); - } catch (final FileNotFoundException ex) { - // Did not work - this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString())); - System.exit(1); - } - - // Output message - this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName)); - } - - /** - * Gets an iterator for contacts - * - * @return Iterator for contacts - * @throws org.mxchange.addressbook.BadTokenException If the underlaying method has found an invalid token - */ - @Override - public Iterator contactIterator () throws BadTokenException { - /* - * Then read the file into RAM (yes, not perfect for >1000 entries ...) - * and get a List back. - */ - List list = this.readContactList(); - - // Get iterator from list and return it - return list.iterator(); - } - - /** - * Shuts down this backend - */ - @Override - public void doShutdown () { - try { - // Close file - this.storageFile.close(); - } catch (final IOException ex) { - this.getLogger().catching(ex); - System.exit(1); - } - } - - /** - * Get length of underlaying file - * - * @return Length of underlaying file - */ - @Override - public long length () { - long length = 0; - - try { - length = this.storageFile.length(); - this.getLogger().debug(MessageFormat.format("length={0}", length)); - } catch (final IOException ex) { - // Length cannot be determined - this.getLogger().catching(ex); - System.exit(1); - } - - // Return result - this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); - return length; - } - - /** - * Rewinds backend - */ - @Override - public void rewind (){ - this.getLogger().trace("CALLED!"); - - try { - // Rewind underlaying database file - this.storageFile.seek(0); - } catch (final IOException ex) { - this.getLogger().catching(ex); - System.exit(1); - } - - this.getLogger().trace("EXIT!"); - } - - /** - * Stores given object by "visiting" it - * - * @param object An object implementing Storeable - * @throws java.io.IOException From "inner" class - */ - @Override - public void store (final Storeable object) throws IOException { - // Make sure the instance is there (DataOutput flawor) - assert(this.storageFile instanceof DataOutput); - - // Try to cast it, this will fail if the interface is not implemented - StoreableCsv csv = (StoreableCsv) object; - - // Now get a string from the object that needs to be stored - String str = csv.getCsvStringFromStoreableObject(); - - // Debug message - this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str)); - - // The string is now a valid CSV string - this.storageFile.writeBytes(str); - } - - /** - * Adds given contact to list - * - * @param contact Contact instance to add - * @param list List instance - */ - private void addContactToList (final Contact contact, final List list) { - // Debug message - this.getLogger().debug(MessageFormat.format("contact={0}", contact)); - - // Is the contact read? - if (contact instanceof Contact) { - // Then add it - boolean added = list.add(contact); - - // Debug message - this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); - - // Has it been added? - if (!added) { - // Not added - this.getLogger().warn("Contact object has not been added."); - } - } - } - - /** - * Checks whether end of file has been reached - * - * @return Whether lines are left to read - */ - private boolean isEndOfFile () { - // Default is EOF - boolean isEof = true; - - try { - isEof = (this.storageFile.getFilePointer() >= this.length()); - } catch (final IOException ex) { - // Length cannot be determined - this.getLogger().catching(ex); - } - - // Return status - this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof)); - return isEof; - } - - /** - * Reads the database file, if available, and adds all read lines into - * the list. - * - * @return A list with Contact instances - */ - private List readContactList () throws BadTokenException { - this.getLogger().trace("CALLED!"); - - // First rewind - this.rewind(); - - // Get file size and divide it by 140 (possible average length of one line) - int lines = Math.round(this.length() / 140 + 0.5f); - - // Debug message - this.getLogger().debug(MessageFormat.format("lines={0}", lines)); - - // Instance list - // @TODO The maximum length could be guessed from file size? - List list = new ArrayList<>(lines); - - // Init variables - StringTokenizer tokenizer; - String line; - - // Read all lines - while (!this.isEndOfFile()) { - // Then read a line - line = this.readLine(); - - // Debug message - this.getLogger().debug(MessageFormat.format("line={0}", line)); - - // Then tokenize it - // @TODO Move this into separate method - tokenizer = new StringTokenizer(line, ";"); - - // Count round - int count = 0; - - // Init contact object - Contact contact = null; - - // The tokens are now available, so get all - while (tokenizer.hasMoreElements()) { - // Get next token - String token = tokenizer.nextToken(); - - // Debug message - this.getLogger().debug(MessageFormat.format("token={0}", token)); - - // Verify token, it must have double-quotes on each side - if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { - // Something bad was read - throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token)); - } - - // All fine, so remove it - String strippedToken = token.substring(1, token.length() - 1); - - // Is the string's content "null"? - if (strippedToken.equals("null")) { - // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken)); - - // This needs to be set to null - strippedToken = null; - } - - // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken)); - - // Init number/string data values - String strData = strippedToken; - Long num = null; - Boolean bool = null; - char gender = '?'; - - // Now, let's try a number check, if no null - if (strippedToken != null) { - // Okay, no null, maybe the string bears a decimal number? - try { - num = Long.valueOf(strippedToken); - - // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); - } catch (final NumberFormatException ex) { - // No number, then set default - num = null; - } - } - - // Now, let's try a boolean check, if no null - if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { - // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken)); - - // parseBoolean() is relaxed, so no exceptions - bool = Boolean.valueOf(strippedToken); - } - - // Now, let's try a boolean check, if no null - if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) { - // Get first character - gender = strippedToken.charAt(0); - } - - // Now it depends on the counter which position we need to check - switch (count) { - case 0: // isOwnContact - assert((bool instanceof Boolean)); - - // Debug message - this.getLogger().debug(MessageFormat.format("bool={0}", bool)); - - // Is it own contact? - if (true == bool) { - // Debug message - this.getLogger().debug("Creating UserContact object ..."); - - // Own entry - contact = new UserContact(); - } else { - // Debug message - this.getLogger().debug("Creating BookContact object ..."); - - // Other contact - contact = new BookContact(); - } - break; - - case 1: // Gender - assert(contact instanceof Contact) : "First token was not boolean"; - assert(gender != '?') : "Gender is not detected."; - - // Update data - contact.updateNameData(gender, null, null, null); - break; - - case 2: // Surname - assert(contact instanceof Contact) : "First token was not boolean"; - assert(gender != '?') : "Gender is not detected."; - - // Update data - contact.updateNameData(gender, strippedToken, null, null); - break; - - case 3: // Family name - assert(contact instanceof Contact) : "First token was not boolean"; - assert(gender != '?') : "Gender is not detected."; - - // Update data - contact.updateNameData(gender, null, strippedToken, null); - break; - - case 4: // Company name - assert(contact instanceof Contact) : "First token was not boolean"; - assert(gender != '?') : "Gender is not detected."; - - // Update data - contact.updateNameData(gender, null, null, strippedToken); - break; - - case 5: // Street number - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateAddressData(strippedToken, 0, null, null); - break; - - case 6: // ZIP code - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateAddressData(null, num, null, null); - break; - - case 7: // City name - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateAddressData(null, 0, strippedToken, null); - break; - - case 8: // Country code - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateAddressData(null, 0, null, strippedToken); - break; - - case 9: // Phone number - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(strippedToken, null, null, null, null, null); - break; - - case 10: // Fax number - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(null, strippedToken, null, null, null, null); - break; - - case 11: // Cellphone number - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(null, null, strippedToken, null, null, null); - break; - - case 12: // Email address - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(null, null, null, strippedToken, null, null); - break; - - case 13: // Birthday - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(null, null, null, null, strippedToken, null); - break; - - case 14: // Birthday - assert(contact instanceof Contact) : "First token was not boolean"; - - // Update data - contact.updateOtherData(null, null, null, null, null, strippedToken); - break; - - default: // New data entry - this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); - break; - } - - // Increment counter for next round - count++; - } - - // Add contact - this.addContactToList(contact, list); - } - - // Return finished list - this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); - return list; - } - - /** - * Reads a line from file base - * - * @return Read line from file - */ - private String readLine () { - // Init input - String input = null; - - try { - input = this.storageFile.readLine(); - } catch (final IOException ex) { - this.getLogger().catching(ex); - } - - // Return read string or null - return input; - } -} diff --git a/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java b/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java deleted file mode 100644 index de208ba..0000000 --- a/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java +++ /dev/null @@ -1,66 +0,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.database.frontend; - -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.database.backend.DatabaseBackend; -import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend; - -/** - * General database frontend class - * - * @author Roland Haeder - */ -public class BaseDatabaseFrontend extends BaseFrameworkSystem { - - /** - * Instance for database backend - */ - private DatabaseBackend backend; - - /** - * No instances from this class - */ - protected BaseDatabaseFrontend () { - } - - /** - * Instance for database backend - * - * @return the backend - */ - protected DatabaseBackend getBackend () { - return this.backend; - } - - /** - * Instance for database backend - * - * @param backend the backend to set - */ - protected void setBackend (final DatabaseBackend backend) { - this.backend = backend; - } - - /** - * Initialize backend - */ - protected void initBackend () { - // Instance backend - this.backend = new CsvDatabaseBackend(this.getTableName()); - } -} diff --git a/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java b/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java deleted file mode 100644 index 0bf6cc3..0000000 --- a/src/org/mxchange/addressbook/database/frontend/DatabaseWrapper.java +++ /dev/null @@ -1,27 +0,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.database.frontend; - -import org.mxchange.addressbook.FrameworkInterface; - -/** - * A generic interface for database frontends - * - * @author Roland Haeder - */ -public interface DatabaseWrapper extends FrameworkInterface { -} diff --git a/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java deleted file mode 100644 index df1854c..0000000 --- a/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java +++ /dev/null @@ -1,129 +0,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.database.frontend.contact; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import org.mxchange.addressbook.BadTokenException; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.database.backend.csv.CsvBackend; -import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend; -import org.mxchange.addressbook.database.storage.Storeable; -import org.mxchange.addressbook.manager.contact.ContactManager; - -/** - * Stores and retrieves Contact instances - * - * @author Roland Haeder - */ -public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper { - /** - * Constructor which accepts a contact manager - * @param manager - */ - public ContactDatabaseFrontend (final ContactManager manager) { - // Call own constructor - this(); - - // Set contact manager - this.setContactManager(manager); - } - - /** - * Basic constrcutor - */ - protected ContactDatabaseFrontend () { - super(); - - // Set "table" name - this.setTableName("contacts"); - - // Initalize backend - this.initBackend(); - } - - /** - * Shuts down the database layer - */ - @Override - public void doShutdown () { - // Shutdown backend - this.getBackend().doShutdown(); - } - - /** - * Flushes all contact entries to database - */ - @Override - public void flushAllContacts () { - // Get full list - List contacts = this.getContactManager().getList(); - - // Get iterator - Iterator iterator = contacts.iterator(); - - // Rewind backend - this.getBackend().rewind(); - - // Get all entries - while (iterator.hasNext()) { - // Get next entry - Contact contact = iterator.next(); - - try { - // Store this entry - this.getBackend().store((Storeable) contact); - } catch (final IOException ex) { - // Should not happen? - this.getLogger().catching(ex); - System.exit(1); - } - } - } - - /** - * Reads all contacts from database backend and handles them over to the - * contact manager - */ - @Override - public void readAllContacts () { - // Get iterator and case it - CsvBackend backend = (CsvBackend) this.getBackend(); - - // First rewind to beginning - this.getBackend().rewind(); - - // Get backend iterator - Iterator iterator = null; - try { - iterator = backend.contactIterator(); - } catch (final BadTokenException ex) { - this.getLogger().catching(ex); - System.exit(1); - } - - // Read all entries - while (iterator.hasNext()) { - // Get next entry - Contact contact = iterator.next(); - - // Add contact instance to manager - this.getContactManager().addContact(contact); - } - } -} diff --git a/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java b/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java deleted file mode 100644 index c14a3c3..0000000 --- a/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2015 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.database.frontend.contact; - -import org.mxchange.addressbook.database.frontend.DatabaseWrapper; - -/** - * - * @author Roland Häder - */ -public interface ContactWrapper extends DatabaseWrapper { - - /** - * Shuts down the database layer - */ - public void doShutdown (); - - /** - * Flushes all contact entries to database - */ - public void flushAllContacts (); - - /** - * Reads all contacts from database backend and handles them over to the - * contact manager - */ - public void readAllContacts (); -} diff --git a/src/org/mxchange/addressbook/database/storage/Storeable.java b/src/org/mxchange/addressbook/database/storage/Storeable.java deleted file mode 100644 index cd68048..0000000 --- a/src/org/mxchange/addressbook/database/storage/Storeable.java +++ /dev/null @@ -1,27 +0,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.database.storage; - -import org.mxchange.addressbook.FrameworkInterface; - -/** - *An interface for objects being stored in databases - * - * @author Roland Haeder - */ -public interface Storeable extends FrameworkInterface { -} diff --git a/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java b/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java deleted file mode 100644 index 6a5915e..0000000 --- a/src/org/mxchange/addressbook/database/storage/csv/StoreableCsv.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2015 KLC - * - * 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.database.storage.csv; - -import org.mxchange.addressbook.database.storage.Storeable; - -/** - * - * @author KLC - */ -public interface StoreableCsv extends Storeable { - /** - * Getter for a CSV-formated string from object - * @return - */ - public String getCsvStringFromStoreableObject (); -} diff --git a/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/src/org/mxchange/addressbook/localization/bundle_de_DE.properties deleted file mode 100644 index e4c5738..0000000 --- a/src/org/mxchange/addressbook/localization/bundle_de_DE.properties +++ /dev/null @@ -1,32 +0,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 . - -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. -AddressbookFrame.addOwnData.AccessibleContext.accessibleName_1=null -AddressbookFrame.addressbookMenu.text_1=null -AddressbookFrame.exitProgram.text_1=null -AddressbookFrame.statusLabel.text_1=null diff --git a/src/org/mxchange/addressbook/localization/bundle_en_US.properties b/src/org/mxchange/addressbook/localization/bundle_en_US.properties deleted file mode 100644 index 8d314b9..0000000 --- a/src/org/mxchange/addressbook/localization/bundle_en_US.properties +++ /dev/null @@ -1,28 +0,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 . - -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. diff --git a/src/org/mxchange/addressbook/manager/BaseManager.java b/src/org/mxchange/addressbook/manager/BaseManager.java deleted file mode 100644 index 2790075..0000000 --- a/src/org/mxchange/addressbook/manager/BaseManager.java +++ /dev/null @@ -1,36 +0,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.manager; - -import org.mxchange.addressbook.BaseFrameworkSystem; - -/** - * A general manager - * - * @author Roland Haeder - * @version 0.0 - * @since 0.0 - */ -public class BaseManager extends BaseFrameworkSystem { - /** - * No instances can be created of this class - */ - protected BaseManager () { - // Call any other super constructors - super(); - } -} diff --git a/src/org/mxchange/addressbook/manager/Manageable.java b/src/org/mxchange/addressbook/manager/Manageable.java deleted file mode 100644 index af3cc6c..0000000 --- a/src/org/mxchange/addressbook/manager/Manageable.java +++ /dev/null @@ -1,26 +0,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.manager; - -import org.mxchange.addressbook.FrameworkInterface; - -/** - * - * @author Roland Haeder - */ -public interface Manageable extends FrameworkInterface { -} diff --git a/src/org/mxchange/addressbook/manager/application/ApplicationManager.java b/src/org/mxchange/addressbook/manager/application/ApplicationManager.java deleted file mode 100644 index 9afad3a..0000000 --- a/src/org/mxchange/addressbook/manager/application/ApplicationManager.java +++ /dev/null @@ -1,60 +0,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.manager.application; - -import org.mxchange.addressbook.application.Application; -import org.mxchange.addressbook.manager.BaseManager; - -/** - * - * @author Roland Haeder - */ -public class ApplicationManager extends BaseManager implements ManageableApplication { - - /** - * Getter for application manager - * @param application An instance of a Application class - * @return - */ - public static final ManageableApplication getManager (final Application application) { - // Get manager - ManageableApplication manager = new ApplicationManager(application); - - // Return manager - return manager; - } - - /** - * Constructor for this manager - * @param application An instance of an Application class - */ - private ApplicationManager (final Application application) { - super(); - - // Set application instance - this.setApplication (application); - } - - @Override - public void start () { - // Bootstrap application - this.getApplication().doBootstrap(); - - // Run the main loop - this.getApplication().doMainLoop(); - } -} diff --git a/src/org/mxchange/addressbook/manager/application/ManageableApplication.java b/src/org/mxchange/addressbook/manager/application/ManageableApplication.java deleted file mode 100644 index 325f83c..0000000 --- a/src/org/mxchange/addressbook/manager/application/ManageableApplication.java +++ /dev/null @@ -1,30 +0,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.manager.application; - -import org.mxchange.addressbook.manager.Manageable; - -/** - * - * @author Roland Haeder - */ -public interface ManageableApplication extends Manageable { - /** - * Launches application - */ - public void start(); -} diff --git a/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/src/org/mxchange/addressbook/manager/contact/ContactManager.java deleted file mode 100644 index e89b708..0000000 --- a/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ /dev/null @@ -1,548 +0,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.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.BaseContact; -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 { - - /** - * 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(); - - // Init contacts - this.contacts = new ArrayList<>(maxContacts); - - // Init database connection - this.contactDatabase = new ContactDatabaseFrontend(this); - - // Read all entries - this.contactDatabase.readAllContacts(); - - // Debug message - //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client); - - // Init client - this.setClient(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.contactDatabase.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 int getColumnCount () { - /* - * Return constant, may look useful. But without this, e.g. the - * AddressTableModel have a hard-coded value. - */ - return BaseContact.COLUMN_COUNT; - } - - /** - * 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 int size () { - return this.contacts.size(); - } - - /** - * 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/src/org/mxchange/addressbook/manager/contact/ManageableContact.java b/src/org/mxchange/addressbook/manager/contact/ManageableContact.java deleted file mode 100644 index 736053d..0000000 --- a/src/org/mxchange/addressbook/manager/contact/ManageableContact.java +++ /dev/null @@ -1,229 +0,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.manager.contact; - -import java.util.List; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.contact.Contact; -import org.mxchange.addressbook.manager.Manageable; - -/** - * - * @author Roland Haeder - */ -public interface ManageableContact extends Manageable { - - /** - * Shuts down this contact manager - */ - public void doShutdown (); - - /** - * Allows the user to enter own cellphone number. - * - * @return Cellphone number - */ - public String enterOwnCellNumber (); - - /** - * Allows the user to enter own city name. - * - * @return City name - */ - public String enterOwnCity (); - - /** - * Allows the user to enter comment for own entry. - * - * @return Comment - */ - public String enterOwnComment (); - - /** - * Allows the user to enter own company name. - * - * @return Company name - */ - public String enterOwnCompanyName (); - - /** - * Allows the user to enter own country code. - * - * @return Country code - */ - public String enterOwnCountryCode (); - - /** - * Allows the user to enter own email address. - * - * @return Email address - */ - public String enterOwnEmailAddress (); - - /** - * Allows the user to enter own family name. - * - * @return Family name - */ - public String enterOwnFamilyName (); - - /** - * Allows the user to enter own fax number. - * - * @return Fax number - */ - public String enterOwnFaxNumber (); - - /** - * Allows the user to enter own gender. - * - * @return Gender - */ - public char enterOwnGender (); - - /** - * Allows the user to enter own phone number. - * - * @return Phone number - */ - public String enterOwnPhoneNumber (); - - /** - * Allows the user to enter own street and house number. - * - * @return Street and house number - */ - public String enterOwnStreet (); - - /** - * Allows the user to enter own surname. - * - * @return Surname - */ - public String enterOwnSurname (); - - /** - * Allows the user to enter own ZIP code. - * - * @return ZIP code - */ - public int enterOwnZipCode (); - - /** - * Getter for column count - * - * @return Column count - */ - public int getColumnCount (); - - /** - * List all contacts - */ - public void listContacts (); - - /** - * Adds given contact to address book - * - * @param contact Contact being added - * @todo Add check for book size - */ - public void registerContact (final Contact contact); - - /** - * Adds given Contact instance to list - * - * @param contact Contact instance to add - */ - public void addContact (final Contact contact); - - /** - * Let the user add a new other address - */ - public void addOtherAddress(); - - /** - * The user can change address data, like street, ZIP code, city and country - * of given Contact instance. - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeAddressData (final Contact contact, final Client client); - - /** - * The user can change name data, like gender, surname, family name and - * company name (if business contact). - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeNameData (final Contact contact, final Client client); - - /** - * Let the user change other address - */ - public void changeOtherAddress(); - - /** - * The user can change other data, like phone numbers or comments. - * - * @param contact Instance to change data - * @param client Client instance to call back - */ - public void doChangeOtherData (final Contact contact, final Client client); - - /** - * Let the user change own data - */ - public void changeOwnData(); - - /** - * Let the user delete other address - */ - public void deleteOtherAddress(); - - /** - * Asks user for own data - */ - public void doEnterOwnData(); - - /** - * Getter for whole list - * @return List of all contacts - */ - public List getList (); - - /** - * Searches address book for a contact - */ - public void searchContacts (); - - /** - * Checks whether own contact is already added by checking all entries for - * isOwnContact flag - * - * @return Whether own contact is already added - */ - public boolean isOwnContactAdded (); - - /** - * Getter for size - * - * @return size of contact "book" - */ - public int size(); -} diff --git a/src/org/mxchange/addressbook/menu/AddressbookMenu.java b/src/org/mxchange/addressbook/menu/AddressbookMenu.java deleted file mode 100644 index 02d00b6..0000000 --- a/src/org/mxchange/addressbook/menu/AddressbookMenu.java +++ /dev/null @@ -1,85 +0,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.menu; - -import java.util.List; -import org.apache.logging.log4j.Logger; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * Utility class for menu structure - * - * @author Roland Haeder - */ -public class AddressbookMenu extends BaseFrameworkSystem { - /** - * Copies entries for given type into the menu list - * - * @param menuList Menu list for later showing - * @param menuType Type of menu - * @param client Client instance to call back - */ - public static void addItemsToList (final List menuList, final String menuType, final Client client) { - // Get logger - Logger log = new AddressbookMenu().getLogger(); - - // Get list size - int size = menuList.size(); - - // Debug message - log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ..."); - - // Depends on type - switch (menuType) { - case "main": // Main menu - // Enter own data - menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen")); - - // Change own data - menuList.add(client.getMenuItem('2', "Eigene Adresse ändern")); - - // Add new addess - menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen")); - - // List entries - menuList.add(client.getMenuItem('4', "Adressbuch anzeigen")); - - // Address search - menuList.add(client.getMenuItem('5', "Adresse suchen")); - - // Change other address - menuList.add(client.getMenuItem('6', "Adresse ändern")); - - // Delete other address - menuList.add(client.getMenuItem('7', "Adresse löschen")); - - // Always last line: Exit program - menuList.add(client.getMenuItem('0', "Programm verlassen")); - break; - - default: // Not supported - log.error("Menu type '" + menuType + "' ont supported"); - System.exit(1); - } - - // Size must have changed to more entries than before - assert(menuList.size() > size); - } - -} diff --git a/src/org/mxchange/addressbook/menu/BaseMenu.java b/src/org/mxchange/addressbook/menu/BaseMenu.java deleted file mode 100644 index d81c071..0000000 --- a/src/org/mxchange/addressbook/menu/BaseMenu.java +++ /dev/null @@ -1,100 +0,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.menu; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - */ -public class BaseMenu extends BaseFrameworkSystem { - /** - * Menu list - */ - private List menuList; - - /** - * No instance from this object - */ - protected BaseMenu () { - super(); - } - - /** - * Size of menu items - * @return Count of menu items - */ - public int getMenuItemsCount () { - return this.menuList.size(); - } - - /** - * "Getter" for an iterator of this menu's items - * - * @return An iterator of all menu items - */ - public Iterator getMenuItemsIterator () { - return this.menuList.iterator(); - } - - /** - * Shows this menu - * - * @param client Client instance to call back - */ - public void show (final Client client) { - // Get values - Iterator iterator = this.menuList.iterator(); - - // Debug message - this.getLogger().debug("Showing menu with '" + this.menuList.size() + "' entries."); - - // Output all menus - while (iterator.hasNext()) { - // Get item - SelectableMenuItem item = iterator.next(); - - // Show this item - item.show(client); - } - } - - /** - * Getter for menu list - * - * @return menuList List of menu entries - */ - protected final List getMenuList () { - return this.menuList; - } - - /** - * Initializes menu - * @param menuType Menu type to initialize - * @param client CLient to call back - */ - protected void initMenu (final String menuType, final Client client) { - // Init menu list - this.menuList = new ArrayList<>(5); - } -} diff --git a/src/org/mxchange/addressbook/menu/Menu.java b/src/org/mxchange/addressbook/menu/Menu.java deleted file mode 100644 index 4a13bdb..0000000 --- a/src/org/mxchange/addressbook/menu/Menu.java +++ /dev/null @@ -1,47 +0,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.menu; - -import java.util.Iterator; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - * @todo find better name - */ -public interface Menu { - - /** - * "Getter" for an iterator on all menu items of the current menu - * @return Iterator on all menu items - */ - public Iterator getMenuItemsIterator(); - - /** - * Shows this menu - * @param client Client instance - */ - public void show (final Client client); - - /** - * Size of all menu items - * @return - */ - public int getMenuItemsCount(); -} diff --git a/src/org/mxchange/addressbook/menu/MenuTools.java b/src/org/mxchange/addressbook/menu/MenuTools.java deleted file mode 100644 index 75bfb7e..0000000 --- a/src/org/mxchange/addressbook/menu/MenuTools.java +++ /dev/null @@ -1,78 +0,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.menu; - -import java.util.Iterator; -import java.util.Map; -import org.apache.logging.log4j.Logger; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.menu.item.SelectableMenuItem; - -/** - * - * @author Roland Haeder - */ -public class MenuTools extends BaseFrameworkSystem { - - /** - * Gets an array with all available access keys back from given menu map. - * This can later be handle to the client's enterChar() method. - * - * @param menus A Map with all menus and their entries - * @param menuType Menu type - * @return An array with available access chars - */ - public static char[] getAccessKeysFromMenuMap (final Map menus, final String menuType) { - // Get logger - Logger logger = new MenuTools().getLogger(); - - // First search for the proper menu class - Menu menu = menus.get(menuType); - - // Is it there? - if (!(menu instanceof Menu)) { - // Not found - // @todo Rewrite to exception - logger.error("Menu '" + menuType + "' not found."); - System.exit(1); - } - - // Get iterator - Iterator iterator = menu.getMenuItemsIterator(); - - // Init return array and counter 'i' - char[] accessKeys = new char[menu.getMenuItemsCount()]; - int i = 0; - - // Now "walk" through all menu entries - while (iterator.hasNext()) { - // Get item - SelectableMenuItem item = iterator.next(); - //* NOISY-DEBUG: */ logger.debug("item=" + item); - - // Get access key from item and add it to the array - accessKeys[i] = item.getAccessKey(); - //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]); - - // Increment counter - i++; - } - - // Return finished array - return accessKeys; - } -} diff --git a/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java b/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java deleted file mode 100644 index cefa2c5..0000000 --- a/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java +++ /dev/null @@ -1,40 +0,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.menu.console; - -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.menu.AddressbookMenu; -import org.mxchange.addressbook.menu.BaseMenu; -import org.mxchange.addressbook.menu.Menu; - -/** - * - * @author Roland Haeder - */ -public class ConsoleMenu extends BaseMenu implements Menu { - /** - * Constructor for this menu - * @param menuType Menu type to initialize - * @param client CLient to call back - */ - public ConsoleMenu (final String menuType, final Client client) { - this.initMenu(menuType, client); - - // Add all items - AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client); - } -} diff --git a/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java b/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java deleted file mode 100644 index bc1bba7..0000000 --- a/src/org/mxchange/addressbook/menu/item/BaseMenuItem.java +++ /dev/null @@ -1,27 +0,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.menu.item; - -import org.mxchange.addressbook.BaseFrameworkSystem; - -/** - * - * @author Roland Haeder - */ -public class BaseMenuItem extends BaseFrameworkSystem { - -} diff --git a/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java b/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java deleted file mode 100644 index efbce50..0000000 --- a/src/org/mxchange/addressbook/menu/item/SelectableMenuItem.java +++ /dev/null @@ -1,44 +0,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.menu.item; - -import org.mxchange.addressbook.client.Client; - -/** - * - * @author Roland Haeder - */ -public interface SelectableMenuItem { - - /** - * Shows this menu item - * @param client Client instance - */ - public void show (final Client client); - - /** - * Access key - * @return the accessKey - */ - public char getAccessKey(); - - /** - * Text to user - * @return the text - */ - public String getText(); -} diff --git a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java deleted file mode 100644 index 37f9c7c..0000000 --- a/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java +++ /dev/null @@ -1,89 +0,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.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); - } - -} diff --git a/src/org/mxchange/addressbook/model/BaseModel.java b/src/org/mxchange/addressbook/model/BaseModel.java deleted file mode 100644 index 54aa507..0000000 --- a/src/org/mxchange/addressbook/model/BaseModel.java +++ /dev/null @@ -1,65 +0,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.model; - -import java.text.MessageFormat; -import javax.swing.event.EventListenerList; -import javax.swing.event.TableModelListener; -import org.mxchange.addressbook.BaseFrameworkSystem; - -/** - * - * @author Roland Haeder - */ -public class BaseModel extends BaseFrameworkSystem { - /** List of listeners */ - private final EventListenerList listenerList; - - /** - * Protected constructor - */ - protected BaseModel () { - // Init listener list - this.listenerList = new EventListenerList(); - } - - /** - * Adds a TableModel listener instance to the event list. - * - * @param listener Lister instance - */ - public void addTableModelListener (final TableModelListener listener) { - // Debug message - this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass())); - - // Add listener - this.listenerList.add(TableModelListener.class, listener); - } - - /** - * Removes a TableModel listener instance from the event list. - * - * @param listener Listener instance - */ - public void removeTableModelListener (final TableModelListener listener) { - // Debug message - this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass())); - - // Remove listener - this.listenerList.remove(TableModelListener.class, listener); - } -} diff --git a/src/org/mxchange/addressbook/model/address/AddressTableModel.java b/src/org/mxchange/addressbook/model/address/AddressTableModel.java deleted file mode 100644 index d386b95..0000000 --- a/src/org/mxchange/addressbook/model/address/AddressTableModel.java +++ /dev/null @@ -1,77 +0,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.model.address; - -import javax.swing.table.TableModel; -import org.mxchange.addressbook.client.Client; -import org.mxchange.addressbook.model.BaseModel; - -/** - * - * @author Roland Haeder - */ -public class AddressTableModel extends BaseModel implements TableModel { - - /** - * Constructor with Client instance which holds the contact manager - * - * @param client Client instance - */ - public AddressTableModel (final Client client) { - // Parent super constructor - super(); - - // Set client - this.setClient(client); - } - - @Override - public Class getColumnClass (final int columnIndex) { - throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public int getColumnCount () { - // Deligate this call to the contact manager - return this.getClient().getContactManager().getColumnCount(); - } - - @Override - public String getColumnName (final int columnIndex) { - throw new UnsupportedOperationException("Not supported yet. columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public int getRowCount () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public Object getValueAt (final int rowIndex, final int columnIndex) { - throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public boolean isCellEditable (final int rowIndex, final int columnIndex) { - throw new UnsupportedOperationException("Not supported yet. rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void setValueAt (final Object value, final int rowIndex, final int columnIndex) { - throw new UnsupportedOperationException("Not supported yet. value=" + value + ",rowIndex=" + rowIndex + ",columnIndex=" + columnIndex); //To change body of generated methods, choose Tools | Templates. - } -}