1 7 8 package javax.swing; 9 10 import javax.swing.event.*; 11 import java.util.EventObject ; 12 import java.io.Serializable ; 13 14 35 36 public abstract class AbstractCellEditor implements CellEditor , Serializable { 37 38 protected EventListenerList listenerList = new EventListenerList(); 39 transient protected ChangeEvent changeEvent = null; 40 41 44 49 public boolean isCellEditable(EventObject e) { 50 return true; 51 } 52 53 58 public boolean shouldSelectCell(EventObject anEvent) { 59 return true; 60 } 61 62 66 public boolean stopCellEditing() { 67 fireEditingStopped(); 68 return true; 69 } 70 71 74 public void cancelCellEditing() { 75 fireEditingCanceled(); 76 } 77 78 82 public void addCellEditorListener(CellEditorListener l) { 83 listenerList.add(CellEditorListener.class, l); 84 } 85 86 90 public void removeCellEditorListener(CellEditorListener l) { 91 listenerList.remove(CellEditorListener.class, l); 92 } 93 94 102 public CellEditorListener[] getCellEditorListeners() { 103 return (CellEditorListener[])listenerList.getListeners( 104 CellEditorListener.class); 105 } 106 107 114 protected void fireEditingStopped() { 115 Object [] listeners = listenerList.getListenerList(); 117 for (int i = listeners.length-2; i>=0; i-=2) { 120 if (listeners[i]==CellEditorListener.class) { 121 if (changeEvent == null) 123 changeEvent = new ChangeEvent(this); 124 ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent); 125 } 126 } 127 } 128 129 136 protected void fireEditingCanceled() { 137 Object [] listeners = listenerList.getListenerList(); 139 for (int i = listeners.length-2; i>=0; i-=2) { 142 if (listeners[i]==CellEditorListener.class) { 143 if (changeEvent == null) 145 changeEvent = new ChangeEvent(this); 146 ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent); 147 } 148 } 149 } 150 } 151 | Popular Tags |