source: trunk/gli/src/org/greenstone/gatherer/gui/combobox/GComboBox.java@ 4366

Last change on this file since 4366 was 4366, checked in by kjdon, 21 years ago

re-tabbed the code for java

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.gui.combobox;
44
45import java.awt.event.KeyListener;
46import javax.swing.ComboBoxModel;
47import javax.swing.JComboBox;
48import javax.swing.JTextField;
49import javax.swing.event.DocumentListener;
50/** In order for a JComboBox to perform the way Gatherer requires, ie firing
51 * a DocumentEvent of some form whenever the user edits the content of the
52 * currently selected item, we need to subclass JComboBox and build a version
53 * which adds a DocumentListener to the JTextField within the combobox not to
54 * the combobox itself. The same deal applies for KeyListeners.
55 */
56public class GComboBox
57 extends JComboBox {
58
59 private JTextField text;
60
61 public GComboBox() {
62 super();
63 text = (JTextField) this.getEditor().getEditorComponent();
64 }
65
66 public GComboBox(ComboBoxModel model) {
67 super(model);
68 text = (JTextField) this.getEditor().getEditorComponent();
69 }
70
71 public void addDocumentListener(DocumentListener listener) {
72 if(text != null) text.getDocument().addDocumentListener(listener);
73 }
74
75 public void addKeyListener(KeyListener listener) {
76 if(text != null) text.addKeyListener(listener);
77 }
78
79 public String getText() {
80 if(text != null) {
81 return text.getText();
82 }
83 GComboBoxModel model = (GComboBoxModel)this.getModel();
84 return (String)model.getSelectedItem();
85 }
86
87 public void setText(String value) {
88 if(text != null) text.setText(value);
89 }
90
91 public void removeDocumentListener(DocumentListener listener) {
92 if(text != null) text.getDocument().removeDocumentListener(listener);
93 }
94
95 public void removeKeyListener(KeyListener listener) {
96 if(text != null) text.removeKeyListener(listener);
97 }
98}
Note: See TracBrowser for help on using the repository browser.