import org.mxchange.addressbook.FrameworkInterface;
import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.menu.item.SelectableMenuItem;
/**
*/
public void doShutdown ();
+ /**
+ * Asks the user to enter his/her gender (M=Male, F=Female, C=Company)
+ *
+ * @param message Message to output
+ * @return Gender enum
+ */
+ public Gender enterGender (final String message);
+
/**
* Displays a message to the user
*
import org.mxchange.addressbook.client.BaseClient;
import org.mxchange.addressbook.client.Client;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.contact.user.UserContact;
import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
import org.mxchange.addressbook.menu.Menu;
}
// Gender:
- char gender = this.getContactManager().enterOwnGender();
+ Gender gender = this.getContactManager().enterOwnGender();
// Surname
String surname = this.getContactManager().enterOwnSurname();
@Override
public Contact doEnterOwnData () {
// First ask for gender
- char gender = this.getContactManager().enterOwnGender();
+ Gender gender = this.getContactManager().enterOwnGender();
// 2nd for surname
String surname = this.getContactManager().enterOwnSurname();
return input;
}
+ /**
+ * Asks the user to enter his/her gender
+ *
+ * @param message Message to the user
+ * @return Gender enum
+ */
+ @Override
+ public Gender enterGender (final String message) {
+ // Get valid chars
+ char[] validChars = Gender.validChars();
+
+ // Debug message
+ //* NOISY-DEBUG: */ System.out.println(validChars);
+
+ // Call inner method
+ char gender = this.enterChar(validChars, message);
+
+ // Now get a Gender instance back
+ Gender g = Gender.fromChar(gender);
+
+ // Return it
+ return g;
+ }
+
/**
* Reads an integer (int) with a textural message from the user
*
*/
package org.mxchange.addressbook.client.gui;
-import org.mxchange.addressbook.model.gender.GenderComboBoxModel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.text.MessageFormat;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
+import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableModel;
import org.mxchange.addressbook.BaseFrameworkSystem;
import org.mxchange.addressbook.application.AddressbookApplication;
import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException;
import org.mxchange.addressbook.model.contact.ContactTableModel;
// Init 3 panels:
// 1) Panel "name" input boxes
- JPanel panel = new JPanel();
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+ JPanel namePanel = new JPanel();
+ namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.Y_AXIS));
// Set border to titled version
- panel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
+ namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name")));
// Add some input boxes for "name" panel
- JComboBox<String> gender = new JComboBox<>(new GenderComboBoxModel(this.getClient()));
+ JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<Gender>());
+
+ // Panel for gender
+ JPanel gPanel = new JPanel();
+ gPanel.setLayout(new GridLayout(1, 2));
+
+ // Set tooltip text
+ gPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.tooltipText"));
+
+ // Gender text field
+ JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
+
+ // Add both to gender panel
+ gPanel.add(gLabel);
+ gPanel.add(gender);
+
+ // Add panel to north of "name" panel
+ namePanel.add(gPanel, BorderLayout.NORTH);
+
+ // Panel for surname
+ JPanel sPanel = new JPanel();
+ sPanel.setLayout(new GridLayout(1, 2));
+
+ // Set too tip text
+ sPanel.setToolTipText(this.getBundle().getString("AddressbookFrame.surname.tooltipText"));
+
+ // New label for surname is not needed
+ JLabel sLabel = new JLabel(this.getBundle().getString("AddressbookFrame.surname.text"));
+
+ // And input box
+ JTextField surname = new JTextField(20);
+
+ // Add both to surname panel
+ sPanel.add(sLabel);
+ sPanel.add(surname);
+
+ // Add surname panel to "name" panel
+ namePanel.add(sPanel, BorderLayout.CENTER);
// Finally add panel to dialog
- this.addContact.add(panel);
+ this.addContact.add(namePanel);
// Only for developing:
/* DEBUG: */ this.addContact.setVisible(true);
import org.mxchange.addressbook.client.BaseClient;
import org.mxchange.addressbook.client.Client;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException;
import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
import org.mxchange.addressbook.menu.Menu;
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
+ @Override
+ public Gender enterGender (final 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.
private String faxNumber;
/**
- * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
- * Company
+ * Gender instance
*/
- private char gender;
+ private Gender gender;
/**
* House number
Contact contact = (Contact) object;
// Now test some data @todo Definedly needs improvement
- return ((this.getGender() == contact.getGender())
+ return ((this.getGender().equals(contact.getGender()))
&& (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
&& (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
}
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.getGender().getDatabaseValue(),
this.getSurname(),
this.getFamilyName(),
this.getCompanyName(),
*
* @return the gender
*/
- public char getGender () {
+ public Gender getGender () {
return this.gender;
}
*
* @param gender the gender to set
*/
- private void setGender (final char gender) {
+ private void setGender (final Gender gender) {
this.gender = gender;
}
// "Translate" it
switch (this.getGender()) {
- case 'M': // Mr.
+ case MALE: // Mr.
translated = "Herr";
break;
- case 'F': // Mrs.
+ case FEMALE: // Mrs.
translated = "Frau";
break;
- case 'C': // "Company"
+ case COMPANY: // "Company"
translated = "Firma";
break;
public int hashCode () {
int hash = 7;
hash = 79 * hash + Objects.hashCode(this.getFamilyName());
- hash = 79 * hash + this.getGender();
+ hash = 79 * hash + this.getGender().hashCode();
hash = 79 * hash + Objects.hashCode(this.getSurname());
return hash;
}
* @param familyName Family name
* @param companyName Company name
*/
- public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
+ public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
// Set all
this.setGender(gender);
+
if (surname != null) {
this.setSurname(surname);
}
*
* @return the gender
*/
- public char getGender ();
+ public Gender getGender ();
/**
* Surname
* @param familyName Family name
* @param companyName Company name
*/
- public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);
+ public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName);
/**
* Updates other data in this Contact instance
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.contact;
+
+/**
+ * Gender enum
+ * @author Roland Haeder
+ */
+public enum Gender {
+ /**
+ * Unknown enum
+ */
+ UNKNOWN("U", "BaseContact.gender.unknown.text"),
+
+ /**
+ * Male enum
+ */
+ MALE("M", "BaseContact.gender.male.text"),
+
+ /**
+ * Female enum
+ */
+ FEMALE("F", "BaseContact.gender.female.text"),
+
+ /**
+ * Company enum
+ */
+ COMPANY("C", "BaseContact.gender.company.text");
+
+ /**
+ * Cache for valid chars
+ */
+ private static char[] validChars;
+
+ /**
+ * Getter for Gender enum from given character
+ *
+ * @param gender Gender character
+ * @return Gender enum
+ */
+ public static Gender fromChar (final char gender) {
+ Gender g = null;
+ switch (gender) {
+ case 'U': // Unknown
+ g = UNKNOWN;
+ break;
+
+ case 'M': // Male
+ g = MALE;
+ break;
+
+ case 'F': // Female
+ g = FEMALE;
+ break;
+
+ case 'C': // Company
+ g = COMPANY;
+ break;
+
+ default: // Unsupported
+ throw new IllegalArgumentException("gender " + gender + " is invalid.");
+ }
+
+ // Return it
+ return g;
+ }
+
+ /**
+ * Valid chars
+ *
+ * @return Valid chars
+ */
+ public static char[] validChars () {
+ // Is cache set?
+ if (validChars != null) {
+ // Return it
+ return validChars;
+ }
+
+ // Init array
+ char[] valid = new char[3];
+
+ // Get values
+ int i = 0;
+ for (Object value : values()) {
+ // First cast
+ Gender gender = (Gender) value;
+
+ // Debug message
+ //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
+
+ // Is it "U"?
+ if (gender.getDatabaseValue().equals("U")) {
+ // Skip this
+ continue;
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
+
+ // Get database value as this is also the access
+ valid[i] = gender.getDatabaseValue().charAt(0);
+
+ // Increment index
+ i++;
+ }
+
+ // Set it here
+ validChars = valid;
+
+ // Return finialized array
+ return valid;
+ }
+
+ /**
+ * Database value
+ */
+ private final String databaseValue;
+
+ /**
+ * Output value (for messages)
+ */
+ private final String messageKey;
+
+ /**
+ * Constructor
+ *
+ * @param databaseValue Value being stored in database
+ * @param messageKey Message key for resource file
+ */
+ private Gender (final String databaseValue, final String messageKey) {
+ // Set both
+ this.databaseValue = databaseValue;
+ this.messageKey = messageKey;
+ }
+
+ /**
+ * Database value
+ *
+ * @return the databaseValue
+ */
+ protected String getDatabaseValue () {
+ return this.databaseValue;
+ }
+
+ /**
+ * Output value (for messages)
+ *
+ * @return the messageKey
+ */
+ protected String getMessageKey () {
+ return this.messageKey;
+ }
+}
package org.mxchange.addressbook.contact.user;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.contact.book.BookContact;
import org.mxchange.addressbook.database.storage.csv.StoreableCsv;
* @param companyName Company name
* @todo Add validation of data
*/
- public UserContact (final char gender, final String surname, final String familyName, final String companyName) {
+ public UserContact (final Gender gender, final String surname, final String familyName, final String companyName) {
// Make sure all constructors are called
this();
import java.util.List;
import java.util.StringTokenizer;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.contact.book.BookContact;
import org.mxchange.addressbook.contact.user.UserContact;
import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
String strData = strippedToken;
Long num = null;
Boolean bool = null;
- char gender = '?';
+ Gender gender = null;
// Now, let's try a number check, if no null
if (strippedToken != null) {
// 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);
+ //gender = strippedToken.charAt(0);
+ throw new UnsupportedOperationException("Gender dection is unifnished!");
}
// Now it depends on the counter which position we need to check
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);
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);
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);
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);
AddressbookFrame.dialog.addContact.title.text=Neue Adresse hinzuf\u00fcgen
AddressbookFrame.main.title.text=Adressen auflisten
AddressbookFrame.border.name.title.text=Anrede, Vorname, Nachname
+AddressbookFrame.gender.text=Anrede:
+AddressbookFrame.gender.tooltipText=W\u00e4hlen Sie die Anrede aus.
+AddressbookFrame.surname.text=Vorname:
+AddressbookFrame.surname.tooltipText=Geben Sie den Vornamen ein.
+BaseContact.gender.unknown.text=Unbekannt
+BaseContact.gender.male.text=Herr
+BaseContact.gender.female.text=Frau
+BaseContact.gender.company.text=Firma
ContactManager.columnName.gender.text=Anrede
ContactManager.columnName.surname.text=Vorname
ContactManager.columnName.familyName.text=Nachname
AddressbookFrame.menuItem.editOwnData.toolTipText=Allows the user to edit own address data
AddressbookFrame.dialog.addContact.title.text=Add new address
AddressbookFrame.main.title.text=List addresses
+AddressbookFrame.gender.text=Gender:
+AddressbookFrame.gender.tooltipText=Choose gender.
+AddressbookFrame.surname.text=Surname:
+AddressbookFrame.surname.tooltipText=Enter surname.
+BaseContact.gender.unknown.text=Unknown
+BaseContact.gender.male.text=Mr.
+BaseContact.gender.female.text=Mrs.
+BaseContact.gender.company.text=Company
ContactManager.columnName.gender.text=Gender
ContactManager.columnName.surname.text=Surname
ContactManager.columnName.familyName.text=Family name
import java.util.List;
import org.mxchange.addressbook.client.Client;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend;
import org.mxchange.addressbook.database.frontend.contact.ContactWrapper;
import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
* @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): ");
+ public Gender enterOwnGender () {
+ return this.getClient().enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
}
/**
import java.util.List;
import org.mxchange.addressbook.client.Client;
import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.contact.Gender;
import org.mxchange.addressbook.manager.Manageable;
/**
*
* @return Gender
*/
- public char enterOwnGender ();
+ public Gender enterOwnGender ();
/**
* Allows the user to enter own phone number.
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.model.gender;
-
-import javax.swing.ComboBoxModel;
-import org.mxchange.addressbook.client.Client;
-import org.mxchange.addressbook.model.BaseModel;
-
-/**
- *
- * @author Roland Haeder
- */
-public class GenderComboBoxModel extends BaseModel implements ComboBoxModel<String> {
-
- /**
- * Selected item instance, the value can only be 'M', 'F' or 'C'
- */
- private char selectedItem = 0;
-
- /**
- * Selectable items
- */
- private final char[] validItems = new char[] {'M', 'F', 'C'};
-
- /**
- * Creates an instance of this model with a Client instance
- * @param client Client instance
- */
- public GenderComboBoxModel (final Client client) {
- // Call super constructor
- super();
-
- // Set client
- this.setClient(client);
- }
-
- @Override
- public String getElementAt (final int index) {
- // Return it
- return String.valueOf(this.validItems[index]);
- }
-
- /**
- * Gets the currently selected item or null if nothing is selected.
- *
- * @return Selected item or null
- */
- @Override
- public Object getSelectedItem () {
- // Is the char set other than 0?
- if (this.selectedItem == 0) {
- // Nothing selected
- return null;
- }
-
- // Return string representing the selected item
- return this.selectedItem;
- }
-
- @Override
- public void setSelectedItem (final Object anItem) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- /**
- * Getter for size. Here only 3 values are valid: M, F and C
- *
- * @return Maximum size
- */
- @Override
- public int getSize () {
- // Get size of array
- return this.validItems.length;
- }
-}