javax.swing.text
Class AbstractDocument.DefaultDocumentEvent

java.lang.Object
  extended byjavax.swing.undo.AbstractUndoableEdit
      extended byjavax.swing.undo.CompoundEdit
          extended byjavax.swing.text.AbstractDocument.DefaultDocumentEvent
All Implemented Interfaces:
DocumentEvent, Serializable, UndoableEdit
Enclosing class:
AbstractDocument

public class AbstractDocument.DefaultDocumentEvent
extends CompoundEdit
implements DocumentEvent

Stores document changes as the document is being modified. Can subsequently be used for change notification when done with the document modification transaction. This is used by the AbstractDocument class and its extensions for broadcasting change information to the document listeners.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.event.DocumentEvent
DocumentEvent.ElementChange, DocumentEvent.EventType
 
Field Summary
private  Hashtable changeLookup
           
private  int length
           
private  int offset
           
private  DocumentEvent.EventType type
           
 
Fields inherited from class javax.swing.undo.CompoundEdit
edits
 
Fields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName
 
Constructor Summary
AbstractDocument.DefaultDocumentEvent(int offs, int len, DocumentEvent.EventType type)
          Constructs a change record.
 
Method Summary
 boolean addEdit(UndoableEdit anEdit)
          Adds a document edit.
 DocumentEvent.ElementChange getChange(Element elem)
          Gets the changes for an element.
 Document getDocument()
          Gets the document that sourced the change event.
 int getLength()
          Returns the length of the change.
 int getOffset()
          Returns the offset within the document of the start of the change.
 String getPresentationName()
          Provides a localized, human readable description of this edit suitable for use in, say, a change log.
 String getRedoPresentationName()
          Provides a localized, human readable description of the redoable form of this edit, e.g. for use as a Redo menu item.
 DocumentEvent.EventType getType()
          Returns the type of event.
 String getUndoPresentationName()
          Provides a localized, human readable description of the undoable form of this edit, e.g. for use as an Undo menu item.
 boolean isSignificant()
          DefaultDocument events are significant.
 void redo()
          Redoes a change.
 String toString()
          Returns a string description of the change event.
 void undo()
          Undoes a change.
 
Methods inherited from class javax.swing.undo.CompoundEdit
canRedo, canUndo, die, end, isInProgress, lastEdit
 
Methods inherited from class javax.swing.undo.AbstractUndoableEdit
replaceEdit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

offset

private int offset

length

private int length

changeLookup

private Hashtable changeLookup

type

private DocumentEvent.EventType type
Constructor Detail

AbstractDocument.DefaultDocumentEvent

public AbstractDocument.DefaultDocumentEvent(int offs,
                                             int len,
                                             DocumentEvent.EventType type)
Constructs a change record.

Parameters:
offs - the offset into the document of the change >= 0
len - the length of the change >= 0
type - the type of event (DocumentEvent.EventType)
Method Detail

toString

public String toString()
Returns a string description of the change event.

Overrides:
toString in class CompoundEdit
Returns:
a string

addEdit

public boolean addEdit(UndoableEdit anEdit)
Adds a document edit. If the number of edits crosses a threshold, this switches on a hashtable lookup for ElementChange implementations since access of these needs to be relatively quick.

Specified by:
addEdit in interface UndoableEdit
Overrides:
addEdit in class CompoundEdit
Parameters:
anEdit - a document edit record
Returns:
true if the edit was added

redo

public void redo()
          throws CannotRedoException
Redoes a change.

Specified by:
redo in interface UndoableEdit
Overrides:
redo in class CompoundEdit
Throws:
CannotRedoException - if the change cannot be redone

undo

public void undo()
          throws CannotUndoException
Undoes a change.

Specified by:
undo in interface UndoableEdit
Overrides:
undo in class CompoundEdit
Throws:
CannotUndoException - if the change cannot be undone

isSignificant

public boolean isSignificant()
DefaultDocument events are significant. If you wish to aggregate DefaultDocumentEvents to present them as a single edit to the user place them into a CompoundEdit.

Specified by:
isSignificant in interface UndoableEdit
Overrides:
isSignificant in class CompoundEdit
Returns:
whether the event is significant for edit undo purposes

getPresentationName

public String getPresentationName()
Provides a localized, human readable description of this edit suitable for use in, say, a change log.

Specified by:
getPresentationName in interface UndoableEdit
Overrides:
getPresentationName in class CompoundEdit
Returns:
the description

getUndoPresentationName

public String getUndoPresentationName()
Provides a localized, human readable description of the undoable form of this edit, e.g. for use as an Undo menu item. Typically derived from getDescription();

Specified by:
getUndoPresentationName in interface UndoableEdit
Overrides:
getUndoPresentationName in class CompoundEdit
Returns:
the description

getRedoPresentationName

public String getRedoPresentationName()
Provides a localized, human readable description of the redoable form of this edit, e.g. for use as a Redo menu item. Typically derived from getPresentationName();

Specified by:
getRedoPresentationName in interface UndoableEdit
Overrides:
getRedoPresentationName in class CompoundEdit
Returns:
the description

getType

public DocumentEvent.EventType getType()
Returns the type of event.

Specified by:
getType in interface DocumentEvent
Returns:
the event type as a DocumentEvent.EventType
See Also:
DocumentEvent.getType()

getOffset

public int getOffset()
Returns the offset within the document of the start of the change.

Specified by:
getOffset in interface DocumentEvent
Returns:
the offset >= 0
See Also:
DocumentEvent.getOffset()

getLength

public int getLength()
Returns the length of the change.

Specified by:
getLength in interface DocumentEvent
Returns:
the length >= 0
See Also:
DocumentEvent.getLength()

getDocument

public Document getDocument()
Gets the document that sourced the change event.

Specified by:
getDocument in interface DocumentEvent
Returns:
the document
See Also:
DocumentEvent.getDocument()

getChange

public DocumentEvent.ElementChange getChange(Element elem)
Gets the changes for an element.

Specified by:
getChange in interface DocumentEvent
Parameters:
elem - the element
Returns:
the changes