javax.swing.text
Class AbstractDocument.BranchElement

java.lang.Object
  extended by javax.swing.text.AbstractDocument.AbstractElement
      extended by javax.swing.text.AbstractDocument.BranchElement
All Implemented Interfaces:
Serializable, AttributeSet, Element, MutableAttributeSet, TreeNode
Direct Known Subclasses:
DefaultStyledDocument.SectionElement, HTMLDocument.BlockElement
Enclosing class:
AbstractDocument

public class AbstractDocument.BranchElement
extends AbstractDocument.AbstractElement

An implementation of Element to represent composite Elements that contain other Elements.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.swing.text.AttributeSet
AttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute
 
Field Summary
 
Fields inherited from interface javax.swing.text.AttributeSet
NameAttribute, ResolveAttribute
 
Constructor Summary
AbstractDocument.BranchElement(Element parent, AttributeSet attributes)
          Creates a new BranchElement with the specified parent and attributes.
 
Method Summary
 Enumeration children()
          Returns the children of this BranchElement.
 boolean getAllowsChildren()
          Returns true since BranchElements allow child elements.
 Element getElement(int index)
          Returns the child element at the specified index.
 int getElementCount()
          Returns the number of child elements of this element.
 int getElementIndex(int offset)
          Returns the index of the child element that spans the specified offset in the document model.
 int getEndOffset()
          Returns the offset inside the document model that is after the last character of this element.
 String getName()
          Returns the name of this element.
 int getStartOffset()
          Returns the start offset of this element inside the document model.
 boolean isLeaf()
          Returns false since BranchElement are no leafes.
 Element positionToElement(int position)
          Returns the Element at the specified Document offset.
 void replace(int offset, int length, Element[] elements)
          Replaces a set of child elements with a new set of child elemens.
 String toString()
          Returns a string representation of this element.
 
Methods inherited from class javax.swing.text.AbstractDocument.AbstractElement
addAttribute, addAttributes, containsAttribute, containsAttributes, copyAttributes, dump, getAttribute, getAttributeCount, getAttributeNames, getAttributes, getChildAt, getChildCount, getDocument, getIndex, getParent, getParentElement, getResolveParent, isDefined, isEqual, removeAttribute, removeAttributes, removeAttributes, setResolveParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDocument.BranchElement

public AbstractDocument.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.

Specified by:
children in interface TreeNode
Specified by:
children in class AbstractDocument.AbstractElement
Returns:
the children of this BranchElement

getAllowsChildren

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

Specified by:
getAllowsChildren in interface TreeNode
Specified by:
getAllowsChildren in class AbstractDocument.AbstractElement
Returns:
true since BranchElements allow child elements

getElement

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

Specified by:
getElement in interface Element
Specified by:
getElement in class AbstractDocument.AbstractElement
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.

Specified by:
getElementCount in interface Element
Specified by:
getElementCount in class AbstractDocument.AbstractElement
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.

Specified by:
getElementIndex in interface Element
Specified by:
getElementIndex in class AbstractDocument.AbstractElement
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.

Specified by:
getEndOffset in interface Element
Specified by:
getEndOffset in class AbstractDocument.AbstractElement
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 AbstractDocument.ParagraphElementName in this case.

Specified by:
getName in interface Element
Overrides:
getName in class AbstractDocument.AbstractElement
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.

Specified by:
getStartOffset in interface Element
Specified by:
getStartOffset in class AbstractDocument.AbstractElement
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.

Specified by:
isLeaf in interface Element
Specified by:
isLeaf in interface TreeNode
Specified by:
isLeaf in class AbstractDocument.AbstractElement
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:
getElementIndex(int)

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.

Overrides:
toString in class Object
Returns:
a string representation of this element
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)