]> git.mxchange.org Git - addressbook-swing.git/blob - Addressbook/src/org/mxchange/addressbook/model/gender/GenderComboBoxModel.java
Introduced new model as we need gender value verfication, maybe this works?
[addressbook-swing.git] / Addressbook / src / org / mxchange / addressbook / model / gender / GenderComboBoxModel.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.model.gender;
18
19 import javax.swing.ComboBoxModel;
20 import org.mxchange.addressbook.client.Client;
21 import org.mxchange.addressbook.model.BaseModel;
22
23 /**
24  *
25  * @author Roland Haeder
26  */
27 public class GenderComboBoxModel extends BaseModel implements ComboBoxModel<String> {
28
29         /**
30          * Selected item instance, the value can only be 'M', 'F' or 'C'
31          */
32         private char selectedItem = 0;
33
34         /**
35          * Selectable items
36          */
37         private final char[] validItems = new char[] {'M', 'F', 'C'};
38
39         /**
40          * Creates an instance of this model with a Client instance
41          * @param client Client instance
42          */
43         public GenderComboBoxModel (final Client client) {
44                 // Call super constructor
45                 super();
46
47                 // Set client
48                 this.setClient(client);
49         }
50
51         @Override
52         public String getElementAt (final int index) {
53                 // Return it
54                 return String.valueOf(this.validItems[index]);
55         }
56
57         /**
58          * Gets the currently selected item or null if nothing is selected.
59          * 
60          * @return Selected item or null
61          */
62         @Override
63         public Object getSelectedItem () {
64                 // Is the char set other than 0?
65                 if (this.selectedItem == 0) {
66                         // Nothing selected
67                         return null;
68                 }
69
70                 // Return string representing the selected item
71                 return this.selectedItem;
72         }
73
74         @Override
75         public void setSelectedItem (final Object anItem) {
76                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
77         }
78
79         /**
80          * Getter for size. Here only 3 values are valid: M, F and C
81          *
82          * @return Maximum size
83          */
84         @Override
85         public int getSize () {
86                 // Get size of array
87                 return this.validItems.length;
88         }
89 }