01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.util.list;
19:
20: import javax.swing.JComboBox;
21:
22: public class NameValueComboBox extends JComboBox {
23:
24: public NameValueComboBox() {
25: this (new NameValueListModel());
26: }
27:
28: public NameValueComboBox(NameValueListModel model) {
29: super (model);
30: setRenderer(new NameValueRenderer());
31: }
32:
33: public NameValueListModel getNameValueListModel() {
34: return (NameValueListModel) getModel();
35: }
36:
37: public void addElement(Object nameValuePair) {
38: getNameValueListModel().addElement(nameValuePair);
39: }
40:
41: public void insertElementAt(Object nameValuePair, int index) {
42: getNameValueListModel().insertElementAt(nameValuePair, index);
43: }
44:
45: public void removeElement(Object nameValuePair) {
46: getNameValueListModel().removeElement(nameValuePair);
47: }
48:
49: public void removeElementAt(int index) {
50: getNameValueListModel().removeElementAt(index);
51: }
52:
53: public Object getSelectedItemValue() {
54: NameValueListModel.NameValuePair nameValuePair = (NameValueListModel.NameValuePair) getSelectedItem();
55: return (nameValuePair != null ? nameValuePair.value : null);
56: }
57:
58: public Object getSelectedItemName() {
59: NameValueListModel.NameValuePair nameValuePair = (NameValueListModel.NameValuePair) getSelectedItem();
60: return (nameValuePair != null ? nameValuePair.name : null);
61: }
62:
63: public boolean setSelectedItemByValue(Object value) {
64: NameValueListModel.NameValuePair nameValuePair = getNameValueListModel()
65: .getEntryByValue(value);
66: if (nameValuePair != null) {
67: setSelectedItem(nameValuePair);
68: return true;
69: } else {
70: return false;
71: }
72: }
73:
74: public boolean setSelectedItemByName(String name) {
75: NameValueListModel.NameValuePair nameValuePair = getNameValueListModel()
76: .getEntryByName(name);
77: if (nameValuePair != null) {
78: setSelectedItem(nameValuePair);
79: return true;
80: } else {
81: return false;
82: }
83: }
84: }
|