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: package javax.swing;
19:
20: import java.io.Serializable;
21: import java.util.EventObject;
22:
23: import javax.swing.event.CellEditorListener;
24: import javax.swing.event.ChangeEvent;
25: import javax.swing.event.EventListenerList;
26:
27: public abstract class AbstractCellEditor implements CellEditor,
28: Serializable {
29: protected EventListenerList listenerList = new EventListenerList();
30: protected transient ChangeEvent changeEvent;
31:
32: public boolean isCellEditable(final EventObject e) {
33: return true;
34: }
35:
36: public boolean shouldSelectCell(final EventObject event) {
37: return true;
38: }
39:
40: public boolean stopCellEditing() {
41: fireEditingStopped();
42: return true;
43: }
44:
45: public void cancelCellEditing() {
46: fireEditingCanceled();
47: }
48:
49: public void addCellEditorListener(final CellEditorListener l) {
50: listenerList.add(CellEditorListener.class, l);
51: }
52:
53: public void removeCellEditorListener(final CellEditorListener l) {
54: listenerList.remove(CellEditorListener.class, l);
55: }
56:
57: public CellEditorListener[] getCellEditorListeners() {
58: return listenerList.getListeners(CellEditorListener.class);
59: }
60:
61: protected void fireEditingStopped() {
62: CellEditorListener[] listeners = getCellEditorListeners();
63: for (int i = 0; i < listeners.length; i++) {
64: listeners[i].editingStopped(getChangeEvent());
65: }
66: }
67:
68: protected void fireEditingCanceled() {
69: CellEditorListener[] listeners = getCellEditorListeners();
70: for (int i = 0; i < listeners.length; i++) {
71: listeners[i].editingCanceled(getChangeEvent());
72: }
73: }
74:
75: private ChangeEvent getChangeEvent() {
76: if (changeEvent == null) {
77: changeEvent = new ChangeEvent(this);
78: }
79:
80: return changeEvent;
81: }
82: }
|