1 7 8 package javax.swing.undo; 9 10 import java.io.Serializable ; 11 import javax.swing.UIManager ; 12 13 21 public class AbstractUndoableEdit implements UndoableEdit , Serializable { 22 23 31 protected static final String UndoName = "Undo"; 32 33 41 protected static final String RedoName = "Redo"; 42 43 47 boolean hasBeenDone; 48 49 53 boolean alive; 54 55 59 public AbstractUndoableEdit() { 60 super(); 61 62 hasBeenDone = true; 63 alive = true; 64 } 65 66 76 public void die() { 77 alive = false; 78 } 79 80 91 public void undo() throws CannotUndoException { 92 if (!canUndo()) { 93 throw new CannotUndoException (); 94 } 95 hasBeenDone = false; 96 } 97 98 109 public boolean canUndo() { 110 return alive && hasBeenDone; 111 } 112 113 123 public void redo() throws CannotRedoException { 124 if (!canRedo()) { 125 throw new CannotRedoException (); 126 } 127 hasBeenDone = true; 128 } 129 130 140 public boolean canRedo() { 141 return alive && !hasBeenDone; 142 } 143 144 152 public boolean addEdit(UndoableEdit anEdit) { 153 return false; 154 } 155 156 164 public boolean replaceEdit(UndoableEdit anEdit) { 165 return false; 166 } 167 168 174 public boolean isSignificant() { 175 return true; 176 } 177 178 191 public String getPresentationName() { 192 return ""; 193 } 194 195 210 public String getUndoPresentationName() { 211 String name = getPresentationName(); 212 if (!"".equals(name)) { 213 name = UIManager.getString("AbstractUndoableEdit.undoText") + 214 " " + name; 215 } else { 216 name = UIManager.getString("AbstractUndoableEdit.undoText"); 217 } 218 219 return name; 220 } 221 222 237 public String getRedoPresentationName() { 238 String name = getPresentationName(); 239 if (!"".equals(name)) { 240 name = UIManager.getString("AbstractUndoableEdit.redoText") + 241 " " + name; 242 } else { 243 name = UIManager.getString("AbstractUndoableEdit.redoText"); 244 } 245 246 return name; 247 } 248 249 255 public String toString() 256 { 257 return super.toString() 258 + " hasBeenDone: " + hasBeenDone 259 + " alive: " + alive; 260 } 261 } 262 263 | Popular Tags |