net.atlanticbb.tantlinger.ui.text
Class CompoundUndoManager

java.lang.Object
  extended by net.atlanticbb.tantlinger.ui.text.CompoundUndoManager
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.UndoableEditListener

public class CompoundUndoManager
extends java.lang.Object
implements javax.swing.event.UndoableEditListener

Manages compound undoable edits. Before an undoable edit happens on a particular document, you should call the static method CompoundUndoManager.beginCompoundEdit(doc) Conversely after an undoable edit happens on a particular document, you shoulc call the static method CompoundUndoManager.beginCompoundEdit(doc) For either of these methods to work, you must add an instance of CompoundUndoManager as a document listener... e.g doc.addUndoableEditListener(new CompoundUndoManager(doc, new UndoManager()); Note that each CompoundUndoManager should have its own UndoManager.

Author:
Bob Tantlinger

Field Summary
static javax.swing.Action REDO
          Static undo action that works across all documents with a CompoundUndoManager registered as an UndoableEditListener
static javax.swing.Action UNDO
          Static undo action that works across all documents with a CompoundUndoManager registered as an UndoableEditListener
 
Constructor Summary
CompoundUndoManager(javax.swing.text.Document doc)
          Creates a new CompoundUndoManager
CompoundUndoManager(javax.swing.text.Document doc, javax.swing.undo.UndoManager um)
          Creates a new CompoundUndoManager
 
Method Summary
protected  void beginCompoundEdit()
           
static void beginCompoundEdit(javax.swing.text.Document doc)
          Notifies the CompoundUndoManager for the specified Document that a compound edit is about to begin.
static void discardAllEdits(javax.swing.text.Document doc)
          Discards all edits for the specified Document
protected  void endCompoundEdit()
           
static void endCompoundEdit(javax.swing.text.Document doc)
          Notifies the CompoundUndoManager for the specified Document that a compound edit is complete.
static javax.swing.undo.UndoManager getUndoManagerForDocument(javax.swing.text.Document doc)
          Gets the undo manager for a document that has a CompoundUndoManager as an UndoableEditListener
protected static void registerDocument(javax.swing.text.Document doc, CompoundUndoManager lst, javax.swing.undo.UndoManager um)
           
 void undoableEditHappened(javax.swing.event.UndoableEditEvent evt)
           
static void updateUndo(javax.swing.text.Document doc)
          Updates the enabled states of the UNDO and REDO actions for the specified document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDO

public static javax.swing.Action UNDO
Static undo action that works across all documents with a CompoundUndoManager registered as an UndoableEditListener


REDO

public static javax.swing.Action REDO
Static undo action that works across all documents with a CompoundUndoManager registered as an UndoableEditListener

Constructor Detail

CompoundUndoManager

public CompoundUndoManager(javax.swing.text.Document doc,
                           javax.swing.undo.UndoManager um)
Creates a new CompoundUndoManager

Parameters:
doc -
um - The UndoManager to use for this document

CompoundUndoManager

public CompoundUndoManager(javax.swing.text.Document doc)
Creates a new CompoundUndoManager

Parameters:
doc -
Method Detail

registerDocument

protected static void registerDocument(javax.swing.text.Document doc,
                                       CompoundUndoManager lst,
                                       javax.swing.undo.UndoManager um)

getUndoManagerForDocument

public static javax.swing.undo.UndoManager getUndoManagerForDocument(javax.swing.text.Document doc)
Gets the undo manager for a document that has a CompoundUndoManager as an UndoableEditListener

Parameters:
doc -
Returns:
The registed undomanger for the document

beginCompoundEdit

public static void beginCompoundEdit(javax.swing.text.Document doc)
Notifies the CompoundUndoManager for the specified Document that a compound edit is about to begin.

Parameters:
doc -

endCompoundEdit

public static void endCompoundEdit(javax.swing.text.Document doc)
Notifies the CompoundUndoManager for the specified Document that a compound edit is complete.

Parameters:
doc -

updateUndo

public static void updateUndo(javax.swing.text.Document doc)
Updates the enabled states of the UNDO and REDO actions for the specified document

Parameters:
doc -

discardAllEdits

public static void discardAllEdits(javax.swing.text.Document doc)
Discards all edits for the specified Document

Parameters:
doc -

undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent evt)
Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener

beginCompoundEdit

protected void beginCompoundEdit()

endCompoundEdit

protected void endCompoundEdit()