jwo.utils.gui
Class UndoHandler

java.lang.Object
  extended by jwo.utils.gui.UndoHandler
All Implemented Interfaces:
EventListener, UndoableEditListener

public class UndoHandler
extends Object
implements UndoableEditListener

Deals with the 'undo' and 'redo' actions associated with a document. This handler should be passed the text component used to display the document so that it can use it to find the standard edit actions. Undo is also mapped onto ctrl-z and redo onto ctrl-y so that menu control is not necessary.

Version:
2.3, 15th February, 2006.
Author:
Jo Wood with additions based on code by Henk Muller.

Constructor Summary
UndoHandler(JTextComponent textComp)
          Creates a handler to be attached to the given text component.
UndoHandler(JTextComponent textComp, boolean ignoreStyleChanges)
          Creates a handler to be attached to the given text component.
 
Method Summary
 void addRedoAction(Action newRedoAction)
          Adds an external redo action to be notified when something is redone.
 void addUndoAction(Action newUndoAction)
          Adds an external undo action to be notified when something is undone.
 boolean redoLastChange()
          Redoes last undoable action.
 void undoableEditHappened(UndoableEditEvent e)
          Responds to undoable edits by saving them in the undo manager.
 boolean undoLastChange()
          Undoes last undoable action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UndoHandler

public UndoHandler(JTextComponent textComp)
Creates a handler to be attached to the given text component. Any style changes are also assumed to be undoable/redoable.

Parameters:
textComp - Text component associated with undo/redo actions.

UndoHandler

public UndoHandler(JTextComponent textComp,
                   boolean ignoreStyleChanges)
Creates a handler to be attached to the given text component. The ignoreStyleChanges argument should be set to true if a syntax highlighter is being used to handle style automatically. By doing so, style changes are not included in the history of undoable/ redoable edit changes.

Parameters:
textComp - Text component associated with undo/redo actions.
ignoreStyleChanges - If true, style changes to textComp's document are ignored.
Method Detail

undoableEditHappened

public void undoableEditHappened(UndoableEditEvent e)
Responds to undoable edits by saving them in the undo manager.

Specified by:
undoableEditHappened in interface UndoableEditListener
Parameters:
e - Undoable edit event.

addUndoAction

public void addUndoAction(Action newUndoAction)
Adds an external undo action to be notified when something is undone.

Parameters:
newUndoAction - Additional undo action (e.g. menu item) to be notified when undo occurs.

addRedoAction

public void addRedoAction(Action newRedoAction)
Adds an external redo action to be notified when something is redone.

Parameters:
newRedoAction - Additional redo action (e.g. menu item) to be notified when redo occurs.

undoLastChange

public boolean undoLastChange()
Undoes last undoable action. This method can be called if an undo action needs to be triggered by an external event such as menu selection.

Returns:
True if last change has been undone.

redoLastChange

public boolean redoLastChange()
Redoes last undoable action. This method can be called if a redo action needs to be triggered by an external event such as menu selection.

Returns:
True if last change has been redone.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009