KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > undo > UndoableEdit


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
8 package javax.swing.undo;
9
10 import javax.swing.event.*;
11
12 /**
13  * An object representing an edit that has been done, and that can be
14  * undone and redone.
15  *
16  * @version 1.19, 12/19/03
17  * @author Ray Ryan
18  */

19
20 public interface UndoableEdit {
21     /**
22      * Undo the edit that was made.
23      */

24     public void undo() throws CannotUndoException JavaDoc;
25
26     /**
27      * True if it is still possible to undo this operation.
28      */

29     public boolean canUndo();
30
31     /**
32      * Re-apply the edit, assuming that it has been undone.
33      */

34     public void redo() throws CannotRedoException JavaDoc;
35
36     /**
37      * True if it is still possible to redo this operation.
38      */

39     public boolean canRedo();
40
41     /**
42      * May be sent to inform an edit that it should no longer be
43      * used. This is a useful hook for cleaning up state no longer
44      * needed once undoing or redoing is impossible--for example,
45      * deleting file resources used by objects that can no longer be
46      * undeleted. <code>UndoManager</code> calls this before it dequeues edits.
47      *
48      * Note that this is a one-way operation. There is no "un-die"
49      * method.
50      *
51      * @see CompoundEdit#die
52      */

53     public void die();
54
55     /**
56      * This <code>UndoableEdit</code> should absorb <code>anEdit</code>
57      * if it can. Returns true
58      * if <code.anEdit</code> has been incorporated, false if it has not.
59      *
60      * <p>Typically the receiver is already in the queue of a
61      * <code>UndoManager</code> (or other <code>UndoableEditListener</code>),
62      * and is being given a chance to incorporate <code>anEdit</code>
63      * rather than letting it be added to the queue in turn.</p>
64      *
65      * <p>If true is returned, from now on <code>anEdit</code> must return
66      * false from <code>canUndo</code> and <code>canRedo</code>,
67      * and must throw the appropriate exception on <code>undo</code> or
68      * <code>redo</code>.</p>
69      * @param anEdit the edit to be added
70      */

71     public boolean addEdit(UndoableEdit JavaDoc anEdit);
72
73     /**
74      * Returns true if this <code>UndoableEdit</code> should replace
75      * <code>anEdit</code>. The receiver should incorporate
76      * <code>anEdit</code>'s state before returning true.
77      *
78      * <p>This message is the opposite of addEdit--anEdit has typically
79      * already been queued in a <code>UndoManager</code> (or other
80      * UndoableEditListener), and the receiver is being given a chance
81      * to take its place.</p>
82      *
83      * <p>If true is returned, from now on anEdit must return false from
84      * canUndo() and canRedo(), and must throw the appropriate
85      * exception on undo() or redo().</p>
86      */

87     public boolean replaceEdit(UndoableEdit JavaDoc anEdit);
88
89     /**
90      * Returns false if this edit is insignificant--for example one
91      * that maintains the user's selection, but does not change any
92      * model state. This status can be used by an
93      * <code>UndoableEditListener</code>
94      * (like UndoManager) when deciding which UndoableEdits to present
95      * to the user as Undo/Redo options, and which to perform as side
96      * effects of undoing or redoing other events.
97      */

98     public boolean isSignificant();
99
100     /**
101      * Provides a localized, human readable description of this edit
102      * suitable for use in, say, a change log.
103      */

104     public String JavaDoc getPresentationName();
105
106     /**
107      * Provides a localized, human readable description of the undoable
108      * form of this edit, e.g. for use as an Undo menu item. Typically
109      * derived from <code>getDescription</code>.
110      */

111     public String JavaDoc getUndoPresentationName();
112
113     /**
114      * Provides a localized, human readable description of the redoable
115      * form of this edit, e.g. for use as a Redo menu item. Typically
116      * derived from <code>getPresentationName</code>.
117      */

118     public String JavaDoc getRedoPresentationName();
119 }
120
Popular Tags