KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > AbstractCellEditor


1 /*
2  * @(#)AbstractCellEditor.java 1.11 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing;
9
10 import javax.swing.event.*;
11 import java.util.EventObject JavaDoc;
12 import java.io.Serializable JavaDoc;
13
14 /**
15  * @version 1.11 12/19/03
16  *
17  * A base class for <code>CellEditors</code>, providing default
18  * implementations for the methods in the <code>CellEditor</code>
19  * interface except <code>getCellEditorValue()</code>.
20  * Like the other abstract implementations in Swing, also manages a list
21  * of listeners.
22  *
23  * <p>
24  * <strong>Warning:</strong>
25  * Serialized objects of this class will not be compatible with
26  * future Swing releases. The current serialization support is
27  * appropriate for short term storage or RMI between applications running
28  * the same version of Swing. As of 1.4, support for long term storage
29  * of all JavaBeans<sup><font size="-2">TM</font></sup>
30  * has been added to the <code>java.beans</code> package.
31  * Please see {@link java.beans.XMLEncoder}.
32  *
33  * @author Philip Milne
34  */

35
36 public abstract class AbstractCellEditor implements CellEditor JavaDoc, Serializable JavaDoc {
37
38     protected EventListenerList listenerList = new EventListenerList();
39     transient protected ChangeEvent changeEvent = null;
40
41     // Force this to be implemented.
42
// public Object getCellEditorValue()
43

44     /**
45      * Returns true.
46      * @param e an event object
47      * @return true
48      */

49     public boolean isCellEditable(EventObject JavaDoc e) {
50     return true;
51     }
52
53     /**
54      * Returns true.
55      * @param anEvent an event object
56      * @return true
57      */

58     public boolean shouldSelectCell(EventObject JavaDoc anEvent) {
59     return true;
60     }
61     
62     /**
63      * Calls <code>fireEditingStopped</code> and returns true.
64      * @return true
65      */

66     public boolean stopCellEditing() {
67     fireEditingStopped();
68     return true;
69     }
70
71     /**
72      * Calls <code>fireEditingCanceled</code>.
73      */

74     public void cancelCellEditing() {
75     fireEditingCanceled();
76     }
77
78     /**
79      * Adds a <code>CellEditorListener</code> to the listener list.
80      * @param l the new listener to be added
81      */

82     public void addCellEditorListener(CellEditorListener l) {
83     listenerList.add(CellEditorListener.class, l);
84     }
85
86     /**
87      * Removes a <code>CellEditorListener</code> from the listener list.
88      * @param l the listener to be removed
89      */

90     public void removeCellEditorListener(CellEditorListener l) {
91     listenerList.remove(CellEditorListener.class, l);
92     }
93
94     /**
95      * Returns an array of all the <code>CellEditorListener</code>s added
96      * to this AbstractCellEditor with addCellEditorListener().
97      *
98      * @return all of the <code>CellEditorListener</code>s added or an empty
99      * array if no listeners have been added
100      * @since 1.4
101      */

102     public CellEditorListener[] getCellEditorListeners() {
103         return (CellEditorListener[])listenerList.getListeners(
104                 CellEditorListener.class);
105     }
106
107     /**
108      * Notifies all listeners that have registered interest for
109      * notification on this event type. The event instance
110      * is created lazily.
111      *
112      * @see EventListenerList
113      */

114     protected void fireEditingStopped() {
115     // Guaranteed to return a non-null array
116
Object JavaDoc[] listeners = listenerList.getListenerList();
117     // Process the listeners last to first, notifying
118
// those that are interested in this event
119
for (int i = listeners.length-2; i>=0; i-=2) {
120         if (listeners[i]==CellEditorListener.class) {
121         // Lazily create the event:
122
if (changeEvent == null)
123             changeEvent = new ChangeEvent(this);
124         ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
125         }
126     }
127     }
128
129     /**
130      * Notifies all listeners that have registered interest for
131      * notification on this event type. The event instance
132      * is created lazily.
133      *
134      * @see EventListenerList
135      */

136     protected void fireEditingCanceled() {
137     // Guaranteed to return a non-null array
138
Object JavaDoc[] listeners = listenerList.getListenerList();
139     // Process the listeners last to first, notifying
140
// those that are interested in this event
141
for (int i = listeners.length-2; i>=0; i-=2) {
142         if (listeners[i]==CellEditorListener.class) {
143         // Lazily create the event:
144
if (changeEvent == null)
145             changeEvent = new ChangeEvent(this);
146         ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
147         }
148     }
149     }
150 }
151
Popular Tags