javax.swing.text

Class DefaultStyledDocument.ElementBuffer

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.
Constructor Summary
ElementBuffer(Element root)
Creates a new ElementBuffer for the specified root element.
Method Summary
voidchange(int offset, int length, DefaultDocumentEvent ev)
Modifies the element structure so that the specified interval starts and ends at an element boundary.
protected voidchangeUpdate()
Performs the actual work for {@link #change}.
Elementclone(Element parent, Element clonee)
Creates and returns a deep clone of the specified clonee with the specified parent as new parent.
ElementgetRootElement()
Returns the root element of this ElementBuffer.
voidinsert(int offset, int length, DefaultStyledDocument.ElementSpec[] data, DefaultDocumentEvent ev)
Inserts new Element in the document at the specified position.
protected voidinsertUpdate(DefaultStyledDocument.ElementSpec[] data)
Inserts new content.
voidremove(int offs, int len, DefaultDocumentEvent ev)
Removes the content.
protected voidremoveUpdate()
Updates the element structure of the document in response to removal of content.

Constructor Detail

ElementBuffer

public ElementBuffer(Element root)
Creates a new ElementBuffer for the specified root element.

Parameters: root the root element for this ElementBuffer

Method Detail

change

public void change(int offset, int length, 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 {@link #changeUpdate()}.

Parameters: offset the start index of the interval to be changed length the length of the interval to be changed ev the DefaultDocumentEvent describing the change

changeUpdate

protected void changeUpdate()
Performs the actual work for {@link #change}. The elements at the interval boundaries are split up (if necessary) so that the interval boundaries are located at element boundaries.

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 {@link BranchElement} or {@link LeafElement}.

Parameters: parent the new parent clonee the element to be cloned

Returns: the cloned element with the new parent

getRootElement

public Element getRootElement()
Returns the root element of this ElementBuffer.

Returns: the root element of this ElementBuffer

insert

public void insert(int offset, int length, DefaultStyledDocument.ElementSpec[] data, DefaultDocumentEvent ev)
Inserts new Element in the document at the specified position. Most of the work is done by {@link #insertUpdate}, after some fields have been prepared for it.

Parameters: offset the location in the document at which the content is inserted length the length of the inserted content data the element specifications for the content to be inserted ev 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

remove

public void remove(int offs, int len, DefaultDocumentEvent ev)
Removes the content. This method sets some internal parameters and delegates the work to {@link #removeUpdate}.

Parameters: offs the offset from which content is remove len the length of the removed content ev 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 {@link Element}s from the document structure.