KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > swing > treetable > AbstractCellEditor


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.swing.treetable;
19
20 import java.util.EventObject JavaDoc;
21
22 import javax.swing.CellEditor JavaDoc;
23 import javax.swing.event.CellEditorListener JavaDoc;
24 import javax.swing.event.ChangeEvent JavaDoc;
25 import javax.swing.event.EventListenerList JavaDoc;
26
27 public class AbstractCellEditor implements CellEditor JavaDoc {
28
29     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
30
31     public Object JavaDoc getCellEditorValue() { return null; }
32     public boolean isCellEditable(EventObject JavaDoc e) { return true; }
33     public boolean shouldSelectCell(EventObject JavaDoc anEvent) { return false; }
34     public boolean stopCellEditing() { return true; }
35     public void cancelCellEditing() {}
36
37     public void addCellEditorListener(CellEditorListener JavaDoc l) {
38     listenerList.add(CellEditorListener JavaDoc.class, l);
39     }
40
41     public void removeCellEditorListener(CellEditorListener JavaDoc l) {
42     listenerList.remove(CellEditorListener JavaDoc.class, l);
43     }
44
45     /*
46      * Notify all listeners that have registered interest for
47      * notification on this event type.
48      * @see EventListenerList
49      */

50     protected void fireEditingStopped() {
51     // Guaranteed to return a non-null array
52
Object JavaDoc[] listeners = listenerList.getListenerList();
53     // Process the listeners last to first, notifying
54
// those that are interested in this event
55
for (int i = listeners.length-2; i>=0; i-=2) {
56         if (listeners[i]==CellEditorListener JavaDoc.class) {
57         ((CellEditorListener JavaDoc)listeners[i+1]).editingStopped(new ChangeEvent JavaDoc(this));
58         }
59     }
60     }
61
62     /*
63      * Notify all listeners that have registered interest for
64      * notification on this event type.
65      * @see EventListenerList
66      */

67     protected void fireEditingCanceled() {
68     // Guaranteed to return a non-null array
69
Object JavaDoc[] listeners = listenerList.getListenerList();
70     // Process the listeners last to first, notifying
71
// those that are interested in this event
72
for (int i = listeners.length-2; i>=0; i-=2) {
73         if (listeners[i]==CellEditorListener JavaDoc.class) {
74         ((CellEditorListener JavaDoc)listeners[i+1]).editingCanceled(new ChangeEvent JavaDoc(this));
75         }
76     }
77     }
78 }
79
Popular Tags