问题描述
我的任务是为应用程序添加撤消/重做/重复功能。我正在调查是否可以使用Swing的UndoManager。
I've been tasked with adding undo/redo/repeat functionality to an application. I'm currently investigating whether I can use Swing's UndoManager.
除了通常的撤销和重做按钮之外,我还需要提供一次撤消或重做多个编辑的功能(像MS Office一样下拉UI),并重复选择的编辑。
Apart from the usual undo and redo buttons, I need to provide the ability to undo or redo multiple edits at once (drop down UI like MS Office), and repeat a chosen edit.
我相信我可以使用UndoManager进行多次撤消和重做。它提供了多次撤消和重做的方法。为了构建UI,我可以扩展UndoManager以显示它所持有的编辑。
I believe I can use UndoManager for multiple undo and redo. It provides methods for multiple undo and redo. To build the UI, I can extend UndoManager to expose the edits it holds.
我不确定我是否可以使用UndoManager来重复选择操作。我的第一个想法是扩展UndoManager并添加重复(编辑)方法。此方法将克隆或复制编辑,重做副本,然后将副本放在撤消堆栈的顶部。编辑只有在实现Clonable时才可重复。
I'm not sure I can use UndoManager for repeat chosen operation however. My first thoughts were to extend UndoManager and add a repeat(edit) method. This method would clone or copy an edit, redo the copy, and then place the copy on top of the undo stack. An edit would only be repeatable if it implemented Clonable.
这看起来合情合理吗?有更好的解决方案吗?我应该自己滚动而不是UndoManager吗?提前致谢。
Does this seem reasonable? Are there better solutions? Should I be rolling my own instead of UndoManager? Thanks in advance.
推荐答案
希望这有助于
这篇关于扩展Swing的UndoManager以提供重复和多次撤消/重做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!