[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Project.java,1.48,1.49
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-03-21 22:00:30
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31312/src/net/sourceforge/bprocessor/model Modified Files: Project.java Log Message: Implemented a simple Undo/Redo mechanism that remembers the entire model state for each operation Ð this may be too slow with larger models (and require large amounts of memory). The history is cleared when saving the model. Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** Project.java 21 Mar 2006 15:10:22 -0000 1.48 --- Project.java 21 Mar 2006 21:59:59 -0000 1.49 *************** *** 71,80 **** private Space activeSpace; - /** Previous state */ - private Bprocessor previousState; - - /** Current state */ - private Bprocessor currentState; - /** The undo stack */ private Stack undoStack; --- 71,74 ---- *************** *** 83,86 **** --- 77,83 ---- private Stack redoStack; + /** The current state */ + private Bprocessor currentState; + /** * Get the instance *************** *** 649,653 **** */ public void checkpoint() { ! previousState = currentState; currentState = PersistenceManager.externalize(); } --- 646,655 ---- */ public void checkpoint() { ! redoStack.clear(); ! if (currentState != null) { ! log.info("pushing state on undo-stack"); ! undoStack.push(currentState); ! } ! log.info("externalizing current-state"); currentState = PersistenceManager.externalize(); } *************** *** 658,662 **** */ public boolean canUndo() { ! return false; } --- 660,664 ---- */ public boolean canUndo() { ! return (!undoStack.isEmpty()); } *************** *** 666,670 **** */ public boolean canRedo() { ! return false; } --- 668,712 ---- */ public boolean canRedo() { ! return (!redoStack.isEmpty()); ! } ! ! /** ! * Undo ! */ ! public void undo() { ! if (canUndo()) { ! if (currentState != null) { ! log.info("pushing state on redo-stack"); ! redoStack.push(currentState); ! } ! log.info("popping state from undo-stack"); ! currentState = (Bprocessor) undoStack.pop(); ! clear(); ! PersistenceManager.internalize(currentState); ! } ! } ! ! /** ! * Redo ! */ ! public void redo() { ! if (canRedo()) { ! if (currentState != null) { ! log.info("pushing state on undo-stack"); ! undoStack.push(currentState); ! } ! log.info("popping state from redo-stack"); ! currentState = (Bprocessor) redoStack.pop(); ! clear(); ! PersistenceManager.internalize(currentState); ! } ! } ! ! /** ! * Reset undo/redo history ! */ ! public void resetHistory() { ! undoStack.clear(); ! redoStack.clear(); } *************** *** 675,685 **** */ public void revert() { ! if (previousState != null) { ! Bprocessor temporary = previousState; ! clear(); ! PersistenceManager.internalize(previousState); ! previousState = currentState; ! currentState = temporary; ! } } --- 717,721 ---- */ public void revert() { ! undo(); } *************** *** 692,695 **** --- 728,733 ---- PersistenceManager.save(file); makeClean(); + resetHistory(); + checkpoint(); setSavePath(file.getCanonicalPath()); setDefaultPath(file.getParent()); *************** *** 703,706 **** --- 741,746 ---- PersistenceManager.save(new File(getSavePath())); makeClean(); + resetHistory(); + checkpoint(); } *************** *** 715,718 **** --- 755,760 ---- PersistenceManager.load(file); makeClean(); + resetHistory(); + checkpoint(); setSavePath(file.getCanonicalPath()); setDefaultPath(file.getParent()); *************** *** 726,729 **** --- 768,772 ---- clear(); makeClean(); + resetHistory(); setSavePath(null); } |