javax.swing.text

Class AbstractDocument.BranchElement

public class AbstractDocument.BranchElement extends AbstractDocument.AbstractElement

An implementation of {@link Element} to represent composite Elements that contain other Elements.
Constructor Summary
BranchElement(Element parent, AttributeSet attributes)
Creates a new BranchElement with the specified parent and attributes.
Method Summary
Enumerationchildren()
Returns the children of this BranchElement.
booleangetAllowsChildren()
Returns true since BranchElements allow child elements.
ElementgetElement(int index)
Returns the child element at the specified index.
intgetElementCount()
Returns the number of child elements of this element.
intgetElementIndex(int offset)
Returns the index of the child element that spans the specified offset in the document model.
intgetEndOffset()
Returns the offset inside the document model that is after the last character of this element.
StringgetName()
Returns the name of this element.
intgetStartOffset()
Returns the start offset of this element inside the document model.
booleanisLeaf()
Returns false since BranchElement are no leafes.
ElementpositionToElement(int position)
Returns the Element at the specified Document offset.
voidreplace(int offset, int length, Element[] elements)
Replaces a set of child elements with a new set of child elemens.
StringtoString()
Returns a string representation of this element.

Constructor Detail

BranchElement

public BranchElement(Element parent, AttributeSet attributes)
Creates a new BranchElement with the specified parent and attributes.

Parameters: parent the parent element of this BranchElement attributes the attributes to set on this BranchElement

Method Detail

children

public Enumeration children()
Returns the children of this BranchElement.

Returns: the children of this BranchElement

getAllowsChildren

public boolean getAllowsChildren()
Returns true since BranchElements allow child elements.

Returns: true since BranchElements allow child elements

getElement

public Element getElement(int index)
Returns the child element at the specified index.

Parameters: index the index of the requested child element

Returns: the requested element

getElementCount

public int getElementCount()
Returns the number of child elements of this element.

Returns: the number of child elements of this element

getElementIndex

public int getElementIndex(int offset)
Returns the index of the child element that spans the specified offset in the document model.

Parameters: offset the offset for which the responsible element is searched

Returns: the index of the child element that spans the specified offset in the document model

getEndOffset

public int getEndOffset()
Returns the offset inside the document model that is after the last character of this element. This is the end offset of the last child element. If this element has no children, this method throws a NullPointerException.

Returns: the offset inside the document model that is after the last character of this element

Throws: NullPointerException if this branch element has no children

getName

public String getName()
Returns the name of this element. This is {@link #ParagraphElementName} in this case.

Returns: the name of this element

getStartOffset

public int getStartOffset()
Returns the start offset of this element inside the document model. This is the start offset of the first child element. If this element has no children, this method throws a NullPointerException.

Returns: the start offset of this element inside the document model

Throws: NullPointerException if this branch element has no children and no startOffset value has been cached

isLeaf

public boolean isLeaf()
Returns false since BranchElement are no leafes.

Returns: false since BranchElement are no leafes

positionToElement

public Element positionToElement(int position)
Returns the Element at the specified Document offset.

Returns: the Element at the specified Document offset

See Also: BranchElement

replace

public void replace(int offset, int length, Element[] elements)
Replaces a set of child elements with a new set of child elemens.

Parameters: offset the start index of the elements to be removed length the number of elements to be removed elements the new elements to be inserted

toString

public String toString()
Returns a string representation of this element.

Returns: a string representation of this element