javax.swing.text

Class AbstractDocument.AbstractElement

public abstract class AbstractDocument.AbstractElement extends Object implements Element, MutableAttributeSet, TreeNode, Serializable

An abstract base implementation of the {@link Element} interface.
Constructor Summary
AbstractElement(Element p, AttributeSet s)
Creates a new instance of AbstractElement with a specified parent Element and AttributeSet.
Method Summary
voidaddAttribute(Object name, Object value)
Adds an attribute to this element.
voidaddAttributes(AttributeSet attrs)
Adds a set of attributes to this element.
abstract Enumerationchildren()
Returns the child nodes of this Element as an Enumeration of {@link TreeNode}s.
booleancontainsAttribute(Object name, Object value)
Returns true if this element contains the specified attribute.
booleancontainsAttributes(AttributeSet attrs)
Returns true if this element contains all of the specified attributes.
AttributeSetcopyAttributes()
Returns a copy of the attributes of this element.
voiddump(PrintStream stream, int indent)
Prints diagnostic output to the specified stream.
abstract booleangetAllowsChildren()
Returns true if this AbstractElement allows children.
ObjectgetAttribute(Object key)
Returns the attribute value with the specified key.
intgetAttributeCount()
Returns the number of defined attributes in this element.
Enumeration<?>getAttributeNames()
Returns the names of the attributes of this element.
AttributeSetgetAttributes()
Returns the attributes of this element.
TreeNodegetChildAt(int index)
Returns the child of this AbstractElement at index.
intgetChildCount()
Returns the number of children of this AbstractElement.
DocumentgetDocument()
Returns the {@link Document} to which this element belongs.
abstract ElementgetElement(int index)
Returns the child element at the specified index.
abstract intgetElementCount()
Returns the number of child elements of this element.
abstract intgetElementIndex(int offset)
Returns the index of the child element that spans the specified offset in the document model.
abstract intgetEndOffset()
Returns the offset inside the document model that is after the last character of this element.
intgetIndex(TreeNode node)
Returns the index of a given child TreeNode or -1 if node is not a child of this AbstractElement.
StringgetName()
Returns the name of this element.
TreeNodegetParent()
Returns the parent TreeNode of this AbstractElement or null if this element has no parent.
ElementgetParentElement()
Returns the parent element of this element.
AttributeSetgetResolveParent()
Returns the resolve parent of this element.
abstract intgetStartOffset()
Returns the start offset if this element inside the document model.
booleanisDefined(Object attrName)
Returns true if an attribute with the specified name is defined in this element, false otherwise.
booleanisEqual(AttributeSet attrs)
Returns true if the specified AttributeSet is equal to this element's AttributeSet, false otherwise.
abstract booleanisLeaf()
Returns true if this AbstractElement is a leaf element, false otherwise.
voidremoveAttribute(Object name)
Removes an attribute from this element.
voidremoveAttributes(AttributeSet attrs)
Removes a set of attributes from this element.
voidremoveAttributes(Enumeration<?> names)
Removes a set of attribute from this element.
voidsetResolveParent(AttributeSet parent)
Sets the parent attribute set against which the element can resolve attributes that are not defined in itself.

Constructor Detail

AbstractElement

public AbstractElement(Element p, AttributeSet s)
Creates a new instance of AbstractElement with a specified parent Element and AttributeSet.

Parameters: p the parent of this AbstractElement s the attributes to be assigned to this AbstractElement

Method Detail

addAttribute

public void addAttribute(Object name, Object value)
Adds an attribute to this element.

Parameters: name the name of the attribute to be added value the value of the attribute to be added

addAttributes

public void addAttributes(AttributeSet attrs)
Adds a set of attributes to this element.

Parameters: attrs the attributes to be added to this element

children

public abstract Enumeration children()
Returns the child nodes of this Element as an Enumeration of {@link TreeNode}s.

Returns: the child nodes of this Element as an Enumeration of {@link TreeNode}s

containsAttribute

public boolean containsAttribute(Object name, Object value)
Returns true if this element contains the specified attribute.

Parameters: name the name of the attribute to check value the value of the attribute to check

Returns: true if this element contains the specified attribute

containsAttributes

public boolean containsAttributes(AttributeSet attrs)
Returns true if this element contains all of the specified attributes.

