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