KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > autocomplete > BasicAddressAutocompleteComboBox


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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
19 import java.util.List JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import javax.swing.ComboBoxModel JavaDoc;
23 import javax.swing.JComboBox JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25
26 import org.columba.addressbook.model.BasicModelPartial;
27
28
29 /**
30  * ComboBox for {@link BasicModelPartial} objects. Includes an
31  * autocomplete feature.
32  *
33  * @author fdietz
34  */

35
36 public class BasicAddressAutocompleteComboBox extends JComboBox JavaDoc {
37     public BasicAddressAutocompleteComboBox() {
38         super();
39     }
40
41     public BasicAddressAutocompleteComboBox(ComboBoxModel JavaDoc cm) {
42         super(cm);
43         addCompleter();
44     }
45
46     public BasicAddressAutocompleteComboBox(Object JavaDoc[] items) {
47         super(items);
48         addCompleter();
49     }
50
51     public BasicAddressAutocompleteComboBox(List JavaDoc v) {
52         super((Vector JavaDoc) v);
53         addCompleter();
54     }
55
56     protected void addCompleter() {
57         setEditable(true);
58
59         Object JavaDoc[] completions = getAddresses();
60         new AddressAutoCompleter(this, completions);
61     }
62
63     private Object JavaDoc[] getAddresses() {
64         return AddressCollector.getInstance().getAddresses();
65     }
66
67     public String JavaDoc getText() {
68         return ((JTextField JavaDoc) getEditor().getEditorComponent()).getText();
69     }
70
71     public void setText(String JavaDoc text) {
72         ((JTextField JavaDoc) getEditor().getEditorComponent()).setText(text);
73     }
74 }
75
Popular Tags