KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > undo > AbstractUndoableEdit


1 /*
2    SwingWT
3    Copyright(c)2003-2004 Daniel Naab
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: dannaab@users.sourceforge.net
9
10    $Log: AbstractUndoableEdit.java,v $
11    Revision 1.2 2004/04/16 22:45:50 dannaab
12    Add copyright msg
13
14 */

15
16 package swingwtx.swing.undo;
17
18 /**
19  * AbstractUndoableEdit
20  *
21  * @author Naab
22  * @version %I%, %G%
23  */

24 public class AbstractUndoableEdit implements UndoableEdit
25 {
26     /** Indicates whether or not this edit is still active and can be undone/redone */
27     private boolean alive = true;
28     /** Indicates if this edit has been completed. */
29     private boolean completed = true;
30
31     public AbstractUndoableEdit()
32     {
33         super();
34     }
35
36     public void undo() throws CannotUndoException
37     {
38         if (!canUndo())
39             throw new CannotUndoException();
40         completed = false;
41     }
42     public void redo() throws CannotRedoException
43     {
44         if (!canRedo())
45             throw new CannotRedoException();
46         completed = true;
47     }
48
49     /** Kill off the edit... can no longer undo */
50     public void die()
51     {
52         alive = false;
53     }
54
55     public boolean canUndo()
56     {
57         return completed && alive;
58     }
59
60     public boolean canRedo()
61     {
62         return !completed && alive;
63     }
64
65     protected static final String JavaDoc UndoName = "Undo";
66     protected static final String JavaDoc RedoName = "Redo";
67
68     public String JavaDoc getUndoPresentationName()
69     {
70         return UndoName;
71     }
72
73     public String JavaDoc getRedoPresentationName()
74     {
75         return RedoName;
76     }
77
78     /** Default implementations do nothing. Override in implementing classes */
79     public boolean addEdit(UndoableEdit anEdit) { return false; }
80     public boolean replaceEdit(UndoableEdit anEdit) { return false; }
81     public boolean isSignificant() { return false; }
82     public String JavaDoc getPresentationName() { return ""; }
83 }
84
Popular Tags