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 /*
21 * %W% %E%
22 *
23 * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
24 *
25 * Redistribution and use in source and binary forms, with or
26 * without modification, are permitted provided that the following
27 * conditions are met:
28 *
29 * - Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 *
32 * - Redistribution in binary form must reproduce the above
33 * copyright notice, this list of conditions and the following
34 * disclaimer in the documentation and/or other materials
35 * provided with the distribution.
36 *
37 * Neither the name of Sun Microsystems, Inc. or the names of
38 * contributors may be used to endorse or promote products derived
39 * from this software without specific prior written permission.
40 *
41 * This software is provided "AS IS," without a warranty of any
42 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
43 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
44 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
45 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
46 * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
47 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
48 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
49 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
50 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
51 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
52 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
53 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
54 *
55 * You acknowledge that this software is not designed, licensed or
56 * intended for use in the design, construction, operation or
57 * maintenance of any nuclear facility.
58 */
59
60
61 package com.puppycrawl.tools.checkstyle.gui;
62
63 import java.util.EventObject;
64 import javax.swing.CellEditor;
65 import javax.swing.event.CellEditorListener;
66 import javax.swing.event.ChangeEvent;
67 import javax.swing.event.EventListenerList;
68
69 /**
70 * A base class for CellEditors, providing default implementations for all
71 * methods in the CellEditor interface and support for managing a series
72 * of listeners.
73 *
74 * <a href="http://java.sun.com/products/jfc/tsc/articles/treetable1/index.html">Original Source Location</a>
75 *
76 * @author Philip Milne
77 */
78 public class AbstractCellEditor implements CellEditor
79 {
80 private final EventListenerList listenerList = new EventListenerList();
81
82 /** @see CellEditor */
83 @Override
84 public Object getCellEditorValue()
85 {
86 return null;
87 }
88
89 /** @see CellEditor */
90 @Override
91 public boolean isCellEditable(EventObject e)
92 {
93 return true;
94 }
95
96 /** @see CellEditor */
97 @Override
98 public boolean shouldSelectCell(EventObject anEvent)
99 {
100 return false;
101 }
102
103 /** @see CellEditor */
104 @Override
105 public boolean stopCellEditing()
106 {
107 return true;
108 }
109
110 /** @see CellEditor */
111 @Override
112 public void cancelCellEditing()
113 {
114 }
115
116 /** @see CellEditor */
117 @Override
118 public void addCellEditorListener(CellEditorListener l)
119 {
120 listenerList.add(CellEditorListener.class, l);
121 }
122
123 /** @see CellEditor */
124 @Override
125 public void removeCellEditorListener(CellEditorListener l)
126 {
127 listenerList.remove(CellEditorListener.class, l);
128 }
129
130 /*
131 * Notify all listeners that have registered interest for
132 * notification on this event type.
133 * @see EventListenerList
134 */
135 protected void fireEditingStopped()
136 {
137 // Guaranteed to return a non-null array
138 final Object[] listeners = listenerList.getListenerList();
139 // Process the listeners last to first, notifying
140 // those that are interested in this event
141 for (int i = listeners.length - 2; i >= 0; i -= 2) {
142 if (listeners[i] == CellEditorListener.class) {
143 ((CellEditorListener) listeners[i + 1]).editingStopped(new ChangeEvent(this));
144 }
145 }
146 }
147
148 /*
149 * Notify all listeners that have registered interest for
150 * notification on this event type.
151 * @see EventListenerList
152 */
153 protected void fireEditingCanceled()
154 {
155 // Guaranteed to return a non-null array
156 final Object[] listeners = listenerList.getListenerList();
157 // Process the listeners last to first, notifying
158 // those that are interested in this event
159 for (int i = listeners.length - 2; i >= 0; i -= 2) {
160 if (listeners[i] == CellEditorListener.class) {
161 ((CellEditorListener) listeners[i + 1]).editingCanceled(new ChangeEvent(this));
162 }
163 }
164 }
165 }