AbstractDocument.DefaultDocumentEvent (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../../java.base/java/io/Serializable.html "interface in java.io")
, [DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
, [UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Enclosing class:
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.
Nested Class Summary
Field Summary
Constructor Summary
Method Summary
Modifier and Type | Method | Description |
---|---|---|
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. |
Constructor Details
DefaultDocumentEvent
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)
Since:
1.4Method Details
toString
Returns a string description of the change event.
Overrides:
[toString](../undo/CompoundEdit.html#toString%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Returns:
a stringaddEdit
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](../undo/UndoableEdit.html#addEdit%28javax.swing.undo.UndoableEdit%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[addEdit](../undo/CompoundEdit.html#addEdit%28javax.swing.undo.UndoableEdit%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Parameters:
anEdit
- a document edit record
Returns:
true if the edit was added
See Also:
UndoableEdit.addEdit(javax.swing.undo.UndoableEdit)redo
Redoes a change.
Specified by:
[redo](../undo/UndoableEdit.html#redo%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[redo](../undo/CompoundEdit.html#redo%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Throws:
[CannotRedoException](../undo/CannotRedoException.html "class in javax.swing.undo")
- if the change cannot be redone
See Also:
AbstractUndoableEdit.canRedo()undo
Undoes a change.
Specified by:
[undo](../undo/UndoableEdit.html#undo%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[undo](../undo/CompoundEdit.html#undo%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Throws:
[CannotUndoException](../undo/CannotUndoException.html "class in javax.swing.undo")
- if the change cannot be undone
See Also:
AbstractUndoableEdit.canUndo()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](../undo/UndoableEdit.html#isSignificant%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[isSignificant](../undo/CompoundEdit.html#isSignificant%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Returns:
whether the event is significant for edit undo purposes
See Also:
UndoableEdit.isSignificant()getPresentationName
public String getPresentationName()
Provides a localized, human readable description of this edit suitable for use in, say, a change log.
Specified by:
[getPresentationName](../undo/UndoableEdit.html#getPresentationName%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[getPresentationName](../undo/CompoundEdit.html#getPresentationName%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Returns:
the description
See Also:
AbstractUndoableEdit.getUndoPresentationName(), AbstractUndoableEdit.getRedoPresentationName()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](../undo/UndoableEdit.html#getUndoPresentationName%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[getUndoPresentationName](../undo/CompoundEdit.html#getUndoPresentationName%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Returns:
the description
See Also:
AbstractUndoableEdit.getPresentationName()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](../undo/UndoableEdit.html#getRedoPresentationName%28%29)
in interface[UndoableEdit](../undo/UndoableEdit.html "interface in javax.swing.undo")
Overrides:
[getRedoPresentationName](../undo/CompoundEdit.html#getRedoPresentationName%28%29)
in class[CompoundEdit](../undo/CompoundEdit.html "class in javax.swing.undo")
Returns:
the description
See Also:
AbstractUndoableEdit.getPresentationName()getType
Returns the type of event.
Specified by:
[getType](../event/DocumentEvent.html#getType%28%29)
in interface[DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
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](../event/DocumentEvent.html#getOffset%28%29)
in interface[DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
Returns:
the offset >= 0
See Also:
DocumentEvent.getOffset()getLength
public int getLength()
Returns the length of the change.
Specified by:
[getLength](../event/DocumentEvent.html#getLength%28%29)
in interface[DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
Returns:
the length >= 0
See Also:
DocumentEvent.getLength()getDocument
Gets the document that sourced the change event.
Specified by:
[getDocument](../event/DocumentEvent.html#getDocument%28%29)
in interface[DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
Returns:
the document
See Also:
DocumentEvent.getDocument()getChange
Gets the changes for an element.
Specified by:
[getChange](../event/DocumentEvent.html#getChange%28javax.swing.text.Element%29)
in interface[DocumentEvent](../event/DocumentEvent.html "interface in javax.swing.event")
Parameters:
elem
- the element
Returns:
the changes