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