~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/autocomplete/TextComponentAdaptor.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2008-03-08 16:18:24 UTC
  • Revision ID: james.westby@ubuntu.com-20080308161824-wsahvl9pwzjcea3g
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: TextComponentAdaptor.java,v 1.2 2007/11/02 14:26:47 kschaefe Exp $
 
3
 *
 
4
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 
5
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 * 
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
package org.jdesktop.swingx.autocomplete;
 
22
 
 
23
import java.util.List;
 
24
import javax.swing.text.JTextComponent;
 
25
 
 
26
/**
 
27
 * An implementation of the AbstractAutoCompleteAdaptor that is suitable for a
 
28
 * JTextComponent.
 
29
 * 
 
30
 * @author Thomas Bierhance
 
31
 */
 
32
public class TextComponentAdaptor extends AbstractAutoCompleteAdaptor {
 
33
    
 
34
    /** a <tt>List</tt> containing the strings to be used for automatic
 
35
     * completion */
 
36
    List<?> items;
 
37
    /** the text component that is used for automatic completion*/
 
38
    JTextComponent textComponent;
 
39
    /** the item that is currently selected */
 
40
    Object selectedItem;
 
41
    
 
42
    /**
 
43
     * Creates a new <tt>TextComponentAdaptor</tt> for the given list and text
 
44
     * component.
 
45
     * 
 
46
     * @param items a <tt>List</tt> that contains the items that are used for
 
47
     * automatic completion
 
48
     * @param textComponent the text component that will be used automatic
 
49
     * completion
 
50
     */
 
51
    public TextComponentAdaptor(JTextComponent textComponent, List<?> items) {
 
52
        this.items = items;
 
53
        this.textComponent = textComponent;
 
54
    }
 
55
    
 
56
    public Object getSelectedItem() {
 
57
        return selectedItem;
 
58
    }
 
59
    
 
60
    public int getItemCount() {
 
61
        return items.size();
 
62
    }
 
63
    
 
64
    public Object getItem(int index) {
 
65
        return items.get(index);
 
66
    }
 
67
    
 
68
    public void setSelectedItem(Object item) {
 
69
        selectedItem = item;
 
70
    }
 
71
    
 
72
    public JTextComponent getTextComponent() {
 
73
        return textComponent;
 
74
    }
 
75
}