Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / javax / swing / plaf / basic / BasicComboBoxEditor.java
blobd87926196568e0fcc8cfc56d03178b531412fe8c
1 /* BasicComboBoxEditor.java --
2 Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.plaf.basic;
41 import java.awt.Component;
42 import java.awt.event.ActionListener;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.FocusListener;
46 import javax.swing.ComboBoxEditor;
47 import javax.swing.JTextField;
49 /**
50 * An editor used by the {@link BasicComboBoxUI} class. This editor uses a
51 * {@link JTextField} as the editor component.
53 * @author Olga Rodimina
55 public class BasicComboBoxEditor extends Object implements ComboBoxEditor,
56 FocusListener
58 /** The editor component. */
59 protected JTextField editor;
61 /**
62 * Creates a new <code>BasicComboBoxEditor</code> instance.
64 public BasicComboBoxEditor()
66 editor = new JTextField();
67 editor.setBorder(null);
68 editor.setColumns(9);
71 /**
72 * Returns the component that will be used by the combo box to display and
73 * edit the currently selected item in the combo box.
75 * @return The editor component, which is a {@link JTextField} in this case.
77 public Component getEditorComponent()
79 return editor;
82 /**
83 * Sets item that should be edited when any editing operation is performed
84 * by the user. The value is always equal to the currently selected value
85 * in the combo box. Thus whenever a different value is selected from the
86 * combo box list then this method should be called to change editing
87 * item to the new selected item.
89 * @param item item that is currently selected in the combo box
91 public void setItem(Object item)
93 if (item == null)
94 editor.setText("");
95 else
96 editor.setText(item.toString());
99 /**
100 * Returns the text from the editor component.
102 * @return The text from the editor component.
104 public Object getItem()
106 return editor.getText();
110 * Selects all the text in the editor component.
112 public void selectAll()
114 editor.selectAll();
118 * This method is called when textfield gains focus. This will enable
119 * editing of the selected item.
121 * @param e the FocusEvent describing change in focus.
123 public void focusGained(FocusEvent e)
125 // FIXME: Need to implement
129 * This method is called when textfield loses focus. If during this time any
130 * editting operation was performed by the user, then it will be cancelled
131 * and selected item will not be changed.
133 * @param e the FocusEvent describing change in focus
135 public void focusLost(FocusEvent e)
137 // FIXME: Need to implement
141 * Adds an {@link ActionListener} to the editor component. If the user will
142 * edit currently selected item in the textfield and pressEnter, then action
143 * will be performed. The actionPerformed of this ActionListener should
144 * change the selected item of the comboBox to the newly editted selected
145 * item.
147 * @param l the ActionListener responsible for changing selected item of the
148 * combo box when it is editted by the user.
150 public void addActionListener(ActionListener l)
152 editor.addActionListener(l);
156 * Removes the {@link ActionListener} from the editor component.
158 * @param l the listener to remove.
160 public void removeActionListener(ActionListener l)
162 editor.removeActionListener(l);
166 * A subclass of {@link BasicComboBoxEditor} that implements the
167 * {@link UIResource} interface.
169 public static class UIResource extends BasicComboBoxEditor
170 implements javax.swing.plaf.UIResource
173 * Creates a new <code>BasicComboBoxEditor.UIResource</code> instance.
175 public UIResource()
177 // Nothing to do here.