01: // EditableStringChoice.java
02: // $Id: EditableStringChoice.java,v 1.3 2000/08/16 21:37:31 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigadmin.widgets;
07:
08: import java.awt.Component;
09: import java.awt.BorderLayout;
10: import java.awt.GridLayout;
11: import java.awt.event.ItemListener;
12: import java.awt.event.ItemEvent;
13: import java.awt.event.ActionListener;
14:
15: import javax.swing.JPanel;
16: import javax.swing.JTextField;
17: import javax.swing.JComboBox;
18: import javax.swing.BorderFactory;
19: import javax.swing.ListCellRenderer;
20: import javax.swing.event.DocumentListener;
21:
22: /**
23: * An editable JComboBox.
24: * @version $Revision: 1.3 $
25: * @author Benoît Mahé (bmahe@w3.org)
26: */
27:
28: public class EditableStringChoice extends JPanel {
29:
30: private JComboBox combo = null;
31:
32: public synchronized void addItemListener(ItemListener l) {
33: combo.addItemListener(l);
34: }
35:
36: public synchronized void removeItemListener(ItemListener l) {
37: combo.removeItemListener(l);
38: }
39:
40: public void addItem(Object item) {
41: combo.addItem(item);
42: }
43:
44: public void addItems(Object items[]) {
45: for (int i = 0; i < items.length; i++) {
46: if (items[i] != null)
47: addItem(items[i]);
48: }
49: }
50:
51: public synchronized void select(String str) {
52: combo.setSelectedItem(str);
53: }
54:
55: public synchronized void remove(String item) {
56: combo.removeItem(item);
57: }
58:
59: public void removeAll() {
60: combo.removeAll();
61: }
62:
63: public String getText() {
64: return combo.getSelectedItem().toString();
65: }
66:
67: public void setRenderer(ListCellRenderer aRenderer) {
68: combo.setRenderer(aRenderer);
69: }
70:
71: public void setMaximumRowCount(int count) {
72: combo.setMaximumRowCount(count);
73: }
74:
75: public void initialize(Object items[]) {
76:
77: combo = new JComboBox(items);
78: combo.setEditable(true);
79:
80: setLayout(new BorderLayout(5, 5));
81: add(combo, BorderLayout.CENTER);
82: }
83:
84: /**
85: * Get a "one line" String choice with no border.
86: */
87: public EditableStringChoice() {
88: super();
89: }
90:
91: }
|