javax.swing.text
Class DefaultStyledDocument.ElementBuffer
java.lang.Object
javax.swing.text.DefaultStyledDocument.ElementBuffer
- All Implemented Interfaces:
- Serializable
- Enclosing class:
- DefaultStyledDocument
public class DefaultStyledDocument.ElementBuffer
- extends Object
- implements Serializable
Performs all structural changes to the Element
hierarchy. This class was implemented with much help from the document:
http://java.sun.com/products/jfc/tsc/articles/text/element_buffer/index.html.
- See Also:
- Serialized Form
Method Summary |
void |
change(int offset,
int length,
AbstractDocument.DefaultDocumentEvent ev)
Modifies the element structure so that the specified interval starts and
ends at an element boundary. |
protected void |
changeUpdate()
Performs the actual work for change(int, int, javax.swing.text.AbstractDocument.DefaultDocumentEvent) . |
Element |
clone(Element parent,
Element clonee)
Creates and returns a deep clone of the specified clonee
with the specified parent as new parent. |
Element |
getRootElement()
Returns the root element of this ElementBuffer . |
void |
insert(int offset,
int length,
DefaultStyledDocument.ElementSpec[] data,
AbstractDocument.DefaultDocumentEvent ev)
Inserts new Element in the document at the specified
position. |
protected void |
insertUpdate(DefaultStyledDocument.ElementSpec[] data)
Inserts new content. |
void |
remove(int offs,
int len,
AbstractDocument.DefaultDocumentEvent ev)
Removes the content. |
protected void |
removeUpdate()
Updates the element structure of the document in response to removal of
content. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultStyledDocument.ElementBuffer
public DefaultStyledDocument.ElementBuffer(Element root)
- Creates a new
ElementBuffer
for the specified
root
element.
- Parameters:
root
- the root element for this ElementBuffer
getRootElement
public Element getRootElement()
- Returns the root element of this
ElementBuffer
.
- Returns:
- the root element of this
ElementBuffer
remove
public void remove(int offs,
int len,
AbstractDocument.DefaultDocumentEvent ev)
- Removes the content. This method sets some internal parameters and
delegates the work to
removeUpdate()
.
- Parameters:
offs
- the offset from which content is removelen
- the length of the removed contentev
- the document event that records the changes
removeUpdate
protected void removeUpdate()
- Updates the element structure of the document in response to removal of
content. It removes the affected
Element
s from the document
structure.
changeUpdate
protected void changeUpdate()
- Performs the actual work for
change(int, int, javax.swing.text.AbstractDocument.DefaultDocumentEvent)
. The elements at the
interval boundaries are split up (if necessary) so that the interval
boundaries are located at element boundaries.
change
public void change(int offset,
int length,
AbstractDocument.DefaultDocumentEvent ev)
- Modifies the element structure so that the specified interval starts and
ends at an element boundary. Content and paragraph elements are split and
created as necessary. This also updates the
DefaultDocumentEvent
to reflect the structural changes.
The bulk work is delegated to changeUpdate()
.
- Parameters:
offset
- the start index of the interval to be changedlength
- the length of the interval to be changedev
- the DefaultDocumentEvent
describing the change
clone
public Element clone(Element parent,
Element clonee)
- Creates and returns a deep clone of the specified
clonee
with the specified parent as new parent.
This method can only clone direct instances of BranchElement
or LeafElement
.
- Parameters:
parent
- the new parentclonee
- the element to be cloned
- Returns:
- the cloned element with the new parent
insert
public void insert(int offset,
int length,
DefaultStyledDocument.ElementSpec[] data,
AbstractDocument.DefaultDocumentEvent ev)
- Inserts new
Element
in the document at the specified
position. Most of the work is done by insertUpdate(javax.swing.text.DefaultStyledDocument.ElementSpec[])
, after some
fields have been prepared for it.
- Parameters:
offset
- the location in the document at which the content is insertedlength
- the length of the inserted contentdata
- the element specifications for the content to be insertedev
- the document event that is updated to reflect the structural
changes
insertUpdate
protected void insertUpdate(DefaultStyledDocument.ElementSpec[] data)
- Inserts new content.
- Parameters:
data
- the element specifications for the elements to be inserted