public class UndoManager extends CompoundEdit implements UndoableEditListener
UndoManager管理
UndoableEdits列表,提供一种方式来撤消或恢复适当的编辑。有两种方法来添加一个
UndoManager编辑。添加编辑直接使用
addEdit方法,或添加
UndoManager到支持
UndoableEditListener豆。下面的示例创建一个
UndoManager并把它作为一个
UndoableEditListener到
JTextField:
undomanager undomanager =新undomanager();JTextField TF =…;TF。getdocument() addundoableeditlistener(undomanager);
UndoManager保持有序列表,列表编辑在编辑下的指数。第二编辑指数是当前列表的大小修改,或者如果undo已被调用,它对应于指数的最后一次重大的修改,松开了。当undo调用所有的编辑从下个指标编辑的最后一次重大的编辑被撤消,以相反的顺序。例如,考虑一个UndoManager由以下编辑:一 B C D。编辑与大胆的大写字母都是显著的,在低的情况下,斜体是微不足道的。
|
| Figure 1 |
如figure 1,如果D只是说,下次将4指标编辑。调用undo结果调用undo在D和设置下一个索引编辑3(编辑C),如下图所示。
|
| Figure 2 |
最后一个重要的编辑一,以便调用undo undo再次调用C,B,和一,按照这个顺序,设置下一个索引编辑0,如下图。
|
| Figure 3 |
调用redo结果调用redo所有编辑下的指数之间的编辑和下一个重要的编辑(或列表的末尾)。继续前面的例子,如果redo被调用,redo会被调用一,B和C。此外,未来编辑索引设置为3(如图所示figure 2)。
添加一个编辑一个UndoManager结果中删除所有的编辑从下一个索引编辑列表的结束。继续前面的例子,如果一个新的编辑,添加编辑D从列表中移除(后die调用它)。如果不是被下一个编辑(c.addEdit(e)返回true),或取代它(e.replaceEdit(c)返回true),新编辑后加入C,如下图。
|
| Figure 4 |
一旦end一直在UndoManager父类的行为是用于所有UndoableEdit调用的方法。参考CompoundEdit对其行为的更多细节。
不像其他的摆动,这个类是线程安全的。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans包。请看XMLEncoder。
editsRedoName, UndoName| Constructor and Description |
|---|
UndoManager()
创建一个新的
UndoManager。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdit(UndoableEdit anEdit)
增加了一个
UndoableEdit这
UndoManager,如果可能的话。
|
boolean |
canRedo()
返回true如果可以重新编辑。
|
boolean |
canUndo()
如果编辑可能撤消,则返回真。
|
boolean |
canUndoOrRedo()
如果这是可能的
undo或
redo调用返回true。
|
void |
discardAllEdits()
清空撤消经理发送每个编辑
die消息的过程中。
|
protected UndoableEdit |
editToBeRedone()
返回下一个重要的编辑要重做如果
redo调用。
|
protected UndoableEdit |
editToBeUndone()
返回下一个重要的编辑是如果
undo调用撤消。
|
void |
end()
原来这
UndoManager为正常
CompoundEdit。
|
int |
getLimit()
返回的最大数量的编辑本
UndoManager持有。
|
String |
getRedoPresentationName()
返回一个描述这个redoable形式编辑。
|
String |
getUndoOrRedoPresentationName()
方便的方法,返回
getUndoPresentationName或
getRedoPresentationName。
|
String |
getUndoPresentationName()
返回一个描述这种可撤销的形式编辑。
|
void |
redo()
重新做适当的修改。
|
protected void |
redoTo(UndoableEdit edit)
重做所有的变化从下个指标编辑
edit,更新下适当指标编辑。
|
void |
setLimit(int l)
设置最大数量的编辑本
UndoManager持有。
|
String |
toString()
返回显示并标识该对象属性的字符串。
|
protected void |
trimEdits(int from, int to)
移除指定范围内的编辑。
|
protected void |
trimForLimit()
将队列编辑的数量减少到一个大小限制范围,集中在下一个编辑的索引上。
|
void |
undo()
撤销相应的编辑。
|
void |
undoableEditHappened(UndoableEditEvent e)
一个
UndoableEditListener方法。
|
void |
undoOrRedo()
方便的方法,调用一
undo或
redo。
|
protected void |
undoTo(UndoableEdit edit)
撤消所有的变化,从下一个索引编辑
edit,更新下适当指标编辑。
|
die, getPresentationName, isInProgress, isSignificant, lastEditreplaceEditpublic int getLimit()
UndoManager持有。小于0的值表示编辑的数量不限于。
UndoManager持有
addEdit(javax.swing.undo.UndoableEdit),
setLimit(int)
public void discardAllEdits()
die消息的过程中。
protected void trimForLimit()
protected void trimEdits(int from,
int to)
die调用他们,从列表中删除编辑。这有没有影响,如果
from >
to。
from -取消最低指数
to -最大索引删除
public void setLimit(int l)
UndoManager持有。小于0的值表示编辑的数量不限于。如果编辑需要丢弃的收缩极限,
die将调用他们的相反的顺序,他们补充说。默认为100。
l -新的限制
RuntimeException -如果这
UndoManager不是在进步(
end已被调用)
CompoundEdit.isInProgress(),
end(),
addEdit(javax.swing.undo.UndoableEdit),
getLimit()
protected UndoableEdit editToBeUndone()
undo调用撤消。这还
null如果没有编辑被撤消。
protected UndoableEdit editToBeRedone()
redo调用。这还
null如果没有编辑要重做。
protected void undoTo(UndoableEdit edit) throws CannotUndoException
edit,更新下适当指标编辑。
CannotUndoException -如果一个编辑把
CannotUndoException
protected void redoTo(UndoableEdit edit) throws CannotRedoException
edit,更新下适当指标编辑。
CannotRedoException -如果一个编辑把
CannotRedoException
public void undoOrRedo()
throws CannotRedoException,
CannotUndoException
undo或
redo。如果任何编辑已撤消(下编辑索引小于编辑列表)的长度
redo这个调用,否则调用
undo。
CannotUndoException -如果一个编辑把
CannotUndoException
CannotRedoException -如果一个编辑把
CannotRedoException
canUndoOrRedo(),
getUndoOrRedoPresentationName()
public boolean canUndoOrRedo()
undo或
redo调用返回true。
canUndoOrRedo是有效的
undoOrRedo()
public void undo()
throws CannotUndoException
end已被调用,这需要通过调用父类的,否则这
undo所有编辑下的指数之间的编辑和最后一个重要的编辑、更新下适当指标编辑。
undo 接口
UndoableEdit
undo 方法重写,继承类
CompoundEdit
CannotUndoException -如果一个编辑把
CannotUndoException或没有被撤消编辑
CompoundEdit.end(),
canUndo(),
editToBeUndone()
public boolean canUndo()
end被调用时,返回值超。如果有任何编辑做否则返回true(
editToBeUndone返回非
null)。
canUndo 接口
UndoableEdit
canUndo 方法重写,继承类
CompoundEdit
CompoundEdit.canUndo(),
editToBeUndone()
public void redo()
throws CannotRedoException
end已被调用,这需要通过对父类。否则,这个调用的
redo所有编辑下的指数之间的编辑和下一个重要的编辑、更新下适当指标编辑。
redo 接口
UndoableEdit
redo 方法重写,继承类
CompoundEdit
CannotRedoException -如果一个编辑把
CannotRedoException或没有编辑要重做
CompoundEdit.end(),
canRedo(),
editToBeRedone()
public boolean canRedo()
end被调用时,返回值超。否则,返回true如果有任何修改必须重做(
editToBeRedone返回非
null)。
canRedo 接口
UndoableEdit
canRedo 方法重写,继承类
CompoundEdit
CompoundEdit.canRedo(),
editToBeRedone()
public boolean addEdit(UndoableEdit anEdit)
UndoableEdit这
UndoManager,如果可能的话。这将从下一个编辑的索引中移除所有的编辑到编辑列表的结尾。如果
end已调用编辑不加
false返回。如果
end没有调用返回
true。
addEdit 接口
UndoableEdit
addEdit 方法重写,继承类
CompoundEdit
anEdit -编辑要添加
anEdit可以纳入本编辑
CompoundEdit.end(),
CompoundEdit.addEdit(javax.swing.undo.UndoableEdit)
public void end()
UndoManager为正常
CompoundEdit。此移除已撤消的所有编辑。
end 方法重写,继承类
CompoundEdit
CompoundEdit.end()
public String getUndoOrRedoPresentationName()
getUndoPresentationName或
getRedoPresentationName。如果下一个编辑与编辑列表的大小的指标,
getUndoPresentationName返回,否则返回
getRedoPresentationName。
public String getUndoPresentationName()
end已被调用,这称为超级。否则,如果有编辑被撤消,这将返回从下一个将撤消的重大编辑的值。如果没有编辑被撤消,
end尚未调用的返回值从
UIManager财产”abstractundoableedit。undotext”。
getUndoPresentationName 接口
UndoableEdit
getUndoPresentationName 方法重写,继承类
CompoundEdit
undo(),
CompoundEdit.getUndoPresentationName()
public String getRedoPresentationName()
end已被调用,这称为超级。否则,如果有编辑要重做,这个返回值的下一个重要的编辑将重做。如果没有编辑的返工和
end尚未调用的返回值从
UIManager财产”abstractundoableedit。redotext”。
getRedoPresentationName 接口
UndoableEdit
getRedoPresentationName 方法重写,继承类
CompoundEdit
redo(),
CompoundEdit.getRedoPresentationName()
public void undoableEditHappened(UndoableEditEvent e)
UndoableEditListener方法。这个调用的
addEdit与
e.getEdit()。
undoableEditHappened 接口
UndoableEditListener
e -
UndoableEditEvent的
UndoableEditEvent将增加
addEdit(javax.swing.undo.UndoableEdit)
public String toString()
toString 方法重写,继承类
CompoundEdit
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.