jdk/src/share/classes/javax/swing/text/html/MuxingAttributeSet.java
author darcy
Wed, 22 Jan 2014 23:20:58 -0800
changeset 22567 5816a47fa4dd
parent 5506 202f599c92aa
child 23697 e556a715949f
permissions -rw-r--r--
8032047: Fix static lint warnings in client libraries 8032048: Add static lint warning to build of jdk repository Reviewed-by: pchelko, serb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An implementation of <code>AttributeSet</code> that can multiplex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * across a set of <code>AttributeSet</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
class MuxingAttributeSet implements AttributeSet, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * Creates a <code>MuxingAttributeSet</code> with the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public MuxingAttributeSet(AttributeSet[] attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        this.attrs = attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Creates an empty <code>MuxingAttributeSet</code>. This is intended for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * use by subclasses only, and it is also intended that subclasses will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * set the constituent <code>AttributeSet</code>s before invoking any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * of the <code>AttributeSet</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected MuxingAttributeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Directly sets the <code>AttributeSet</code>s that comprise this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * <code>MuxingAttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected synchronized void setAttributes(AttributeSet[] attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.attrs = attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Returns the <code>AttributeSet</code>s multiplexing too. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <code>AttributeSet</code>s need to be referenced, this should be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected synchronized AttributeSet[] getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Inserts <code>as</code> at <code>index</code>. This assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * the value of <code>index</code> is between 0 and attrs.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected synchronized void insertAttributeSetAt(AttributeSet as,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                                     int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int numAttrs = attrs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        AttributeSet newAttrs[] = new AttributeSet[numAttrs + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (index < numAttrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            if (index > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                System.arraycopy(attrs, 0, newAttrs, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                System.arraycopy(attrs, index, newAttrs, index + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                 numAttrs - index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                System.arraycopy(attrs, 0, newAttrs, 1, numAttrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            System.arraycopy(attrs, 0, newAttrs, 0, numAttrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        newAttrs[index] = as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        attrs = newAttrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Removes the AttributeSet at <code>index</code>. This assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * the value of <code>index</code> is greater than or equal to 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * and less than attrs.length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected synchronized void removeAttributeSetAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int numAttrs = attrs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        AttributeSet[] newAttrs = new AttributeSet[numAttrs - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (numAttrs > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                // FIRST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                System.arraycopy(attrs, 1, newAttrs, 0, numAttrs - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            else if (index < (numAttrs - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                // MIDDLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                System.arraycopy(attrs, 0, newAttrs, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                System.arraycopy(attrs, index + 1, newAttrs, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                 numAttrs - index - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                // END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                System.arraycopy(attrs, 0, newAttrs, 0, numAttrs - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        attrs = newAttrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    //  --- AttributeSet methods ----------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Gets the number of attributes that are defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return the number of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see AttributeSet#getAttributeCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public int getAttributeCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        AttributeSet[] as = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        for (int i = 0; i < as.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            n += as[i].getAttributeCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Checks whether a given attribute is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * This will convert the key over to CSS if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * key is a StyleConstants key that has a CSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param key the attribute key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return true if the attribute is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see AttributeSet#isDefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public boolean isDefined(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        AttributeSet[] as = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        for (int i = 0; i < as.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (as[i].isDefined(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Checks whether two attribute sets are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param attr the attribute set to check against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return true if the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see AttributeSet#isEqual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean isEqual(AttributeSet attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return ((getAttributeCount() == attr.getAttributeCount()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                containsAttributes(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Copies a set of attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return the copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see AttributeSet#copyAttributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public AttributeSet copyAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        AttributeSet[] as = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        MutableAttributeSet a = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        for (int i = as.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            a.addAttributes(as[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Gets the value of an attribute.  If the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * attribute is a StyleConstants attribute that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * a CSS mapping, the request will be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param key the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see AttributeSet#getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public Object getAttribute(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        AttributeSet[] as = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int n = as.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            Object o = as[i].getAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Gets the names of all attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return the attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see AttributeSet#getAttributeNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public Enumeration getAttributeNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return new MuxingAttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Checks whether a given attribute name/value is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return true if the name/value is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see AttributeSet#containsAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public boolean containsAttribute(Object name, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return value.equals(getAttribute(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Checks whether the attribute set contains all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * the given attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param attrs the attributes to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return true if the element contains all the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see AttributeSet#containsAttributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public boolean containsAttributes(AttributeSet attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        boolean result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Enumeration names = attrs.getAttributeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        while (result && names.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            Object name = names.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            result = attrs.getAttribute(name).equals(getAttribute(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Returns null, subclasses may wish to do something more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * intelligent with this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public AttributeSet getResolveParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * The <code>AttributeSet</code>s that make up the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private AttributeSet[] attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * An Enumeration of the Attribute names in a MuxingAttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * This may return the same name more than once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private class MuxingAttributeNameEnumeration implements Enumeration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        MuxingAttributeNameEnumeration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            updateEnum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (currentEnum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return currentEnum.hasMoreElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        public Object nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (currentEnum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                throw new NoSuchElementException("No more names");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            Object retObject = currentEnum.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (!currentEnum.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                updateEnum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return retObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        void updateEnum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            AttributeSet[] as = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            currentEnum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            while (currentEnum == null && attrIndex < as.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                currentEnum = as[attrIndex++].getAttributeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                if (!currentEnum.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    currentEnum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        /** Index into attrs the current Enumeration came from. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        private int attrIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        /** Enumeration from attrs. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        private Enumeration currentEnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}