KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > AbstractCellEditor


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4  
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7  
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9  
10    $Log: AbstractCellEditor.java,v $
11    Revision 1.1 2004/04/16 14:38:47 bobintetley
12    Table and Tree cell editor support
13
14  
15  */

16 package swingwtx.swing;
17
18 import java.util.*;
19
20 import swingwtx.swing.event.*;
21
22 /**
23  * Base class for cell editors
24  *
25  * @author Robin Rawson-Tetley
26  */

27 public abstract class AbstractCellEditor implements CellEditor {
28
29     protected Vector listeners = new Vector();
30
31     public boolean isCellEditable(EventObject e) {
32     return true;
33     }
34
35     public boolean shouldSelectCell(EventObject anEvent) {
36     return true;
37     }
38
39     public boolean stopCellEditing() {
40     fireEditingStopped();
41     return true;
42     }
43
44     public void cancelCellEditing() {
45     fireEditingCanceled();
46     }
47
48
49     public void addCellEditorListener(CellEditorListener l) {
50     listeners.add(l);
51     }
52
53     public void removeCellEditorListener(CellEditorListener l) {
54     listeners.remove(l);
55     }
56
57     public CellEditorListener[] getCellEditorListeners() {
58         if (listeners.size() == 0) return null;
59         CellEditorListener[] l = new CellEditorListener[listeners.size()];
60         for (int i = 0; i < listeners.size(); i++)
61             l[i] = (CellEditorListener) listeners.get(i);
62         return l;
63     }
64
65     protected void fireEditingStopped() {
66     for (int i = 0; i < listeners.size(); i++) {
67             ChangeEvent e = new ChangeEvent(this);
68             ((CellEditorListener) listeners.get(i)).editingStopped(e);
69     }
70     }
71
72     protected void fireEditingCanceled() {
73     for (int i = 0; i < listeners.size(); i++) {
74             ChangeEvent e = new ChangeEvent(this);
75             ((CellEditorListener) listeners.get(i)).editingCanceled(e);
76     }
77     }
78 }
79
Popular Tags