01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.addressbook.gui.autocomplete;
17:
18: import java.util.List;
19: import java.util.Vector;
20:
21: import javax.swing.ComboBoxModel;
22: import javax.swing.JComboBox;
23: import javax.swing.JTextField;
24:
25: import org.columba.addressbook.model.BasicModelPartial;
26:
27: /**
28: * ComboBox for {@link BasicModelPartial} objects. Includes an
29: * autocomplete feature.
30: *
31: * @author fdietz
32: */
33:
34: public class BasicAddressAutocompleteComboBox extends JComboBox {
35: public BasicAddressAutocompleteComboBox() {
36: super ();
37: }
38:
39: public BasicAddressAutocompleteComboBox(ComboBoxModel cm) {
40: super (cm);
41: addCompleter();
42: }
43:
44: public BasicAddressAutocompleteComboBox(Object[] items) {
45: super (items);
46: addCompleter();
47: }
48:
49: public BasicAddressAutocompleteComboBox(List v) {
50: super ((Vector) v);
51: addCompleter();
52: }
53:
54: protected void addCompleter() {
55: setEditable(true);
56:
57: Object[] completions = getAddresses();
58: new AddressAutoCompleter(this , completions);
59: }
60:
61: private Object[] getAddresses() {
62: return AddressCollector.getInstance().getAddresses();
63: }
64:
65: public String getText() {
66: return ((JTextField) getEditor().getEditorComponent())
67: .getText();
68: }
69:
70: public void setText(String text) {
71: ((JTextField) getEditor().getEditorComponent()).setText(text);
72: }
73: }
|