FileDocCategorySizeDatePackage
MuxingAttributeSet.javaAPI DocJava SE 5 API8801Fri Aug 26 14:58:18 BST 2005javax.swing.text.html

MuxingAttributeSet

public class MuxingAttributeSet extends Object implements Serializable, AttributeSet
An implementation of AttributeSet that can multiplex across a set of AttributeSets.
version
1.4 12/19/03

Fields Summary
private AttributeSet[]
attrs
The AttributeSets that make up the resulting AttributeSet.
Constructors Summary
public MuxingAttributeSet(AttributeSet[] attrs)
Creates a MuxingAttributeSet with the passed in attributes.

        this.attrs = attrs;
    
protected MuxingAttributeSet()
Creates an empty MuxingAttributeSet. This is intended for use by subclasses only, and it is also intended that subclasses will set the constituent AttributeSets before invoking any of the AttributeSet methods.

    
Methods Summary
public booleancontainsAttribute(java.lang.Object name, java.lang.Object value)
Checks whether a given attribute name/value is defined.

param
name the attribute name
param
value the attribute value
return
true if the name/value is defined
see
AttributeSet#containsAttribute

        return value.equals(getAttribute(name));
    
public booleancontainsAttributes(javax.swing.text.AttributeSet attrs)
Checks whether the attribute set contains all of the given attributes.

param
attrs the attributes to check
return
true if the element contains all the attributes
see
AttributeSet#containsAttributes

        boolean result = true;

        Enumeration names = attrs.getAttributeNames();
        while (result && names.hasMoreElements()) {
            Object name = names.nextElement();
            result = attrs.getAttribute(name).equals(getAttribute(name));
        }

        return result;
    
public javax.swing.text.AttributeSetcopyAttributes()
Copies a set of attributes.

return
the copy
see
AttributeSet#copyAttributes

        AttributeSet[] as = getAttributes();
        MutableAttributeSet a = new SimpleAttributeSet();
        int n = 0;
        for (int i = as.length - 1; i >= 0; i--) {
            a.addAttributes(as[i]);
        }
        return a;
    
public java.lang.ObjectgetAttribute(java.lang.Object key)
Gets the value of an attribute. If the requested attribute is a StyleConstants attribute that has a CSS mapping, the request will be converted.

param
key the attribute name
return
the attribute value
see
AttributeSet#getAttribute

        AttributeSet[] as = getAttributes();
        int n = as.length;
        for (int i = 0; i < n; i++) {
            Object o = as[i].getAttribute(key);
            if (o != null) {
                return o;
            }
        }
        return null;
    
public intgetAttributeCount()
Gets the number of attributes that are defined.

return
the number of attributes
see
AttributeSet#getAttributeCount

        AttributeSet[] as = getAttributes();
        int n = 0;
        for (int i = 0; i < as.length; i++) {
            n += as[i].getAttributeCount();
        }
        return n;
    
public java.util.EnumerationgetAttributeNames()
Gets the names of all attributes.

return
the attribute names
see
AttributeSet#getAttributeNames

        return new MuxingAttributeNameEnumeration();
    
protected synchronized javax.swing.text.AttributeSet[]getAttributes()
Returns the AttributeSets multiplexing too. When the AttributeSets need to be referenced, this should be called.

        return attrs;
    
public javax.swing.text.AttributeSetgetResolveParent()
Returns null, subclasses may wish to do something more intelligent with this.

        return null;
    
protected synchronized voidinsertAttributeSetAt(javax.swing.text.AttributeSet as, int index)
Inserts as at index. This assumes the value of index is between 0 and attrs.length, inclusive.

        int numAttrs = attrs.length;
        AttributeSet newAttrs[] = new AttributeSet[numAttrs + 1];
        if (index < numAttrs) {
            if (index > 0) {
                System.arraycopy(attrs, 0, newAttrs, 0, index);
                System.arraycopy(attrs, index, newAttrs, index + 1,
                                 numAttrs - index);
            }
            else {
                System.arraycopy(attrs, 0, newAttrs, 1, numAttrs);
            }
        }
        else {
            System.arraycopy(attrs, 0, newAttrs, 0, numAttrs);
        }
        newAttrs[index] = as;
        attrs = newAttrs;
    
public booleanisDefined(java.lang.Object key)
Checks whether a given attribute is defined. This will convert the key over to CSS if the key is a StyleConstants key that has a CSS mapping.

param
key the attribute key
return
true if the attribute is defined
see
AttributeSet#isDefined

        AttributeSet[] as = getAttributes();
        for (int i = 0; i < as.length; i++) {
            if (as[i].isDefined(key)) {
                return true;
            }
        }
        return false;
    
public booleanisEqual(javax.swing.text.AttributeSet attr)
Checks whether two attribute sets are equal.

param
attr the attribute set to check against
return
true if the same
see
AttributeSet#isEqual

        return ((getAttributeCount() == attr.getAttributeCount()) &&
                containsAttributes(attr));
    
protected synchronized voidremoveAttributeSetAt(int index)
Removes the AttributeSet at index. This assumes the value of index is greater than or equal to 0, and less than attrs.length.

        int numAttrs = attrs.length;
        AttributeSet[] newAttrs = new AttributeSet[numAttrs - 1];
        if (numAttrs > 0) {
            if (index == 0) {
                // FIRST
                System.arraycopy(attrs, 1, newAttrs, 0, numAttrs - 1);
            }
            else if (index < (numAttrs - 1)) {
                // MIDDLE
                System.arraycopy(attrs, 0, newAttrs, 0, index);
                System.arraycopy(attrs, index + 1, newAttrs, index,
                                 numAttrs - index - 1);
            }
            else {
                // END
                System.arraycopy(attrs, 0, newAttrs, 0, numAttrs - 1);
            }
        }
        attrs = newAttrs;
    
protected synchronized voidsetAttributes(javax.swing.text.AttributeSet[] attrs)
Directly sets the AttributeSets that comprise this MuxingAttributeSet.

        this.attrs = attrs;