- java.lang.Object
-
- javax.swing.undo.AbstractUndoableEdit
-
- javax.swing.undo.CompoundEdit
-
- javax.swing.text.AbstractDocument.DefaultDocumentEvent
-
- All Implemented Interfaces:
- Serializable, DocumentEvent, 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.swing.event.DocumentEvent
DocumentEvent.ElementChange, DocumentEvent.EventType
-
-
Field Summary
-
Fields inherited from class javax.swing.undo.CompoundEdit
edits
-
-
Constructor Summary
Constructors Constructor and Description AbstractDocument.DefaultDocumentEvent(int offs, int len, DocumentEvent.EventType type)
Constructs a change record.
-
Method Summary
Methods Modifier and Type Method and 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.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.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
-
-
-
-
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 >= 0len
- the length of the change >= 0type
- the type of event (DocumentEvent.EventType)- Since:
- 1.4
-
-
Method Detail
-
toString
public String toString()
Returns a string description of the change event.- Overrides:
toString
in classCompoundEdit
- 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 interfaceUndoableEdit
- Overrides:
addEdit
in classCompoundEdit
- Parameters:
anEdit
- a document edit record- Returns:
- true if the edit was added
- See Also:
UndoableEdit.addEdit(javax.swing.undo.UndoableEdit)
-
redo
public void redo() throws CannotRedoException
Redoes a change.- Specified by:
redo
in interfaceUndoableEdit
- Overrides:
redo
in classCompoundEdit
- Throws:
CannotRedoException
- if the change cannot be redone- See Also:
AbstractUndoableEdit.canRedo()
-
undo
public void undo() throws CannotUndoException
Undoes a change.- Specified by:
undo
in interfaceUndoableEdit
- Overrides:
undo
in classCompoundEdit
- Throws:
CannotUndoException
- 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
in interfaceUndoableEdit
- Overrides:
isSignificant
in classCompoundEdit
- 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
in interfaceUndoableEdit
- Overrides:
getPresentationName
in classCompoundEdit
- 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
in interfaceUndoableEdit
- Overrides:
getUndoPresentationName
in classCompoundEdit
- 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
in interfaceUndoableEdit
- Overrides:
getRedoPresentationName
in classCompoundEdit
- Returns:
- the description
- See Also:
AbstractUndoableEdit.getPresentationName()
-
getType
public DocumentEvent.EventType getType()
Returns the type of event.- Specified by:
getType
in interfaceDocumentEvent
- 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 interfaceDocumentEvent
- Returns:
- the offset >= 0
- See Also:
DocumentEvent.getOffset()
-
getLength
public int getLength()
Returns the length of the change.- Specified by:
getLength
in interfaceDocumentEvent
- Returns:
- the length >= 0
- See Also:
DocumentEvent.getLength()
-
getDocument
public Document getDocument()
Gets the document that sourced the change event.- Specified by:
getDocument
in interfaceDocumentEvent
- Returns:
- the document
- See Also:
DocumentEvent.getDocument()
-
getChange
public DocumentEvent.ElementChange getChange(Element elem)
Gets the changes for an element.- Specified by:
getChange
in interfaceDocumentEvent
- Parameters:
elem
- the element- Returns:
- the changes
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/swing/text/AbstractDocument.DefaultDocumentEvent.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.