1. /*
  2. * @(#)UndoableEdit.java 1.19 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.undo;
  8. import javax.swing.event.*;
  9. /**
  10. * An object representing an edit that has been done, and that can be
  11. * undone and redone.
  12. *
  13. * @version 1.19, 12/19/03
  14. * @author Ray Ryan
  15. */
  16. public interface UndoableEdit {
  17. /**
  18. * Undo the edit that was made.
  19. */
  20. public void undo() throws CannotUndoException;
  21. /**
  22. * True if it is still possible to undo this operation.
  23. */
  24. public boolean canUndo();
  25. /**
  26. * Re-apply the edit, assuming that it has been undone.
  27. */
  28. public void redo() throws CannotRedoException;
  29. /**
  30. * True if it is still possible to redo this operation.
  31. */
  32. public boolean canRedo();
  33. /**
  34. * May be sent to inform an edit that it should no longer be
  35. * used. This is a useful hook for cleaning up state no longer
  36. * needed once undoing or redoing is impossible--for example,
  37. * deleting file resources used by objects that can no longer be
  38. * undeleted. <code>UndoManager</code> calls this before it dequeues edits.
  39. *
  40. * Note that this is a one-way operation. There is no "un-die"
  41. * method.
  42. *
  43. * @see CompoundEdit#die
  44. */
  45. public void die();
  46. /**
  47. * This <code>UndoableEdit</code> should absorb <code>anEdit</code>
  48. * if it can. Returns true
  49. * if <code.anEdit</code> has been incorporated, false if it has not.
  50. *
  51. * <p>Typically the receiver is already in the queue of a
  52. * <code>UndoManager</code> (or other <code>UndoableEditListener</code>),
  53. * and is being given a chance to incorporate <code>anEdit</code>
  54. * rather than letting it be added to the queue in turn.</p>
  55. *
  56. * <p>If true is returned, from now on <code>anEdit</code> must return
  57. * false from <code>canUndo</code> and <code>canRedo</code>,
  58. * and must throw the appropriate exception on <code>undo</code> or
  59. * <code>redo</code>.</p>
  60. * @param anEdit the edit to be added
  61. */
  62. public boolean addEdit(UndoableEdit anEdit);
  63. /**
  64. * Returns true if this <code>UndoableEdit</code> should replace
  65. * <code>anEdit</code>. The receiver should incorporate
  66. * <code>anEdit</code>'s state before returning true.
  67. *
  68. * <p>This message is the opposite of addEdit--anEdit has typically
  69. * already been queued in a <code>UndoManager</code> (or other
  70. * UndoableEditListener), and the receiver is being given a chance
  71. * to take its place.</p>
  72. *
  73. * <p>If true is returned, from now on anEdit must return false from
  74. * canUndo() and canRedo(), and must throw the appropriate
  75. * exception on undo() or redo().</p>
  76. */
  77. public boolean replaceEdit(UndoableEdit anEdit);
  78. /**
  79. * Returns false if this edit is insignificant--for example one
  80. * that maintains the user's selection, but does not change any
  81. * model state. This status can be used by an
  82. * <code>UndoableEditListener</code>
  83. * (like UndoManager) when deciding which UndoableEdits to present
  84. * to the user as Undo/Redo options, and which to perform as side
  85. * effects of undoing or redoing other events.
  86. */
  87. public boolean isSignificant();
  88. /**
  89. * Provides a localized, human readable description of this edit
  90. * suitable for use in, say, a change log.
  91. */
  92. public String getPresentationName();
  93. /**
  94. * Provides a localized, human readable description of the undoable
  95. * form of this edit, e.g. for use as an Undo menu item. Typically
  96. * derived from <code>getDescription</code>.
  97. */
  98. public String getUndoPresentationName();
  99. /**
  100. * Provides a localized, human readable description of the redoable
  101. * form of this edit, e.g. for use as a Redo menu item. Typically
  102. * derived from <code>getPresentationName</code>.
  103. */
  104. public String getRedoPresentationName();
  105. }