TextWrapper I: Don't redo Undo/Redo!

Don't want to "redo" the undo/redo support in Swing text components? Tired of "redoing" the undo-redo wheel once more?

Redoing the undo-redo, once again?

Yes. I am tired of reinventing the undo-redo wheel. So I decided to build an easy to use wrapper that automatically provides undo-redo support for any text component.

Usage is extremely simple:

import net.antonioshome.swing.text.undo.UndoWrapper;

JTextComponent myComponent = ...

UndoWrapper myWrapper = new UndoWrapper( myComponent );

And... that's all, folks!.

You can JavaWebStart a small demo of the UndoWrapper

Key bindings

Key bindings are Ctrl-Z for undo and Ctrl-Y for redo. These follow the Common User Access Guidelines, as far as I understand from this page. I'm not sure if Ctrl-Y is for sure a CUA binding, but I suspect it is (because many user interfaces have this binding).

A word of warning

Beware that the Undo-Redo functionality requires memory (well, of course), so think it twice before adding Undo-Redo support to all your text components, right? I assume there's really no problem in doing so (nowadays computers are really powerful), but do some tests before trying it out in tons of components, ok?

The wrapper series

I pretend to do some sort of text wrapper series, that would include different common-sense functionality to any Swing widgets. Among the requirements for these wrappers are:

  • No inheritance needed: you should be able to use the wrappers without using custom components.
  • Extremely easy to use: a few lines of code should suffice to get it working.

As you may suspect, this "Undo Wrapper" is the second wrapper I release (the first one is the TreeWrapper, that provides popup menus and drag-and-drop for JTrees).

I will be storing all these wrappers in my attic. Sources are LGPL'ed there.

I've got some ideas in mind, such as selecting all stuff in the text field when focus is gained, or an easy way to add popup menus to text components (including the frequently used cut-copy-paste popup menu).

Any ideas would be most welcome, as usual ;-).

Happy wrapping, Antonio

blog comments powered by Disqus