Parameters: attrs the attributes to check

Returns: true if this element contains all of the specified attributes

copyAttributes

public AttributeSet copyAttributes()
Returns a copy of the attributes of this element.

Returns: a copy of the attributes of this element

dump

public void dump(PrintStream stream, int indent)
Prints diagnostic output to the specified stream.

Parameters: stream the stream to write to indent the indentation level

getAllowsChildren

public abstract boolean getAllowsChildren()
Returns true if this AbstractElement allows children.

Returns: true if this AbstractElement allows children

getAttribute

public Object getAttribute(Object key)
Returns the attribute value with the specified key. If this attribute is not defined in this element and this element has a resolving parent, the search goes upward to the resolve parent chain.

Parameters: key the key of the requested attribute

Returns: the attribute value for key of null if key is not found locally and cannot be resolved in this element's resolve parents

getAttributeCount

public int getAttributeCount()
Returns the number of defined attributes in this element.

Returns: the number of defined attributes in this element

getAttributeNames

public Enumeration<?> getAttributeNames()
Returns the names of the attributes of this element.

Returns: the names of the attributes of this element

getAttributes

public AttributeSet getAttributes()
Returns the attributes of this element.

Returns: the attributes of this element

getChildAt

public TreeNode getChildAt(int index)
Returns the child of this AbstractElement at index.

Parameters: index the position in the child list of the child element to be returned

Returns: the child of this AbstractElement at index

getChildCount

public int getChildCount()
Returns the number of children of this AbstractElement.

Returns: the number of children of this AbstractElement

getDocument

public Document getDocument()
Returns the {@link Document} to which this element belongs.

Returns: the {@link Document} to which this element belongs

getElement

public abstract 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 abstract int getElementCount()
Returns the number of child elements of this element.

Returns: the number of child elements of this element

getElementIndex

public abstract 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 abstract int getEndOffset()
Returns the offset inside the document model that is after the last character of this element.

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

getIndex

public int getIndex(TreeNode node)
Returns the index of a given child TreeNode or -1 if node is not a child of this AbstractElement.

Parameters: node the node for which the index is requested

Returns: the index of a given child TreeNode or -1 if node is not a child of this AbstractElement

getName

public String getName()
Returns the name of this element.

Returns: the name of this element

getParent

public TreeNode getParent()
Returns the parent TreeNode of this AbstractElement or null if this element has no parent.

Returns: the parent TreeNode of this AbstractElement or null if this element has no parent

getParentElement

public Element getParentElement()
Returns the parent element of this element.

Returns: the parent element of this element

getResolveParent

public AttributeSet getResolveParent()
Returns the resolve parent of this element. This is taken from the AttributeSet, but if this is null, this method instead returns the Element's parent's AttributeSet

Returns: the resolve parent of this element

See Also: setResolveParent

getStartOffset

public abstract int getStartOffset()
Returns the start offset if this element inside the document model.

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

isDefined

public boolean isDefined(Object attrName)
Returns true if an attribute with the specified name is defined in this element, false otherwise.

Parameters: attrName the name of the requested attributes

Returns: true if an attribute with the specified name is defined in this element, false otherwise

isEqual

public boolean isEqual(AttributeSet attrs)
Returns true if the specified AttributeSet is equal to this element's AttributeSet, false otherwise.

Parameters: attrs the attributes to compare this element to

Returns: true if the specified AttributeSet is equal to this element's AttributeSet, false otherwise

isLeaf

public abstract boolean isLeaf()
Returns true if this AbstractElement is a leaf element, false otherwise.

Returns: true if this AbstractElement is a leaf element, false otherwise

removeAttribute

public void removeAttribute(Object name)
Removes an attribute from this element.

Parameters: name the name of the attribute to be removed

removeAttributes

public void removeAttributes(AttributeSet attrs)
Removes a set of attributes from this element.

Parameters: attrs the attributes to be removed

removeAttributes

public void removeAttributes(Enumeration<?> names)
Removes a set of attribute from this element.

Parameters: names the names of the attributes to be removed

setResolveParent

public void setResolveParent(AttributeSet parent)
Sets the parent attribute set against which the element can resolve attributes that are not defined in itself.

Parameters: parent the resolve parent to set