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

An implementation of Element to represent composite Elements that contain other Elements.
See Also:
Serialized Form

Fields inherited from interface javax.swing.text.AttributeSet

NameAttribute, ResolveAttribute

Constructor Summary

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

Method Summary

Enumeration<E>
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, 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 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 Details

children

public Enumeration<E> children()
Returns the children of this BranchElement.
Overrides:
children in interface 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
Overrides:
getAllowsChildren in interface 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
Overrides:
getElement in interface 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
Overrides:
getElementCount in interface 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
Overrides:
getElementIndex in interface 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
Overrides:
getEndOffset in interface 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.BranchElement in this case.
Specified by:
getName in interface Element
Overrides:
getName in interface 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
Overrides:
getStartOffset in interface 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
isLeaf in interface TreeNode
Overrides:
isLeaf in interface 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

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 interface Object
Returns:
a string representation of this element

AbstractDocument.java -- Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.