001 package ui.editor; 002 003 import java.awt.Component; 004 import java.awt.event.*; 005 import java.awt.AWTEvent; 006 import javax.swing.*; 007 import javax.swing.event.*; 008 import java.util.EventObject; 009 import java.io.Serializable; 010 011 /** Used by JTreeTable. 012 */ 013 public class AbstractCellEditor implements CellEditor { 014 015 protected EventListenerList listenerList = new EventListenerList(); 016 017 public Object getCellEditorValue() { return null; } 018 public boolean isCellEditable(EventObject e) { return true; } 019 public boolean shouldSelectCell(EventObject anEvent) { return false; } 020 public boolean stopCellEditing() { return true; } 021 public void cancelCellEditing() {} 022 023 public void addCellEditorListener(CellEditorListener l) { 024 listenerList.add(CellEditorListener.class, l); 025 } 026 027 public void removeCellEditorListener(CellEditorListener l) { 028 listenerList.remove(CellEditorListener.class, l); 029 } 030 031 /** 032 * Notify all CellEditorListeners that have registered interest for 033 * notification on this event type. 034 * @see EventListenerList 035 */ 036 protected void fireEditingStopped() { 037 // Guaranteed to return a non-null array 038 Object[] listeners = listenerList.getListenerList(); 039 // Process the listeners last to first, notifying 040 // those that are interested in this event 041 for (int i = listeners.length - 2; i >= 0; i-=2) { 042 if (listeners[i] == CellEditorListener.class) { 043 ((CellEditorListener)listeners[i+1]).editingStopped(new ChangeEvent(this)); 044 } 045 } 046 } 047 048 protected void fireEditingCanceled() { 049 Object[] listeners = listenerList.getListenerList(); 050 for (int i = listeners.length - 2; i >= 0; i-=2) { 051 if (listeners[i] == CellEditorListener.class) { 052 ((CellEditorListener)listeners[i+1]).editingCanceled(new ChangeEvent(this)); 053 } 054 } 055 } 056 }