javax.swing.text

Class AbstractDocument.AbstractElement

Enclosing Class:
AbstractDocument
Implemented Interfaces:
AttributeSet, Element, MutableAttributeSet, Serializable, TreeNode
Known Direct Subclasses:
AbstractDocument.BranchElement, AbstractDocument.LeafElement

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

Fields inherited from interface javax.swing.text.AttributeSet

NameAttribute, ResolveAttribute

Constructor Summary

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.
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.
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.
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.
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.
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.
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(Enumeration names)
Removes a set of attribute from this element.
void
removeAttributes(AttributeSet attrs)
Removes a set of attributes 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 Details

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 Details

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


children

public 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


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


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 boolean getAllowsChildren()
Returns true if this AbstractElement allows children.
Specified by:
getAllowsChildren in interface TreeNode

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


getAttributes

public AttributeSet getAttributes()
Returns the attributes of this element.
Specified by:
getAttributes in interface Element

Returns:
the attributes of this element


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


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 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


getElementCount

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


getEndOffset

public 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


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


getName

public String getName()
Returns the name of this element.
Specified by:
getName in interface 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.
Specified by:
getParent in interface TreeNode

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

Returns:
the parent element of this element


getResolveParent

public AttributeSet getResolveParent()
Returns the resolve parent of this element.
Specified by:
getResolveParent in interface AttributeSet

Returns:
the resolve parent of this element

See Also:
setResolveParent(AttributeSet)


getStartOffset

public 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


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


isLeaf

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

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


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(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


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


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


AbstractDocument.java -- Copyright (C) 2002, 2004, 2005 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.