semi-sleep

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  17 Posts :: 0 Stories :: 1 Comments :: 0 Trackbacks

/* UndoableEdit and AbstractUndoableEdit */

AbstractUndoableEdit edit = new AbstractUndoableEdit();

 

// methods fall into 3 categories

 

// 1.undoable operations

// if the alive field is false, all operation fail

// the hasBeenDone field affect the behaviours of canUndo and canRedo method

if (edit.canUndo()) {

       edit.undo(); // the behaviour depends on canUndo

}

 

if (edit.canRedo()) {

       edit.redo(); // the behaviour depends on canRedo

}

 

edit.die(); // set alive to be false

 

// 2.edit management

edit.isSignificant(); // if the edit affect model state, default implementation return false

edit.addEdit(null); // edit queued in some UndoableEditListener, and try to absorb another edit

edit.replaceEdit(null); // try to replace another edit queued in some UndoableEditListener

 

// 3.representation

edit.getPresentationName();

 

// the following 2 methods use result of getPresentationName and add undo/redo text in UIManager

edit.getUndoPresentationName();

edit.getRedoPresentationName();

 

/* CompoundEdit */

// implements the composition pattern, manages a set of edits

CompoundEdit compound = new CompoundEdit();

 

// undoable operations (except die) fail if inProgress is true

// edit management methods (except isSignificant) fail if inProgress is false

compound.isInProgress();

compound.end(); // set inProgress to be false

 

// representation methods try to use information of the last edit

 

/* UndoManager */

UndoManager manager = new UndoManager();

 

// extends undoable operations when inProgress is true

// undo/redo now stop at the latest significant edit

// limit the maximal number of edits

manager.setLimit(0);

manager.getLimit();

manager.discardAllEdits(); // clear all edits

 

// extends representation methods when inProgress is true

// undo/redo methods try to use information of the latest edit to be undo/redo

 

// add undoOrRedo methods

if (manager.canUndoOrRedo()) {

       manager.undoOrRedo();

}

 

manager.getUndoOrRedoPresentationName();

 

/* StateEditable */

// stateful object should be able to store and restore its state

StateEditable stateEditable = new StateEditable() {

       public void restoreState(Hashtable<?, ?> state) {}

       public void storeState(Hashtable<Object, Object> state) {}

};

 

/* StateEdit */

// extends AbstractUndoableEdit to add the ability to use StateEditable

// store pre-state

StateEdit stateEdit = new StateEdit(stateEditable);

 

// store post-state

stateEdit.end();

 

// restore the state of stateEditable

stateEdit.undo();

stateEdit.redo();

 

/* UndoableEditSupport */

UndoableEditSupport support = new UndoableEditSupport(new Object());

 

// methods fall into 2 categories

// 1.manage a set of UndoableEditListener

support.addUndoableEditListener(null);

support.removeUndoableEditListener(null);

support.getUndoableEditListeners();

 

// 2.send UndoableEditEvent

// if updateLevel is 0, all UndoableEditEvent would be sent immediately

// else UndoableEdit will be saved in CompoundUndoableEdit and wait util updateLevel change to 0

support.beginUpdate(); // increase updateLevel

// send UndoableEditEvent if updateLevel is 0 or save edit in CompoundUndoableEdit

support.postEdit(null);

support.endUpdate(); // decrease unpdateLeve and send UndoableEditEvent if necessary

posted on 2006-12-14 18:36 semi-sleep 阅读(510) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: