javax.swing.text
Class DefaultStyledDocument.ElementBuffer

java.lang.Object
  extended byjavax.swing.text.DefaultStyledDocument.ElementBuffer
All Implemented Interfaces:
Serializable
Enclosing class:
DefaultStyledDocument

public class DefaultStyledDocument.ElementBuffer
extends Object
implements Serializable

Class to manage changes to the element hierarchy.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

See Also:
Serialized Form

Nested Class Summary
(package private)  class DefaultStyledDocument.ElementBuffer.ElemChanges
           
 
Field Summary
(package private)  Vector changes
           
(package private)  boolean createdFracture
          Only for insert, set to true when the fracture has been created.
(package private)  int endOffset
           
(package private)  Element fracturedChild
          Fractured child.
(package private)  Element fracturedParent
          Parent that contains the fractured child.
(package private)  boolean insertOp
           
(package private)  DefaultStyledDocument.ElementBuffer.ElemChanges[] insertPath
          For insert, path to inserted elements.
(package private)  int length
           
(package private)  int offset
           
(package private)  boolean offsetLastIndex
          Used to indicate when fracturing that the last leaf should be skipped.
(package private)  boolean offsetLastIndexOnReplace
          Used to indicate that the parent of the deepest leaf should offset the index by 1 when adding/removing elements in an insert.
(package private)  Stack path
           
(package private)  int pos
           
(package private)  boolean recreateLeafs
           
(package private)  Element root
           
 
Constructor Summary
DefaultStyledDocument.ElementBuffer(Element root)
          Creates a new ElementBuffer.
 
Method Summary
(package private)  void advance(int n)
          move the current offset forward by n.
(package private)  void beginEdits(int offset, int length)
          Initialize the buffer
(package private)  boolean canJoin(Element e0, Element e1)
          Can the two given elements be coelesced together into one element?
 void change(int offset, int length, AbstractDocument.DefaultDocumentEvent de)
          Changes content.
protected  void changeUpdate()
          Updates the element structure in response to a change in the document.
 Element clone(Element parent, Element clonee)
          Creates a copy of this element, with a different parent.
(package private)  Element cloneAsNecessary(Element parent, Element clonee, int rmOffs0, int rmOffs1)
          Creates a copy of this element, with a different parent.
(package private)  void create(int length, DefaultStyledDocument.ElementSpec[] data, AbstractDocument.DefaultDocumentEvent de)
           
(package private)  void endEdits(AbstractDocument.DefaultDocumentEvent de)
          Creates the UndoableEdit record for the edits made in the buffer.
(package private)  void fracture(int depth)
          Determines if a fracture needs to be performed.
(package private)  void fractureDeepestLeaf(DefaultStyledDocument.ElementSpec[] specs)
          Splits the bottommost leaf in path.
(package private)  void fractureFrom(DefaultStyledDocument.ElementBuffer.ElemChanges[] changed, int startIndex, int endFractureIndex)
          Recreates the elements to the right of the insertion point.
 Element getRootElement()
          Gets the root element.
 void insert(int offset, int length, DefaultStyledDocument.ElementSpec[] data, AbstractDocument.DefaultDocumentEvent de)
          Inserts new content.
(package private)  void insertElement(DefaultStyledDocument.ElementSpec es)
           
(package private)  void insertFirstContent(DefaultStyledDocument.ElementSpec[] specs)
          Inserts the first content.
protected  void insertUpdate(DefaultStyledDocument.ElementSpec[] data)
          Inserts an update into the document.
(package private)  Element join(Element p, Element left, Element right, int rmOffs0, int rmOffs1)
          Joins the two elements carving out a hole for the given removed range.
(package private)  void pop()
           
(package private)  void push(Element e, int index)
           
(package private)  void push(Element e, int index, boolean isFracture)
          Pushes a new element onto the stack that represents the current path.
(package private)  Element recreateFracturedElement(Element parent, Element toDuplicate)
          Recreates toDuplicate.
 void remove(int offset, int length, AbstractDocument.DefaultDocumentEvent de)
          Removes content.
(package private)  boolean removeElements(Element elem, int rmOffs0, int rmOffs1)
          Remove the elements from elem in range rmOffs0, rmOffs1.
protected  void removeUpdate()
          Updates the element structure in response to a removal from the associated sequence in the document.
(package private)  boolean split(int offs, int len)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

Element root

pos

transient int pos

offset

transient int offset

length

transient int length

endOffset

transient int endOffset

changes

transient Vector changes

path

transient Stack path

insertOp

transient boolean insertOp

recreateLeafs

transient boolean recreateLeafs

insertPath

transient DefaultStyledDocument.ElementBuffer.ElemChanges[] insertPath
For insert, path to inserted elements.


createdFracture

transient boolean createdFracture
Only for insert, set to true when the fracture has been created.


fracturedParent

transient Element fracturedParent
Parent that contains the fractured child.


fracturedChild

transient Element fracturedChild
Fractured child.


offsetLastIndex

transient boolean offsetLastIndex
Used to indicate when fracturing that the last leaf should be skipped.


offsetLastIndexOnReplace

transient boolean offsetLastIndexOnReplace
Used to indicate that the parent of the deepest leaf should offset the index by 1 when adding/removing elements in an insert.

Constructor Detail

DefaultStyledDocument.ElementBuffer

public DefaultStyledDocument.ElementBuffer(Element root)
Creates a new ElementBuffer.

Parameters:
root - the root element
Method Detail

getRootElement

public Element getRootElement()
Gets the root element.

Returns:
the root element

insert

public void insert(int offset,
                   int length,
                   DefaultStyledDocument.ElementSpec[] data,
                   AbstractDocument.DefaultDocumentEvent de)
Inserts new content.

Parameters:
offset - the starting offset >= 0
length - the length >= 0
data - the data to insert
de - the event capturing this edit

create

void create(int length,
            DefaultStyledDocument.ElementSpec[] data,
            AbstractDocument.DefaultDocumentEvent de)

remove

public void remove(int offset,
                   int length,
                   AbstractDocument.DefaultDocumentEvent de)
Removes content.

Parameters:
offset - the starting offset >= 0
length - the length >= 0
de - the event capturing this edit

change

public void change(int offset,
                   int length,
                   AbstractDocument.DefaultDocumentEvent de)
Changes content.

Parameters:
offset - the starting offset >= 0
length - the length >= 0
de - the event capturing this edit

insertUpdate

protected void insertUpdate(DefaultStyledDocument.ElementSpec[] data)
Inserts an update into the document.

Parameters:
data - the elements to insert

removeUpdate

protected void removeUpdate()
Updates the element structure in response to a removal from the associated sequence in the document. Any elements consumed by the span of the removal are removed.


changeUpdate

protected void changeUpdate()
Updates the element structure in response to a change in the document.


split

boolean split(int offs,
              int len)

endEdits

void endEdits(AbstractDocument.DefaultDocumentEvent de)
Creates the UndoableEdit record for the edits made in the buffer.


beginEdits

void beginEdits(int offset,
                int length)
Initialize the buffer


push

void push(Element e,
          int index,
          boolean isFracture)
Pushes a new element onto the stack that represents the current path.

Parameters:
isFracture - true if pushing on an element that was created as the result of a fracture.

push

void push(Element e,
          int index)

pop

void pop()

advance

void advance(int n)
move the current offset forward by n.


insertElement

void insertElement(DefaultStyledDocument.ElementSpec es)

removeElements

boolean removeElements(Element elem,
                       int rmOffs0,
                       int rmOffs1)
Remove the elements from elem in range rmOffs0, rmOffs1. This uses canJoin and join to handle joining the endpoints of the insertion.

Returns:
true if elem will no longer have any elements.

canJoin

boolean canJoin(Element e0,
                Element e1)
Can the two given elements be coelesced together into one element?


join

Element join(Element p,
             Element left,
             Element right,
             int rmOffs0,
             int rmOffs1)
Joins the two elements carving out a hole for the given removed range.


clone

public Element clone(Element parent,
                     Element clonee)
Creates a copy of this element, with a different parent.

Parameters:
parent - the parent element
clonee - the element to be cloned
Returns:
the copy

cloneAsNecessary

Element cloneAsNecessary(Element parent,
                         Element clonee,
                         int rmOffs0,
                         int rmOffs1)
Creates a copy of this element, with a different parent. Children of this element included in the removal range will be discarded.


fracture

void fracture(int depth)
Determines if a fracture needs to be performed. A fracture can be thought of as moving the right part of a tree to a new location, where the right part is determined by what has been inserted. depth is used to indicate a JoinToFracture is needed to an element at a depth of depth. Where the root is 0, 1 is the children of the root...

This will invoke fractureFrom if it is determined a fracture needs to happen.


fractureFrom

void fractureFrom(DefaultStyledDocument.ElementBuffer.ElemChanges[] changed,
                  int startIndex,
                  int endFractureIndex)
Recreates the elements to the right of the insertion point. This starts at startIndex in changed, and calls duplicate to duplicate existing elements. This will also duplicate the elements along the insertion point, until a depth of endFractureIndex is reached, at which point only the elements to the right of the insertion point are duplicated.


recreateFracturedElement

Element recreateFracturedElement(Element parent,
                                 Element toDuplicate)
Recreates toDuplicate. This is called when an element needs to be created as the result of an insertion. This will recurse and create all the children. This is similiar to clone, but deteremines the offsets differently.


fractureDeepestLeaf

void fractureDeepestLeaf(DefaultStyledDocument.ElementSpec[] specs)
Splits the bottommost leaf in path. This is called from insert when the first element is NOT content.


insertFirstContent

void insertFirstContent(DefaultStyledDocument.ElementSpec[] specs)
Inserts the first content. This needs to be separate to handle joining.