本文介绍了扩展 Swing's UndoManager 以提供重复和多次撤销/重做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是向应用程序添加撤消/重做/重复功能.我目前正在调查是否可以使用 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 并添加一个 repeat(edit) 方法.此方法将克隆或复制编辑,重做副本,然后将副本放在撤消堆栈的顶部.只有实现了可克隆的编辑才能重复.

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.

推荐答案

希望能帮到你http://java-sl.com/tip_merge_undo_edits.html

这篇关于扩展 Swing's UndoManager 以提供重复和多次撤销/重做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 07:06