/** * UndoWrapper is responsible for adding undo and redo support to text components. * @author Antonio Vieiro (antonio@antonioshome.net), $Author: $ * @version $Revision: $ */ public class UndoWrapper implements UndoableEditListener { private UndoManager undoManager; private UndoAction undoAction; private RedoAction redoAction; private JEditorPane textComponent;
/** * Creates a new instance of UndoWrapper */ public UndoWrapper( JEditorPane aComponent ) { textComponent = aComponent; undoManager = new UndoManager(); undoAction = new UndoAction(); redoAction = new RedoAction(); textComponent.getDocument().addUndoableEditListener( this ); textComponent.getInputMap().put( (KeyStroke) undoAction.getValue( Action.ACCELERATOR_KEY), "undo" ); textComponent.getInputMap().put( (KeyStroke) redoAction.getValue( Action.ACCELERATOR_KEY), "redo" ); textComponent.getActionMap().put( "undo", undoAction ); textComponent.getActionMap().put( "redo", redoAction ); }