1. /*
  2. * @(#)CellEditor.java 1.17 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.util.EventObject;
  9. import javax.swing.event.*;
  10. /**
  11. * This interface defines the methods any general editor should be able
  12. * to implement. <p>
  13. *
  14. * Having this interface enables complex components (the client of the
  15. * editor) such as JList, JTree, and JTable to allow any generic editor to
  16. * edit values in a table cell, or tree cell, etc. Without this generic
  17. * editor interface, JTable would have to know about specific editors,
  18. * such as JTextField, JCheckBox, JComboBox, etc. In addition, without
  19. * this interface, clients of editors such as JTable would not be able
  20. * to work with any editors developed in the future by the user
  21. * or a 3rd party ISV. <p>
  22. *
  23. * To use this interface, a developer creating a new editor can have the
  24. * new component implement the interface. Or the developer can
  25. * choose a wrapper based approch and provide a companion object which
  26. * implements the CellEditor interface (See JCellEditor for example). The
  27. * wrapper approch is particularly useful if the user want to use a
  28. * 3rd party ISV editor with JTable, but the ISV didn't implement the
  29. * CellEditor interface. The user can simply create an object that
  30. * contains an instance of the 3rd party editor object and "translate"
  31. * the CellEditor API into the 3rd party editor's API.
  32. *
  33. * @see javax.swing.event.CellEditorListener
  34. *
  35. * @version 1.17 11/29/01
  36. * @author Alan Chung
  37. */
  38. public interface CellEditor {
  39. /** Returns the value contained in the editor**/
  40. public Object getCellEditorValue();
  41. /**
  42. * Ask the editor if it can start editing using <I>anEvent</I>.
  43. * <I>anEvent</I> is in the invoking component coordinate system.
  44. * The editor can not assume the Component returned by
  45. * getCellEditorComponent() is installed. This method is intended
  46. * for the use of client to avoid the cost of setting up and installing
  47. * the editor component if editing is not possible.
  48. * If editing can be started this method returns true.
  49. *
  50. * @param anEvent the event the editor should use to consider
  51. * whether to begin editing or not.
  52. * @return true if editing can be started.
  53. * @see #shouldSelectCell
  54. */
  55. public boolean isCellEditable(EventObject anEvent);
  56. /**
  57. * Tell the editor to start editing using <I>anEvent</I>. It is
  58. * up to the editor if it want to start editing in different states
  59. * depending on the exact type of <I>anEvent</I>. For example, with
  60. * a text field editor, if the event is a mouse event the editor
  61. * might start editing with the cursor at the clicked point. If
  62. * the event is a keyboard event, it might want replace the value
  63. * of the text field with that first key, etc. <I>anEvent</I>
  64. * is in the invoking component's coordinate system. A null value
  65. * is a valid parameter for <I>anEvent</I>, and it is up to the editor
  66. * to determine what is the default starting state. For example,
  67. * a text field editor might want to select all the text and start
  68. * editing if <I>anEvent</I> is null. The editor can assume
  69. * the Component returned by getCellEditorComponent() is properly
  70. * installed in the clients Component hierarchy before this method is
  71. * called. <p>
  72. *
  73. * The return value of shouldSelectCell() is a boolean indicating whether
  74. * the editing cell should be selected or not. Typically, the return
  75. * value is true, because is most cases the editing cell should be
  76. * selected. However, it is useful to return false to keep the selection
  77. * from changing for some types of edits. eg. A table that contains
  78. * a column of check boxes, the user might want to be able to change
  79. * those checkboxes without altering the selection. (See Netscape
  80. * Communicator for just such an example) Of course, it is up to
  81. * the client of the editor to use the return value, but it doesn't
  82. * need to if it doesn't want to.
  83. *
  84. * @param anEvent the event the editor should use to start
  85. * editing.
  86. * @return true if the editor would like the editing cell to be selected
  87. * @see #isCellEditable
  88. */
  89. public boolean shouldSelectCell(EventObject anEvent);
  90. /**
  91. * Tell the editor to stop editing and accept any partially edited
  92. * value as the value of the editor. The editor returns false if
  93. * editing was not stopped, useful for editors which validates and
  94. * can not accept invalid entries.
  95. *
  96. * @return true if editing was stopped
  97. */
  98. public boolean stopCellEditing();
  99. /**
  100. * Tell the editor to cancel editing and not accept any partially
  101. * edited value.
  102. */
  103. public void cancelCellEditing();
  104. /**
  105. * Add a listener to the list that's notified when the editor starts,
  106. * stops, or cancels editing.
  107. *
  108. * @param l the CellEditorListener
  109. */
  110. public void addCellEditorListener(CellEditorListener l);
  111. /**
  112. * Remove a listener from the list that's notified
  113. *
  114. * @param l the CellEditorListener
  115. */
  116. public void removeCellEditorListener(CellEditorListener l);
  117. }