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
。
edits
RedoName, 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, lastEdit
replaceEdit
public 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.