1. /*
  2. * @(#)AbstractCellEditor.java 1.4 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing;
  11. import javax.swing.event.*;
  12. import java.util.EventObject;
  13. import java.io.Serializable;
  14. /**
  15. * @version 1.4 02/02/00
  16. *
  17. * A base class for <code>CellEditors</code>, providing default
  18. * implementations for the methods in the <code>CellEditor</code>
  19. * interface except <code>getCellEditorValue()</code>.
  20. * Like the other abstract implementations in Swing, also manages a list
  21. * of listeners.
  22. *
  23. * <p>
  24. * <strong>Warning:</strong>
  25. * Serialized objects of this class will not be compatible with
  26. * future Swing releases. The current serialization support is appropriate
  27. * for short term storage or RMI between applications running the same
  28. * version of Swing. A future release of Swing will provide support for
  29. * long term persistence.
  30. *
  31. * @author Philip Milne
  32. */
  33. public abstract class AbstractCellEditor implements CellEditor, Serializable {
  34. protected EventListenerList listenerList = new EventListenerList();
  35. transient protected ChangeEvent changeEvent = null;
  36. // Force this to be implemented.
  37. // public Object getCellEditorValue()
  38. /**
  39. * Returns true.
  40. * @param e an event object
  41. * @return true
  42. */
  43. public boolean isCellEditable(EventObject e) {
  44. return true;
  45. }
  46. /**
  47. * Returns true.
  48. * @param e an event object
  49. * @return true
  50. */
  51. public boolean shouldSelectCell(EventObject anEvent) {
  52. return true;
  53. }
  54. /**
  55. * Calls <code>fireEditingStopped</code> and returns true.
  56. * @return true
  57. */
  58. public boolean stopCellEditing() {
  59. fireEditingStopped();
  60. return true;
  61. }
  62. /**
  63. * Calls <code>fireEditingCanceled</code>.
  64. */
  65. public void cancelCellEditing() {
  66. fireEditingCanceled();
  67. }
  68. /**
  69. * Adds a <code>CellEditorListener</code> to the listener list.
  70. * @param l the new listener to be added
  71. */
  72. public void addCellEditorListener(CellEditorListener l) {
  73. listenerList.add(CellEditorListener.class, l);
  74. }
  75. /**
  76. * Removes a <code>CellEditorListener</code> from the listener list.
  77. * @param l the listener to be removed
  78. */
  79. public void removeCellEditorListener(CellEditorListener l) {
  80. listenerList.remove(CellEditorListener.class, l);
  81. }
  82. /*
  83. * Notifies all listeners that have registered interest for
  84. * notification on this event type. The event instance
  85. * is lazily created using the parameters passed into
  86. * the fire method.
  87. * @see EventListenerList
  88. */
  89. protected void fireEditingStopped() {
  90. // Guaranteed to return a non-null array
  91. Object[] listeners = listenerList.getListenerList();
  92. // Process the listeners last to first, notifying
  93. // those that are interested in this event
  94. for (int i = listeners.length-2; i>=0; i-=2) {
  95. if (listeners[i]==CellEditorListener.class) {
  96. // Lazily create the event:
  97. if (changeEvent == null)
  98. changeEvent = new ChangeEvent(this);
  99. ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
  100. }
  101. }
  102. }
  103. /*
  104. * Notifies all listeners that have registered interest for
  105. * notification on this event type. The event instance
  106. * is lazily created using the parameters passed into
  107. * the fire method.
  108. * @see EventListenerList
  109. */
  110. protected void fireEditingCanceled() {
  111. // Guaranteed to return a non-null array
  112. Object[] listeners = listenerList.getListenerList();
  113. // Process the listeners last to first, notifying
  114. // those that are interested in this event
  115. for (int i = listeners.length-2; i>=0; i-=2) {
  116. if (listeners[i]==CellEditorListener.class) {
  117. // Lazily create the event:
  118. if (changeEvent == null)
  119. changeEvent = new ChangeEvent(this);
  120. ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
  121. }
  122. }
  123. }
  124. }