KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > treetable > AbstractCellEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * this file is derived from the "Creating TreeTable" article at
22  * http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html
23  */

24 package org.netbeans.modules.tasklist.usertasks.treetable;
25
26 import java.util.EventObject JavaDoc;
27
28 import javax.swing.CellEditor JavaDoc;
29 import javax.swing.event.CellEditorListener JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.EventListenerList JavaDoc;
32
33 /**
34  * Abstract cell editor. Implement all abstract methods of CellEditor.
35  */

36 public class AbstractCellEditor implements CellEditor JavaDoc {
37     /** CellEditorListener[] */
38     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
39     
40     public Object JavaDoc getCellEditorValue() { return null; }
41     public boolean isCellEditable(EventObject JavaDoc e) { return true; }
42     public boolean shouldSelectCell(EventObject JavaDoc anEvent) { return false; }
43     public boolean stopCellEditing() { return true; }
44     public void cancelCellEditing() {}
45     
46     public void addCellEditorListener(CellEditorListener JavaDoc l) {
47         listenerList.add(CellEditorListener JavaDoc.class, l);
48     }
49     
50     public void removeCellEditorListener(CellEditorListener JavaDoc l) {
51         listenerList.remove(CellEditorListener JavaDoc.class, l);
52     }
53     
54     /**
55      * Notify all listeners that have registered interest for
56      * notification on this event type.
57      * @see EventListenerList
58      */

59     protected void fireEditingStopped() {
60         // Guaranteed to return a non-null array
61
Object JavaDoc[] listeners = listenerList.getListenerList();
62         // Process the listeners last to first, notifying
63
// those that are interested in this event
64
for (int i = listeners.length-2; i>=0; i-=2) {
65             if (listeners[i]==CellEditorListener JavaDoc.class) {
66                 ((CellEditorListener JavaDoc)listeners[i+1]).editingStopped(
67                     new ChangeEvent JavaDoc(this));
68             }
69         }
70     }
71     
72     /**
73      * Notify all listeners that have registered interest for
74      * notification on this event type.
75      * @see EventListenerList
76      */

77     protected void fireEditingCanceled() {
78         // Guaranteed to return a non-null array
79
Object JavaDoc[] listeners = listenerList.getListenerList();
80         // Process the listeners last to first, notifying
81
// those that are interested in this event
82
for (int i = listeners.length-2; i>=0; i-=2) {
83             if (listeners[i]==CellEditorListener JavaDoc.class) {
84                 ((CellEditorListener JavaDoc)listeners[i+1]).editingCanceled(
85                     new ChangeEvent JavaDoc(this));
86             }
87         }
88     }
89 }
90
Popular Tags