AbstractDocument.AbstractElement (Java 2 Platform SE 5.0) (original) (raw)


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, Serializable, TreeNode

Implements the abstract part of an element. By default elements support attributes by having a field that represents the immutable part of the current attribute set for the element. The element itself implements MutableAttributeSet which can be used to modify the set by fetching a new immutable set. The immutable sets are provided by the AttributeContext associated with the document.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.


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](../../../javax/swing/text/AbstractDocument.AbstractElement.html#AbstractDocument.AbstractElement%28javax.swing.text.Element, javax.swing.text.AttributeSet%29)(Element parent,AttributeSet a) Creates a new AbstractElement.
Method Summary
void [addAttribute](../../../javax/swing/text/AbstractDocument.AbstractElement.html#addAttribute%28java.lang.Object, java.lang.Object%29)(Object name,Object value) Adds an attribute to the element.
void addAttributes(AttributeSet attr) Adds a set of attributes to the element.
abstract Enumeration children() Returns the children of the receiver as anEnumeration.
boolean [containsAttribute](../../../javax/swing/text/AbstractDocument.AbstractElement.html#containsAttribute%28java.lang.Object, java.lang.Object%29)(Object name,Object value) Checks whether a given attribute name/value is defined.
boolean containsAttributes(AttributeSet attrs) Checks whether the element contains all the attributes.
AttributeSet copyAttributes() Copies a set of attributes.
void [dump](../../../javax/swing/text/AbstractDocument.AbstractElement.html#dump%28java.io.PrintStream, int%29)(PrintStream psOut, int indentAmount) Dumps a debugging representation of the element hierarchy.
abstract boolean getAllowsChildren() Returns true if the receiver allows children.
Object getAttribute(Object attrName) Gets the value of an attribute.
int getAttributeCount() Gets the number of attributes that are defined.
Enumeration<?> getAttributeNames() Gets the names of all attributes.
AttributeSet getAttributes() Gets the attributes for the element.
TreeNode getChildAt(int childIndex) Returns the child TreeNode at index childIndex.
int getChildCount() Returns the number of children TreeNode's receiver contains.
Document getDocument() Retrieves the underlying model.
abstract Element getElement(int index) Gets a child element.
abstract int getElementCount() Gets the number of children for the element.
abstract int getElementIndex(int offset) Gets the child element index closest to the given model offset.
abstract int getEndOffset() Gets the ending offset in the model for the element.
int getIndex(TreeNode node) Returns the index of node in the receivers children.
String getName() Gets the name of the element.
TreeNode getParent() Returns the parent TreeNode of the receiver.
Element getParentElement() Gets the parent of the element.
AttributeSet getResolveParent() Gets the resolving parent.
abstract int getStartOffset() Gets the starting offset in the model for the element.
boolean isDefined(Object attrName) Checks whether a given attribute is defined.
boolean isEqual(AttributeSet attr) Checks whether two attribute sets are equal.
abstract boolean isLeaf() Checks whether the element is a leaf.
void removeAttribute(Object name) Removes an attribute from the set.
void removeAttributes(AttributeSet attrs) Removes a set of attributes for the element.
void removeAttributes(Enumeration<?> names) Removes a set of attributes for the element.
void setResolveParent(AttributeSet parent) Sets the resolving parent.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../../java/lang/Object.html#wait%28long, int%29)
Constructor Detail

AbstractDocument.AbstractElement

public AbstractDocument.AbstractElement(Element parent, AttributeSet a)

Creates a new AbstractElement.

Parameters:

parent - the parent element

a - the attributes for the element

Method Detail

dump

public void dump(PrintStream psOut, int indentAmount)

Dumps a debugging representation of the element hierarchy.

Parameters:

psOut - the output stream

indentAmount - the indentation level >= 0


getAttributeCount

public int getAttributeCount()

Gets the number of attributes that are defined.

Specified by:

[getAttributeCount](../../../javax/swing/text/AttributeSet.html#getAttributeCount%28%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Returns:

the number of attributes >= 0

See Also:

AttributeSet.getAttributeCount()


isDefined

public boolean isDefined(Object attrName)

Checks whether a given attribute is defined.

Specified by:

[isDefined](../../../javax/swing/text/AttributeSet.html#isDefined%28java.lang.Object%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Parameters:

attrName - the non-null attribute name

Returns:

true if the attribute is defined

See Also:

AttributeSet.isDefined(java.lang.Object)


isEqual

public boolean isEqual(AttributeSet attr)

Checks whether two attribute sets are equal.

Specified by:

[isEqual](../../../javax/swing/text/AttributeSet.html#isEqual%28javax.swing.text.AttributeSet%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Parameters:

attr - the attribute set to check against

Returns:

true if the same

See Also:

AttributeSet.isEqual(javax.swing.text.AttributeSet)


copyAttributes

public AttributeSet copyAttributes()

Copies a set of attributes.

Specified by:

[copyAttributes](../../../javax/swing/text/AttributeSet.html#copyAttributes%28%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Returns:

the copy

See Also:

AttributeSet.copyAttributes()


getAttribute

public Object getAttribute(Object attrName)

Gets the value of an attribute.

Specified by:

[getAttribute](../../../javax/swing/text/AttributeSet.html#getAttribute%28java.lang.Object%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Parameters:

attrName - the non-null attribute name

Returns:

the attribute value

See Also:

AttributeSet.getAttribute(java.lang.Object)


getAttributeNames

public Enumeration<?> getAttributeNames()

Gets the names of all attributes.

Specified by:

[getAttributeNames](../../../javax/swing/text/AttributeSet.html#getAttributeNames%28%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Returns:

the attribute names as an enumeration

See Also:

AttributeSet.getAttributeNames()


containsAttribute

public boolean containsAttribute(Object name, Object value)

Checks whether a given attribute name/value is defined.

Specified by:

[containsAttribute](../../../javax/swing/text/AttributeSet.html#containsAttribute%28java.lang.Object, java.lang.Object%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Parameters:

name - the non-null attribute name

value - the attribute value

Returns:

true if the name/value is defined

See Also:

[AttributeSet.containsAttribute(java.lang.Object, java.lang.Object)](../../../javax/swing/text/AttributeSet.html#containsAttribute%28java.lang.Object, java.lang.Object%29)


containsAttributes

public boolean containsAttributes(AttributeSet attrs)

Checks whether the element contains all the attributes.

Specified by:

[containsAttributes](../../../javax/swing/text/AttributeSet.html#containsAttributes%28javax.swing.text.AttributeSet%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Parameters:

attrs - the attributes to check

Returns:

true if the element contains all the attributes

See Also:

AttributeSet.containsAttributes(javax.swing.text.AttributeSet)


getResolveParent

public AttributeSet getResolveParent()

Gets the resolving parent. If not overridden, the resolving parent defaults to the parent element.

Specified by:

[getResolveParent](../../../javax/swing/text/AttributeSet.html#getResolveParent%28%29) in interface [AttributeSet](../../../javax/swing/text/AttributeSet.html "interface in javax.swing.text")

Returns:

the attributes from the parent, null if none

See Also:

AttributeSet.getResolveParent()


addAttribute

public void addAttribute(Object name, Object value)

Adds an attribute to the element.

Specified by:

[addAttribute](../../../javax/swing/text/MutableAttributeSet.html#addAttribute%28java.lang.Object, java.lang.Object%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

name - the non-null attribute name

value - the attribute value

See Also:

[MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)](../../../javax/swing/text/MutableAttributeSet.html#addAttribute%28java.lang.Object, java.lang.Object%29)


addAttributes

public void addAttributes(AttributeSet attr)

Adds a set of attributes to the element.

Specified by:

[addAttributes](../../../javax/swing/text/MutableAttributeSet.html#addAttributes%28javax.swing.text.AttributeSet%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

attr - the attributes to add

See Also:

[MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)](../../../javax/swing/text/MutableAttributeSet.html#addAttribute%28java.lang.Object, java.lang.Object%29)


removeAttribute

public void removeAttribute(Object name)

Removes an attribute from the set.

Specified by:

[removeAttribute](../../../javax/swing/text/MutableAttributeSet.html#removeAttribute%28java.lang.Object%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

name - the non-null attribute name

See Also:

MutableAttributeSet.removeAttribute(java.lang.Object)


removeAttributes

public void removeAttributes(Enumeration<?> names)

Removes a set of attributes for the element.

Specified by:

[removeAttributes](../../../javax/swing/text/MutableAttributeSet.html#removeAttributes%28java.util.Enumeration%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

names - the attribute names

See Also:

MutableAttributeSet.removeAttributes(java.util.Enumeration)


removeAttributes

public void removeAttributes(AttributeSet attrs)

Removes a set of attributes for the element.

Specified by:

[removeAttributes](../../../javax/swing/text/MutableAttributeSet.html#removeAttributes%28javax.swing.text.AttributeSet%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

attrs - the attributes

See Also:

MutableAttributeSet.removeAttributes(java.util.Enumeration)


setResolveParent

public void setResolveParent(AttributeSet parent)

Sets the resolving parent.

Specified by:

[setResolveParent](../../../javax/swing/text/MutableAttributeSet.html#setResolveParent%28javax.swing.text.AttributeSet%29) in interface [MutableAttributeSet](../../../javax/swing/text/MutableAttributeSet.html "interface in javax.swing.text")

Parameters:

parent - the parent, null if none

See Also:

MutableAttributeSet.setResolveParent(javax.swing.text.AttributeSet)


getDocument

public Document getDocument()

Retrieves the underlying model.

Specified by:

[getDocument](../../../javax/swing/text/Element.html#getDocument%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the model


getParentElement

public Element getParentElement()

Gets the parent of the element.

Specified by:

[getParentElement](../../../javax/swing/text/Element.html#getParentElement%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the parent


getAttributes

public AttributeSet getAttributes()

Gets the attributes for the element.

Specified by:

[getAttributes](../../../javax/swing/text/Element.html#getAttributes%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the attribute set


getName

public String getName()

Gets the name of the element.

Specified by:

[getName](../../../javax/swing/text/Element.html#getName%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the name, null if none


getStartOffset

public abstract int getStartOffset()

Gets the starting offset in the model for the element.

Specified by:

[getStartOffset](../../../javax/swing/text/Element.html#getStartOffset%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the offset >= 0

See Also:

Document, AbstractDocument


getEndOffset

public abstract int getEndOffset()

Gets the ending offset in the model for the element.

Specified by:

[getEndOffset](../../../javax/swing/text/Element.html#getEndOffset%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the offset >= 0

See Also:

Document, AbstractDocument


getElement

public abstract Element getElement(int index)

Gets a child element.

Specified by:

[getElement](../../../javax/swing/text/Element.html#getElement%28int%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Parameters:

index - the child index, >= 0 && < getElementCount()

Returns:

the child element


getElementCount

public abstract int getElementCount()

Gets the number of children for the element.

Specified by:

[getElementCount](../../../javax/swing/text/Element.html#getElementCount%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Returns:

the number of children >= 0


getElementIndex

public abstract int getElementIndex(int offset)

Gets the child element index closest to the given model offset.

Specified by:

[getElementIndex](../../../javax/swing/text/Element.html#getElementIndex%28int%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Parameters:

offset - the offset >= 0

Returns:

the element index >= 0


isLeaf

public abstract boolean isLeaf()

Checks whether the element is a leaf.

Specified by:

[isLeaf](../../../javax/swing/text/Element.html#isLeaf%28%29) in interface [Element](../../../javax/swing/text/Element.html "interface in javax.swing.text")

Specified by:

[isLeaf](../../../javax/swing/tree/TreeNode.html#isLeaf%28%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Returns:

true if a leaf


getChildAt

public TreeNode getChildAt(int childIndex)

Returns the child TreeNode at index childIndex.

Specified by:

[getChildAt](../../../javax/swing/tree/TreeNode.html#getChildAt%28int%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")


getChildCount

public int getChildCount()

Returns the number of children TreeNode's receiver contains.

Specified by:

[getChildCount](../../../javax/swing/tree/TreeNode.html#getChildCount%28%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Returns:

the number of children TreeNodews's receiver contains


getParent

public TreeNode getParent()

Returns the parent TreeNode of the receiver.

Specified by:

[getParent](../../../javax/swing/tree/TreeNode.html#getParent%28%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Returns:

the parent TreeNode of the receiver


getIndex

public int getIndex(TreeNode node)

Returns the index of node in the receivers children. If the receiver does not contain node, -1 will be returned.

Specified by:

[getIndex](../../../javax/swing/tree/TreeNode.html#getIndex%28javax.swing.tree.TreeNode%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Parameters:

node - the location of interest

Returns:

the index of node in the receiver's children, or -1 if absent


getAllowsChildren

public abstract boolean getAllowsChildren()

Returns true if the receiver allows children.

Specified by:

[getAllowsChildren](../../../javax/swing/tree/TreeNode.html#getAllowsChildren%28%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Returns:

true if the receiver allows children, otherwise false


children

public abstract Enumeration children()

Returns the children of the receiver as anEnumeration.

Specified by:

[children](../../../javax/swing/tree/TreeNode.html#children%28%29) in interface [TreeNode](../../../javax/swing/tree/TreeNode.html "interface in javax.swing.tree")

Returns:

the children of the receiver as an Enumeration



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.