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