javax.swing.text

Class AbstractDocument.BranchElement

Enclosing Class:
AbstractDocument
Implemented Interfaces:
AttributeSet, Element, MutableAttributeSet, Serializable, TreeNode
Known Direct Subclasses:
DefaultStyledDocument.SectionElement, HTMLDocument.BlockElement

public class AbstractDocument.BranchElement
extends AbstractDocument.AbstractElement

Implements a composite element that contains other elements.

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

Fields inherited from interface javax.swing.text.AttributeSet

NameAttribute, ResolveAttribute

Constructor Summary

BranchElement(Element parent, AttributeSet a)
Constructs a composite element that initially contains no children.

Method Summary

Enumeration<E>
children()
Returns the children of the receiver as an Enumeration.
boolean
getAllowsChildren()
Returns true if the receiver allows children.
Element
getElement(int index)
Gets a child element.
int
getElementCount()
Gets the number of children for the element.
int
getElementIndex(int offset)
Gets the child element index closest to the given model offset.
int
getEndOffset()
Gets the ending offset in the model for the element.
String
getName()
Gets the element name.
int
getStartOffset()
Gets the starting offset in the model for the element.
boolean
isLeaf()
Checks whether the element is a leaf.
Element
positionToElement(int pos)
Gets the child element that contains the given model position.
void
replace(int offset, int length, Element[] elems)
Replaces content with a new set of elements.
String
toString()
Converts the element to a string.

Methods inherited from class javax.swing.text.AbstractDocument.AbstractElement

addAttribute, addAttributes, children, containsAttribute, containsAttributes, copyAttributes, dump, getAllowsChildren, getAttribute, getAttributeCount, getAttributeNames, getAttributes, getChildAt, getChildCount, getDocument, getElement, getElementCount, getElementIndex, getEndOffset, getIndex, getName, getParent, getParentElement, getResolveParent, getStartOffset, isDefined, isEqual, isLeaf, removeAttribute, removeAttributes, removeAttributes, setResolveParent

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BranchElement

public BranchElement(Element parent,
                     AttributeSet a)
Constructs a composite element that initially contains no children.
Parameters:
parent - The parent element
a - the attributes for the element

Method Details

children

public Enumeration<E> children()
Returns the children of the receiver as an Enumeration.
Specified by:
children in interface TreeNode
Overrides:
children in interface AbstractDocument.AbstractElement
Returns:
the children of the receiver

getAllowsChildren

public boolean getAllowsChildren()
Returns true if the receiver allows children.
Specified by:
getAllowsChildren in interface TreeNode
Overrides:
getAllowsChildren in interface AbstractDocument.AbstractElement
Returns:
true if the receiver allows children, otherwise false

getElement

public Element getElement(int index)
Gets a child element.
Specified by:
getElement in interface Element
Overrides:
getElement in interface AbstractDocument.AbstractElement
Parameters:
index - the child index, >= 0 && <32getElementCount()
Returns:
the child element, null if none

getElementCount

public int getElementCount()
Gets the number of children for the element.
Specified by:
getElementCount in interface Element
Overrides:
getElementCount in interface AbstractDocument.AbstractElement
Returns:
the number of children >= 0

getElementIndex

public int getElementIndex(int offset)
Gets the child element index closest to the given model offset.
Specified by:
getElementIndex in interface Element
Overrides:
getElementIndex in interface AbstractDocument.AbstractElement
Parameters:
offset - the offset >= 0
Returns:
the element index >= 0

getEndOffset

public int getEndOffset()
Gets the ending offset in the model for the element.
Specified by:
getEndOffset in interface Element
Overrides:
getEndOffset in interface AbstractDocument.AbstractElement
Returns:
the offset >= 0
Throws:
NullPointerException - if this element has no children

getName

public String getName()
Gets the element name.
Specified by:
getName in interface Element
Overrides:
getName in interface AbstractDocument.AbstractElement
Returns:
the element name

getStartOffset

public int getStartOffset()
Gets the starting offset in the model for the element.
Specified by:
getStartOffset in interface Element
Overrides:
getStartOffset in interface AbstractDocument.AbstractElement
Returns:
the offset >= 0

isLeaf

public boolean isLeaf()
Checks whether the element is a leaf.
Specified by:
isLeaf in interface Element
isLeaf in interface TreeNode
Overrides:
isLeaf in interface AbstractDocument.AbstractElement
Returns:
true if a leaf

positionToElement

public Element positionToElement(int pos)
Gets the child element that contains the given model position.
Parameters:
pos - the position >= 0
Returns:
the element, null if none

replace

public void replace(int offset,
                    int length,
                    Element[] elems)
Replaces content with a new set of elements.
Parameters:
offset - the starting offset >= 0
length - the length to replace >= 0
elems - the new elements

toString

public String toString()
Converts the element to a string.
Overrides:
toString in interface Object
Returns:
the string