From: Roland Haeder Date: Wed, 15 Jul 2015 10:45:12 +0000 (+0200) Subject: Added show() method and in client a simple, textural display X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0490615f8cc85a9462dcd1514dfe58c637edea5b;p=jaddressbook-lib.git Added show() method and in client a simple, textural display Signed-off-by:Roland Häder --- diff --git a/Addressbook/src/org/mxchange/addressbook/client/Client.java b/Addressbook/src/org/mxchange/addressbook/client/Client.java index 740a366d..54538944 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/Client.java +++ b/Addressbook/src/org/mxchange/addressbook/client/Client.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.client; import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.contact.Contact; import org.mxchange.addressbook.menu.item.SelectableMenuItem; /** @@ -25,12 +26,34 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem; */ public interface Client extends FrameworkInterface { + /** + * Displays a "box" for the address + * + * @param contact Contact to show address from + */ + public void displayAddressBox (final Contact contact); + /** * Displays a message to the user + * * @param message Message to show to the user */ public void displayMessage (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); + /** * Asks the user for a choice and proceeds accordingly * @throws java.lang.Exception diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 364c8db5..66ace076 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -24,6 +24,7 @@ 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.menu.Menu; import org.mxchange.addressbook.menu.MenuTools; import org.mxchange.addressbook.menu.console.ConsoleMenu; @@ -69,6 +70,19 @@ public class ConsoleClient extends BaseClient implements Client { this.fillConsoleMenuMap(); } + /** + * Displays a textual address "box" of given contact + * + * @param contact Contact to show address for + * @todo Use mask + */ + @Override + public void displayAddressBox (final Contact contact) { + // Simple display ... + // @todo Use mask + this.displayMessage("Strasse, PLZ Ort, Land: " + contact.getStreet() + "\n" + contact.getZipCode() + " " + contact.getCity() + "\n" + contact.getCountryCode()); + } + /** * Displays textural message to the user * @param message @@ -78,6 +92,41 @@ public class ConsoleClient extends BaseClient implements Client { System.out.println(message); } + /** + * 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.displayMessage("Anrede, Vorname, Name: " + gender + " " + contact.getSurname() + " " + contact.getFamilyName()); + } else { + // Company contact + this.displayMessage("Firma: " + companyName + "\nAnsprechpartner: " + 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.displayMessage("Telefonnumer: " + contact.getPhoneNumber() + "\nFaxnummer: " + contact.getFaxNumber() + "\nHandy: " + contact.getCellphoneNumber() + "\nKommentar:\n" + contact.getComment()); + } + @Override public void doUserChoice () throws Exception { // Get all access keys from menu diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index 44cfccef..95335ff7 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.contact; import org.mxchange.addressbook.BaseFrameworkSystem; +import org.mxchange.addressbook.client.Client; /** * A general contact @@ -393,6 +394,37 @@ public class BaseContact extends BaseFrameworkSystem { 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 * @@ -419,4 +451,20 @@ public class BaseContact extends BaseFrameworkSystem { 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); + } } diff --git a/Addressbook/src/org/mxchange/addressbook/contact/Contact.java b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java index db905063..1ea7d578 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/Contact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.contact; import org.mxchange.addressbook.FrameworkInterface; +import org.mxchange.addressbook.client.Client; /** * @@ -30,6 +31,12 @@ public interface Contact extends FrameworkInterface { */ public void enableFlagOwnContact (); + /** + * 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 * @@ -141,4 +148,11 @@ public interface Contact extends FrameworkInterface { * @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); } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index 096197be..80cffd3c 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -119,6 +119,9 @@ public class ContactManager extends BaseManager implements ManageableContact { // It must be found assert(contact instanceof Contact); + // Display contact + contact.show(this.getClient()); + // @TODO Unfinished throw new UnsupportedOperationException("Method is not finished."); }