KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > treetable > AbstractCellEditor


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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

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

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