javax.swing.text
Class AbstractDocument.AbstractElement

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

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

An abstract base implementation of the Element interface.

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.AbstractElement(Element p, AttributeSet s)
          Creates a new instance of AbstractElement with a specified parent Element and AttributeSet.
 
Method Summary
 void addAttribute(Object name, Object value)
          Adds an attribute to this element.
 void addAttributes(AttributeSet attrs)
          Adds a set of attributes to this element.
abstract  Enumeration children()
          Returns the child nodes of this Element as an Enumeration of TreeNodes.
 boolean containsAttribute(Object name, Object value)
          Returns true if this element contains the specified attribute.
 boolean containsAttributes(AttributeSet attrs)
          Returns true if this element contains all of the specified attributes.
 AttributeSet copyAttributes()
          Returns a copy of the attributes of this element.
 void dump(PrintStream stream, int indent)
          Prints diagnostic output to the specified stream.
abstract  boolean getAllowsChildren()
          Returns true if this AbstractElement allows children.
 Object getAttribute(Object key)
          Returns the attribute value with the specified key.
 int getAttributeCount()
          Returns the number of defined attributes in this element.
 Enumeration<?> getAttributeNames()
          Returns the names of the attributes of this element.
 AttributeSet getAttributes()
          Returns the attributes of this element.
 TreeNode getChildAt(int index)
          Returns the child of this AbstractElement at index.
 int getChildCount()
          Returns the number of children of this AbstractElement.
 Document getDocument()
          Returns the Document to which this element belongs.
abstract  Element getElement(int index)
          Returns the child element at the specified index.
abstract  int getElementCount()
          Returns the number of child elements of this element.
abstract  int getElementIndex(int offset)
          Returns the index of the child element that spans the specified offset in the document model.
abstract  int getEndOffset()
          Returns the offset inside the document model that is after the last character of this element.
 int getIndex(TreeNode node)
          Returns the index of a given child TreeNode or -1 if node is not a child of this AbstractElement.
 String getName()
          Returns the name of this element.
 TreeNode getParent()
          Returns the parent TreeNode of this AbstractElement or null if this element has no parent.
 Element getParentElement()
          Returns the parent element of this element.
 AttributeSet getResolveParent()
          Returns the resolve parent of this element.
abstract  int getStartOffset()
          Returns the start offset if this element inside the document model.
 boolean isDefined(Object attrName)
          Returns true if an attribute with the specified name is defined in this element, false otherwise.
 boolean isEqual(AttributeSet attrs)
          Returns true if the specified AttributeSet is equal to this element's AttributeSet, false otherwise.
abstract  boolean isLeaf()
          Returns true if this AbstractElement is a leaf element, false otherwise.
 void removeAttribute(Object name)
          Removes an attribute from this element.
 void removeAttributes(AttributeSet attrs)
          Removes a set of attributes from this element.
 void removeAttributes(Enumeration<?> names)
          Removes a set of attribute from this element.
 void setResolveParent(AttributeSet parent)
          Sets the parent attribute set against which the element can resolve attributes that are not defined in itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDocument.AbstractElement

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

children

public abstract Enumeration children()
Returns the child nodes of this Element as an Enumeration of TreeNodes.

Specified by:
children in interface TreeNode
Returns:
the child nodes of this Element as an Enumeration of TreeNodes

getAllowsChildren

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

Specified by:
getAllowsChildren in interface TreeNode
Returns:
true if this AbstractElement allows children

getChildAt

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

Specified by:
getChildAt in interface TreeNode
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.

Specified by:
getChildCount in interface TreeNode
Returns:
the number of children of this AbstractElement

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.

Specified by:
getIndex in interface TreeNode
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

getParent

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

Specified by:
getParent in interface TreeNode
Returns:
the parent TreeNode of this AbstractElement or null if this element has no parent

isLeaf

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

Specified by:
isLeaf in interface Element
Specified by:
isLeaf in interface TreeNode
Returns:
true if this AbstractElement is a leaf element, false otherwise

addAttribute

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

Specified by:
addAttribute in interface MutableAttributeSet
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.

Specified by:
addAttributes in interface MutableAttributeSet
Parameters:
attrs - the attributes to be added to this element

removeAttribute

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

Specified by:
removeAttribute in interface MutableAttributeSet
Parameters:
name - the name of the attribute to be removed

removeAttributes

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

Specified by:
removeAttributes in interface MutableAttributeSet
Parameters:
attrs - the attributes to be removed

removeAttributes

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

Specified by:
removeAttributes in interface MutableAttributeSet
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.

Specified by:
setResolveParent in interface MutableAttributeSet
Parameters:
parent - the resolve parent to set

containsAttribute

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

Specified by:
containsAttribute in interface AttributeSet
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.

Specified by:
containsAttributes in interface AttributeSet
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.

Specified by:
copyAttributes in interface AttributeSet
Returns:
a copy of the attributes of this element

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.

Specified by:
getAttribute in interface AttributeSet
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.

Specified by:
getAttributeCount in interface AttributeSet
Returns:
the number of defined attributes in this element

getAttributeNames

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

Specified by:
getAttributeNames in interface AttributeSet
Returns:
the names of the attributes 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

Specified by:
getResolveParent in interface AttributeSet
Returns:
the resolve parent of this element
See Also:
setResolveParent(AttributeSet)

isDefined

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

Specified by:
isDefined in interface AttributeSet
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.

Specified by:
isEqual in interface AttributeSet
Parameters:
attrs - the attributes to compare this element to
Returns:
true if the specified AttributeSet is equal to this element's AttributeSet, false otherwise

getAttributes

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

Specified by:
getAttributes in interface Element
Returns:
the attributes of this element

getDocument

public Document getDocument()
Returns the Document to which this element belongs.

Specified by:
getDocument in interface Element
Returns:
the Document to which this element belongs

getElement

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

Specified by:
getElement in interface Element
Parameters:
index - the index of the requested child element
Returns:
the requested element

getName

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

Specified by:
getName in interface Element
Returns:
the name of this element

getParentElement

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

Specified by:
getParentElement in interface Element
Returns:
the parent element of this element

getEndOffset

public abstract int getEndOffset()
Returns the offset inside the document model that is after the last character of this element.

Specified by:
getEndOffset in interface Element
Returns:
the offset inside the document model that is after the last character of this element

getElementCount

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

Specified by:
getElementCount in interface 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.

Specified by:
getElementIndex in interface Element
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

getStartOffset

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

Specified by:
getStartOffset in interface Element
Returns:
the start offset if this element inside the document model

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