1. /*
  2. * @(#)UndoableEdit.java 1.13 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.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.13, 11/29/01
  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. UndoManager calls this before it dequeues edits.
  39. *
  40. * Note that this is a one-way operation. There is no "undie"
  41. * method.
  42. *
  43. * @see CompoundEdit#die
  44. */
  45. public void die();
  46. /**
  47. * This UndoableEdit should absorb anEdit if it can. Return true
  48. * if anEdit has been incoporated, false if it has not.
  49. *
  50. * <p>Typically the receiver is already in the queue of a
  51. * UndoManager (or other UndoableEditListener), and is being
  52. * given a chance to incorporate anEdit rather than letting it be
  53. * added to the queue in turn.</p>
  54. *
  55. * <p>If true is returned, from now on anEdit must return false from
  56. * canUndo() and canRedo(), and must throw the appropriate
  57. * exception on undo() or redo().</p>
  58. */
  59. public boolean addEdit(UndoableEdit anEdit);
  60. /**
  61. * Return true if this UndoableEdit should replace anEdit. The
  62. * receiver should incorporate anEdit's state before returning true.
  63. *
  64. * <p>This message is the opposite of addEdit--anEdit has typically
  65. * already been queued in a UndoManager (or other
  66. * UndoableEditListener), and the receiver is being given a chance
  67. * to take its place.</p>
  68. *
  69. * <p>If true is returned, from now on anEdit must return false from
  70. * canUndo() and canRedo(), and must throw the appropriate
  71. * exception on undo() or redo().</p>
  72. */
  73. public boolean replaceEdit(UndoableEdit anEdit);
  74. /**
  75. * Return false if this edit is insignificant--for example one
  76. * that maintains the user's selection, but does not change any
  77. * model state. This status can be used by an UndoableEditListener
  78. * (like UndoManager) when deciding which UndoableEdits to present
  79. * to the user as Undo/Redo options, and which to perform as side
  80. * effects of undoing or redoing other events.
  81. */
  82. public boolean isSignificant();
  83. /**
  84. * Provide a localized, human readable description of this edit
  85. * suitable for use in, say, a change log.
  86. */
  87. public String getPresentationName();
  88. /**
  89. * Provide a localized, human readable description of the undoable
  90. * form of this edit, e.g. for use as an Undo menu item. Typically
  91. * derived from getDescription();
  92. */
  93. public String getUndoPresentationName();
  94. /**
  95. * Provide a localized, human readable description of the redoable
  96. * form of this edit, e.g. for use as a Redo menu item. Typically
  97. * derived from getPresentationName();
  98. */
  99. public String getRedoPresentationName();
  100. }