From: Roland Haeder Date: Mon, 27 Jul 2015 10:55:18 +0000 (+0200) Subject: Introduced Gender enum which replaces the old char X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a605f8ef9955c6acc7d9dc8de26d6a362573c58;p=jfinancials-lib.git Introduced Gender enum which replaces the old char 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 7dcbdfe..9ebbc14 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/Client.java +++ b/Addressbook/src/org/mxchange/addressbook/client/Client.java @@ -19,6 +19,7 @@ package org.mxchange.addressbook.client; 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; /** @@ -68,6 +69,14 @@ public interface Client extends FrameworkInterface { */ 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 * diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 94818f1..b018096 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.Application; 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; @@ -138,7 +139,7 @@ public class ConsoleClient extends BaseClient implements Client { } // Gender: - char gender = this.getContactManager().enterOwnGender(); + Gender gender = this.getContactManager().enterOwnGender(); // Surname String surname = this.getContactManager().enterOwnSurname(); @@ -183,7 +184,7 @@ public class ConsoleClient extends BaseClient implements Client { @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(); @@ -287,6 +288,30 @@ public class ConsoleClient extends BaseClient implements Client { 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 * diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index 2c9494b..b3bcab4 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -16,7 +16,6 @@ */ 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; @@ -28,6 +27,7 @@ import java.awt.event.WindowEvent; 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; @@ -38,11 +38,13 @@ import javax.swing.JMenuItem; 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; @@ -281,17 +283,54 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // 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 gender = new JComboBox<>(new GenderComboBoxModel(this.getClient())); + JComboBox gender = new JComboBox<>(new DefaultComboBoxModel()); + + // 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); diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index a9ba1c1..634b0cf 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -20,6 +20,7 @@ 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.Gender; import org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException; import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException; import org.mxchange.addressbook.menu.Menu; @@ -126,6 +127,11 @@ public class SwingClient extends BaseClient implements Client { 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. diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index f03a3c1..aa82551 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -75,10 +75,9 @@ public class BaseContact extends BaseFrameworkSystem { 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 @@ -139,7 +138,7 @@ public class BaseContact extends BaseFrameworkSystem { 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()))); } @@ -244,7 +243,7 @@ public class BaseContact extends BaseFrameworkSystem { 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(), @@ -323,7 +322,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @return the gender */ - public char getGender () { + public Gender getGender () { return this.gender; } @@ -332,7 +331,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param gender the gender to set */ - private void setGender (final char gender) { + private void setGender (final Gender gender) { this.gender = gender; } @@ -392,15 +391,15 @@ public class BaseContact extends BaseFrameworkSystem { // "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; @@ -435,7 +434,7 @@ public class BaseContact extends BaseFrameworkSystem { 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; } @@ -497,9 +496,10 @@ public class BaseContact extends BaseFrameworkSystem { * @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); } diff --git a/Addressbook/src/org/mxchange/addressbook/contact/Contact.java b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java index 76230fb..57bca67 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/Contact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/Contact.java @@ -44,7 +44,7 @@ public interface Contact extends FrameworkInterface { * * @return the gender */ - public char getGender (); + public Gender getGender (); /** * Surname @@ -169,7 +169,7 @@ public interface Contact extends FrameworkInterface { * @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 diff --git a/Addressbook/src/org/mxchange/addressbook/contact/Gender.java b/Addressbook/src/org/mxchange/addressbook/contact/Gender.java new file mode 100644 index 0000000..96bce2c --- /dev/null +++ b/Addressbook/src/org/mxchange/addressbook/contact/Gender.java @@ -0,0 +1,168 @@ +/* + * 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; + +/** + * 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; + } +} diff --git a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java index 5a530b0..fd6637e 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java @@ -17,6 +17,7 @@ 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; @@ -37,7 +38,7 @@ public class UserContact extends BookContact implements Contact, 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(); diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java index bc7e001..3abb9da 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java @@ -26,6 +26,7 @@ import java.util.Iterator; 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; @@ -307,7 +308,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken 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) { @@ -335,7 +336,8 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken // 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 @@ -364,7 +366,6 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken 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); @@ -372,7 +373,6 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken 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); @@ -380,7 +380,6 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken 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); @@ -388,7 +387,6 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken 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); diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties index f873060..7cc24c1 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_de_DE.properties @@ -27,6 +27,14 @@ AddressbookFrame.menuItem.editOwnData.toolTipText=Erlaubt das \u00c4ndern eigene 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 diff --git a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties index 46addd1..8fce7b5 100644 --- a/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties +++ b/Addressbook/src/org/mxchange/addressbook/localization/bundle_en_US.properties @@ -26,6 +26,14 @@ AddressbookFrame.menuItem.editOwnData.text=Edit own data 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 diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index f14525f..107bf3f 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -23,6 +23,7 @@ import java.util.Iterator; 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; @@ -345,8 +346,8 @@ public class ContactManager extends BaseManager implements ManageableContact { * @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): "); } /** diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java index 869f3e2..2ed123c 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java @@ -19,6 +19,7 @@ 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.contact.Gender; import org.mxchange.addressbook.manager.Manageable; /** @@ -93,7 +94,7 @@ public interface ManageableContact extends Manageable { * * @return Gender */ - public char enterOwnGender (); + public Gender enterOwnGender (); /** * Allows the user to enter own phone number. diff --git a/Addressbook/src/org/mxchange/addressbook/model/gender/GenderComboBoxModel.java b/Addressbook/src/org/mxchange/addressbook/model/gender/GenderComboBoxModel.java deleted file mode 100644 index 0b0a46d..0000000 --- a/Addressbook/src/org/mxchange/addressbook/model/gender/GenderComboBoxModel.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.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 { - - /** - * 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; - } -}