1 /*
2 * %W% %E%
3 *
4 * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Redistribution in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials
16 * provided with the distribution.
17 *
18 * Neither the name of Sun Microsystems, Inc. or the names of
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * This software is provided "AS IS," without a warranty of any
23 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
24 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
26 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
27 * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
28 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
29 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
30 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
31 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
32 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
33 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
34 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
35 *
36 * You acknowledge that this software is not designed, licensed or
37 * intended for use in the design, construction, operation or
38 * maintenance of any nuclear facility.
39 */
40
41 package uk.ac.rdg.resc.jstyx.client.browser;
42
43 import java.awt.Component;
44 import java.awt.event.*;
45 import java.awt.AWTEvent;
46 import javax.swing.*;
47 import javax.swing.event.*;
48 import java.util.EventObject;
49 import java.io.Serializable;
50
51 /***
52 * @version %I% %G%
53 *
54 * A base class for CellEditors, providing default implementations for all
55 * methods in the CellEditor interface and support for managing a series
56 * of listeners.
57 *
58 * @author Philip Milne
59 */
60
61 public class AbstractCellEditor implements CellEditor {
62
63 protected EventListenerList listenerList = new EventListenerList();
64
65 public Object getCellEditorValue() { return null; }
66 public boolean isCellEditable(EventObject e) { return true; }
67 public boolean shouldSelectCell(EventObject anEvent) { return false; }
68 public boolean stopCellEditing() { return true; }
69 public void cancelCellEditing() {}
70
71 public void addCellEditorListener(CellEditorListener l) {
72 listenerList.add(CellEditorListener.class, l);
73 }
74
75 public void removeCellEditorListener(CellEditorListener l) {
76 listenerList.remove(CellEditorListener.class, l);
77 }
78
79 /***
80 * Notify all listeners that have registered interest for
81 * notification on this event type.
82 * @see EventListenerList
83 */
84 protected void fireEditingStopped() {
85 // Guaranteed to return a non-null array
86 Object[] listeners = listenerList.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.class) {
91 ((CellEditorListener)listeners[i+1]).editingStopped(new ChangeEvent(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 // Guaranteed to return a non-null array
103 Object[] listeners = listenerList.getListenerList();
104 // Process the listeners last to first, notifying
105 // those that are interested in this event
106 for (int i = listeners.length-2; i>=0; i-=2) {
107 if (listeners[i]==CellEditorListener.class) {
108 ((CellEditorListener)listeners[i+1]).editingCanceled(new ChangeEvent(this));
109 }
110 }
111 }
112 }
113