com.borland.primetime.editor
Class JBUndoManager

java.lang.Object
  |
  +--com.borland.primetime.editor.JBUndoManager

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

This is the Undo Manager. It handles UndoSegments and UndoGroups, so that blocks of edits can be undone and redone as a group.


Inner Class Summary
protected  class JBUndoManager.UndoGroup
          An UndoGroup is a collection of zero or more edits that are treated as one unit in terms of undo and redo support.
protected  class JBUndoManager.UndoSegment
          An UndoSegment is a special subclass of UndoGroup which is able to coalesce subsequent edits of the same type.
 
Field Summary
protected  JBUndoManager.UndoGroup activeUndoGroup
           
static int INSERT
           
static int OVERWRITE
           
static int REMOVE
           
protected  java.util.Stack undoGroupStack
           
static int UNKNOWN
           
 
Constructor Summary
JBUndoManager()
           
 
Method Summary
 boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
          Insert anEdit at indexOfNextAdd, and remove any old edits that were at indexOfNextAdd or later.
 boolean canRedo()
          Check whether or not redo is valid in the current state.
 boolean canUndo()
          Check whether or not undo is valid in the current state.
 void discardAllEdits()
          Clear the entire undo stack, calling die on all the edits in reverse order.
 void endUndoGroup(int point, int mark)
          End the current undo group.
 void endUndoSegment(int point, int mark)
          End the current undo group.
protected  JBUndoManager.UndoGroup getCurrentRedoEdit()
          Get the current edit to redo, if redo is performed.
protected  JBUndoManager.UndoGroup getCurrentUndoEdit()
          Get the current edit to undo, if undo is performed.
 int getCurrentUndoHashCode()
          Get the hashcode of the current undo object.
protected  JBUndoManager.UndoGroup getLastEdit()
          Get the last edit in the list.
 int getRedoEndMark()
          Return the offset of the caret mark after the current edit to redo.
 int getRedoEndPoint()
          Return the offset of the caret point after the current edit to redo.
 int getRedoStartMark()
          Return the offset of the caret mark before the current edit to redo.
 int getRedoStartPoint()
          Return the offset of the caret point before the current edit to redo.
 int getUndoEndMark()
          Return the offset of the caret mark after the current edit to undo.
 int getUndoEndPoint()
          Return the offset of the caret point after the current edit to undo.
 int getUndoStartMark()
          Return the offset of the caret mark before the current edit to undo.
 int getUndoStartPoint()
          Return the offset of the caret point before the current edit to undo.
 void redo()
          Redo the edit at indexOfNextAdd.
 void startUndoGroup(int point, int mark)
          Start a new undo group.
 void startUndoSegment(int point, int mark, int type)
          Start a new UndoSegment.
protected  void trimEdits(int index)
          Trim the list of edits from the end of the list to index.
protected  void trimForLimit()
          Ensure that the list of edits is under MAXEDITSIZE.
 void undo()
          Undo the edit just before indexOfNextAdd.
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
          Called by the UndoabledEdit sources this UndoManager listens to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN

INSERT

public static final int INSERT

REMOVE

public static final int REMOVE

OVERWRITE

public static final int OVERWRITE

activeUndoGroup

protected JBUndoManager.UndoGroup activeUndoGroup

undoGroupStack

protected java.util.Stack undoGroupStack
Constructor Detail

JBUndoManager

public JBUndoManager()
Method Detail

getCurrentUndoHashCode

public int getCurrentUndoHashCode()
Get the hashcode of the current undo object.
Returns:
the hashcode of the next edit to be undone, or -1 if there are no edits to be undone.

canUndo

public boolean canUndo()
Check whether or not undo is valid in the current state.
Returns:
true if undo can be formed now, false otherwise.

canRedo

public boolean canRedo()
Check whether or not redo is valid in the current state.
Returns:
true if redo can be formed now, false otherwise.

undo

public void undo()
          throws javax.swing.undo.CannotUndoException
Undo the edit just before indexOfNextAdd.
Throws:
javax.swing.undo.CannotUndoException - if undo cannot be performed now.

redo

public void redo()
          throws javax.swing.undo.CannotRedoException
Redo the edit at indexOfNextAdd.
Throws:
javax.swing.undo.CannotRedoException - if redo cannot be performed now.

addEdit

public boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
Insert anEdit at indexOfNextAdd, and remove any old edits that were at indexOfNextAdd or later. Updates indexOfNextAdd.
Parameters:
anEdit - the UndoableEdit to add.
Returns:
True if anEdit was sucessfully added (should always returns true).

discardAllEdits

public void discardAllEdits()
Clear the entire undo stack, calling die on all the edits in reverse order.

undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
Called by the UndoabledEdit sources this UndoManager listens to. Calls addEdit with e.getEdit().
Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener
See Also:
addEdit(javax.swing.undo.UndoableEdit)

getUndoStartPoint

public int getUndoStartPoint()
Return the offset of the caret point before the current edit to undo. The editor should place the caret point at that offset if the current edit is undone.
Returns:
the offset of the caret point before the current edit to undo. If the offset is not known, -1 is returned.

getUndoStartMark

public int getUndoStartMark()
Return the offset of the caret mark before the current edit to undo. The editor should place the caret mark at that offset if the current edit is undone.
Returns:
the offset of the caret mark before the current edit to undo. If the offset is not known, -1 is returned.

getUndoEndPoint

public int getUndoEndPoint()
Return the offset of the caret point after the current edit to undo. The editor uses this to determine if the caret point is at the same offset as it was immediately after this edit was performed.
Returns:
the offset of the caret point after the current edit to undo. If the offset is not known, -1 is returned.

getUndoEndMark

public int getUndoEndMark()
Return the offset of the caret mark after the current edit to undo. The editor uses this to determine if the caret mark is at the same offset as it was immediately after this edit was performed.
Returns:
the offset of the caret mark after the current edit to undo. If the offset is not known, -1 is returned.

getRedoStartPoint

public int getRedoStartPoint()
Return the offset of the caret point before the current edit to redo. The editor uses this to determine if the caret point is at the same offset as it was immediately after this edit was undone.
Returns:
the offset of the caret point before the current edit to redo. If the offset is not known, -1 is returned.

getRedoStartMark

public int getRedoStartMark()
Return the offset of the caret mark before the current edit to redo. The editor uses this to determine if the caret mark is at the same offset as it was immediately after this edit was undone.
Returns:
the offset of the caret mark before the current edit to redo. If the offset is not known, -1 is returned.

getRedoEndPoint

public int getRedoEndPoint()
Return the offset of the caret point after the current edit to redo. The editor should place the caret point at that offset if the current edit is redone.
Returns:
the offset of the caret point after the current edit to redo. If the offset is not known, -1 is returned.

getRedoEndMark

public int getRedoEndMark()
Return the offset of the caret mark after the current edit to redo. The editor should place the caret mark at that offset if the current edit is redone.
Returns:
the offset of the caret mark after the current edit to redo. If the offset is not known, -1 is returned.

getLastEdit

protected JBUndoManager.UndoGroup getLastEdit()
Get the last edit in the list.
Returns:
the Current edit to undo, or null if there is none appropriate.

getCurrentUndoEdit

protected JBUndoManager.UndoGroup getCurrentUndoEdit()
Get the current edit to undo, if undo is performed.
Returns:
the current edit to undo, or null if there is none appropriate.

getCurrentRedoEdit

protected JBUndoManager.UndoGroup getCurrentRedoEdit()
Get the current edit to redo, if redo is performed.
Returns:
the current edit to redo, or null if there is none appropriate.

trimEdits

protected void trimEdits(int index)
Trim the list of edits from the end of the list to index. We remove the edits in reverse order, calling die on them as we go.
Parameters:
index - Trim from this point forward in the list.

trimForLimit

protected void trimForLimit()
Ensure that the list of edits is under MAXEDITSIZE. If it's too large, start removing edits at 0 and calling die on them.

startUndoSegment

public void startUndoSegment(int point,
                             int mark,
                             int type)
Start a new UndoSegment. Subsequent edits will be automatically placed in the active UndoSegment, which will allow them to be undone as a unit.
Parameters:
point - The position of the caret point to be recorded at the start of this UndoSegment.
mark - The position of the caret mark to be recorded at the start of this UndoSegment.
type - The type of edit this UndoSegment represents.

endUndoSegment

public void endUndoSegment(int point,
                           int mark)
End the current undo group. This also places the current group on the undo stack.
Parameters:
point - The position of the caret point to be recorded at the end of this undo group.
mark - The position of the caret mark to be recorded at the end of this undo group.

startUndoGroup

public void startUndoGroup(int point,
                           int mark)
Start a new undo group. Subsequent edits will be automatically placed in the active undo group, which will allow them to be undone as a unit.
Parameters:
point - The position of the caret point to be recorded at the start of this undo group.
mark - The position of the caret mark to be recorded at the start of this undo group.

endUndoGroup

public void endUndoGroup(int point,
                         int mark)
End the current undo group. This also places the current group on the undo stack.
Parameters:
point - The position of the caret point to be recorded at the end of this undo group.
mark - The position of the caret mark to be recorded at the end of this undo group.