Java Reference
In-Depth Information
AttributeSet Interface
The
AttributeSet
interface describes a read-only set of key/value attributes, allowing you
access to the descriptive content of a series of attributes. If the set of attributes lacks a specific
key defined for it, the
AttributeSet
supports the ability to look elsewhere by traveling up a chain
to a resolving parent for the parent's definition of the attribute. This allows the
AttributeSet
to
define a core set of attributes and lets developers (or possibly even users) modify only the set of
attributes they want to change. Unless you want someone to change the defaults globally, you
shouldn't provide direct access to the resolving parent. That way, you never lose any of the
original settings.
public interface AttributeSet {
// Constants
public final static Object NameAttribute;
public final static Object ResolveAttribute;
// Properties
public int getAttributeCount();
public Enumeration getAttributeNames();
public AttributeSet getResolveParent();
// Other methods
public boolean containsAttribute(Object name, Object value);
public boolean containsAttributes(AttributeSet attributes);
public AttributeSet copyAttributes();
public Object getAttribute(Object key);
public boolean isDefined(Object attrName);
public boolean isEqual(AttributeSet attr);
}
MutableAttributeSet Interface
The
MutableAttributeSet
interface describes how you would go about adding to or removing
from the set of attributes, as well as how to set the resolving parent.
public interface MutableAttributeSet extends AttributeSet {
public void addAttribute(Object name, Object value);
public void addAttributes(AttributeSet attributes);
public void removeAttribute(Object name);
public void removeAttributes(AttributeSet attributes);
public void removeAttributes(Enumeration names);
public void setResolveParent(AttributeSet parent);
}
SimpleAttributeSet Class
The
SimpleAttributeSet
class is the first implementation of the
AttributeSet
interface. When
you begin using it, you'll finally be able to see just how to create the multiple-attributed text
for display in the
JTextPane
. The
SimpleAttributeSet
class is a specific implementation of
AttributeSet
that relies on a standard
Hashtable
for managing the key/attribute pairs.