本文整理汇总了Java中javax.swing.undo.UndoableEdit.undo方法的典型用法代码示例。如果您正苦于以下问题:Java UndoableEdit.undo方法的具体用法?Java UndoableEdit.undo怎么用?Java UndoableEdit.undo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.undo.UndoableEdit
的用法示例。
在下文中一共展示了UndoableEdit.undo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
public static void main(String[] args) {
final LinkedList<UndoableEdit> edits = new LinkedList<UndoableEdit>();
UndoableEditListener editListener = new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
System.out.println(e.getEdit());
edits.addFirst(e.getEdit());
}
};
UndoableList<Integer> list = new UndoableList<Integer>(new LinkedList<Integer>());
list.addUndoableEditListener(editListener);
for (int i = 1; i < 10; i++) {
list.add(2*i);
}
System.out.println(list);
list.add(6, 13);
System.out.println(list);
list.set(3, 7);
System.out.println(list);
List<Integer> subList = list.subList(3, 6);
System.out.println(subList);
subList.set(0, 8);
System.out.println(list);
System.out.println(subList);
subList.remove(1);
System.out.println("----------------------------------");
for (UndoableEdit edit : edits) {
System.out.println("Undo " + edit);
edit.undo();
System.out.println(list);
}
}
示例2: undo
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
public @Override void undo() throws CannotUndoException {
BaseDocument doc = (BaseDocument)getDocument();
inUndo = true;
// Super of undo()
doc.atomicLockImpl();
if (!doc.modifiable) {
throw new CannotUndoException();
}
try {
doc.incrementDocVersion();
if (!canUndo()) {
throw new CannotUndoException();
}
hasBeenDone2 = false;
doc.lastModifyUndoEdit = null; // #8692 check last modify undo edit
if (debugUndo) {
/*DEBUG*/System.err.println("UNDO in doc=" + doc);
}
int i = edits.size(); // i should be > 0 since only non-empty edits are fired
while (--i >= 0) {
UndoableEdit e = (UndoableEdit)edits.elementAt(i);
e.undo();
}
// fire a DocumentEvent to notify the view(s)
if (getType() == DocumentEvent.EventType.REMOVE) {
doc.firePreInsertUpdate(this);
doc.fireInsertUpdate(this);
} else if (getType() == DocumentEvent.EventType.INSERT) {
doc.firePreRemoveUpdate(this);
doc.fireRemoveUpdate(this);
} else {
doc.fireChangedUpdate(this);
}
if (previous != null) {
previous.undo();
}
} finally {
doc.atomicUnlockImpl(false);
inUndo = false;
}
// End super of undo()
}