01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Anton Avtamonov
20: * @version $Revision$
21: */package javax.swing.plaf.basic;
22:
23: import java.awt.Component;
24: import java.awt.event.ActionListener;
25: import java.awt.event.FocusEvent;
26: import java.awt.event.FocusListener;
27:
28: import javax.swing.ComboBoxEditor;
29: import javax.swing.JTextField;
30:
31: public class BasicComboBoxEditor implements ComboBoxEditor,
32: FocusListener {
33:
34: private Object item = "";
35:
36: public static class UIResource extends BasicComboBoxEditor
37: implements javax.swing.plaf.UIResource {
38: }
39:
40: protected JTextField editor = new JTextField();
41:
42: public void addActionListener(final ActionListener l) {
43: editor.addActionListener(l);
44: }
45:
46: public void removeActionListener(final ActionListener l) {
47: editor.removeActionListener(l);
48: }
49:
50: public void focusGained(final FocusEvent e) {
51: }
52:
53: public void focusLost(final FocusEvent e) {
54:
55: }
56:
57: public Component getEditorComponent() {
58: return editor;
59: }
60:
61: public Object getItem() {
62: String text = editor.getText();
63: if (!text.equals(item.toString())) {
64: item = text;
65: }
66: return item;
67: }
68:
69: public void setItem(final Object item) {
70: this .item = item != null ? item : "";
71: editor.setText(this .item.toString());
72: }
73:
74: public void selectAll() {
75: editor.requestFocus();
76: editor.selectAll();
77: }
78: }
|