KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > gui > AbstractCellEditor


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2002 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19

20 package com.puppycrawl.tools.checkstyle.gui;
21
22 import java.util.EventObject JavaDoc;
23 import javax.swing.CellEditor JavaDoc;
24 import javax.swing.event.CellEditorListener JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.EventListenerList JavaDoc;
27
28 /**
29  * Abstract implementation of a CellEditor.
30  *
31  * @author http://java.sun.com/products/jfc/tsc/articles/treetable2
32  */

33 public class AbstractCellEditor implements CellEditor JavaDoc
34 {
35     private final EventListenerList JavaDoc mListenerList = new EventListenerList JavaDoc();
36
37     /** @see CellEditor */
38     public Object JavaDoc getCellEditorValue()
39     {
40         return null;
41     }
42
43     /** @see CellEditor */
44     public boolean isCellEditable(EventObject JavaDoc e)
45     {
46         return true;
47     }
48
49     /** @see CellEditor */
50     public boolean shouldSelectCell(EventObject JavaDoc anEvent)
51     {
52         return false;
53     }
54
55     /** @see CellEditor */
56     public boolean stopCellEditing()
57     {
58         return true;
59     }
60
61     /** @see CellEditor */
62     public void cancelCellEditing()
63     {
64     }
65
66     /** @see CellEditor */
67     public void addCellEditorListener(CellEditorListener JavaDoc l)
68     {
69         mListenerList.add(CellEditorListener JavaDoc.class, l);
70     }
71
72     /** @see CellEditor */
73     public void removeCellEditorListener(CellEditorListener JavaDoc l)
74     {
75         mListenerList.remove(CellEditorListener JavaDoc.class, l);
76     }
77
78     /*
79      * Notify all listeners that have registered interest for
80      * notification on this event type.
81      * @see EventListenerList
82      */

83     protected void fireEditingStopped()
84     {
85         // Guaranteed to return a non-null array
86
final Object JavaDoc[] listeners = mListenerList.getListenerList();
87         // Process the listeners last to first, notifying
88
// those that are interested in this event
89
for (int i = listeners.length - 2; i >= 0; i -= 2) {
90             if (listeners[i] == CellEditorListener JavaDoc.class) {
91                 ((CellEditorListener JavaDoc) listeners[i + 1]).editingStopped(new ChangeEvent JavaDoc(this));
92             }
93         }
94     }
95
96     /*
97      * Notify all listeners that have registered interest for
98      * notification on this event type.
99      * @see EventListenerList
100      */

101     protected void fireEditingCanceled()
102     {
103         // Guaranteed to return a non-null array
104
final Object JavaDoc[] listeners = mListenerList.getListenerList();
105         // Process the listeners last to first, notifying
106
// those that are interested in this event
107
for (int i = listeners.length - 2; i >= 0; i -= 2) {
108             if (listeners[i] == CellEditorListener JavaDoc.class) {
109                 ((CellEditorListener JavaDoc) listeners[i + 1]).editingCanceled(new ChangeEvent JavaDoc(this));
110             }
111         }
112     }
113 }
114
Popular Tags