1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: public class SimpleAttributeSet
46: implements MutableAttributeSet, Serializable, Cloneable
47: {
48:
49: private static final long serialVersionUID = 8267656273837665219L;
50:
51: public static final AttributeSet EMPTY = new SimpleAttributeSet();
52:
53: Hashtable tab;
54:
55: public SimpleAttributeSet()
56: {
57: this(null);
58: }
59:
60: public SimpleAttributeSet(AttributeSet a)
61: {
62: tab = new Hashtable();
63: if (a != null)
64: addAttributes(a);
65: }
66:
67: public void addAttribute(Object name, Object value)
68: {
69: tab.put(name, value);
70: }
71:
72: public void addAttributes(AttributeSet attributes)
73: {
74: Enumeration e = attributes.getAttributeNames();
75: while (e.hasMoreElements())
76: {
77: Object name = e.nextElement();
78: Object val = attributes.getAttribute(name);
79: tab.put(name, val);
80: }
81: }
82:
83: public Object clone()
84: {
85: SimpleAttributeSet s = new SimpleAttributeSet();
86: s.tab = (Hashtable) tab.clone();
87: return s;
88: }
89:
90:
98: public boolean containsAttribute(Object name, Object value)
99: {
100: return (tab.containsKey(name) && tab.get(name).equals(value)) ||
101: (getResolveParent() != null && getResolveParent().
102: containsAttribute(name, value));
103: }
104:
105:
112: boolean containsAttributeLocally(Object name, Object value)
113: {
114: return tab.containsKey(name)
115: && tab.get(name).equals(value);
116: }
117:
118: public boolean containsAttributes(AttributeSet attributes)
119: {
120: Enumeration e = attributes.getAttributeNames();
121: while (e.hasMoreElements())
122: {
123: Object name = e.nextElement();
124: Object val = attributes.getAttribute(name);
125: if (! containsAttribute(name, val))
126: return false;
127: }
128: return true;
129: }
130:
131: public AttributeSet copyAttributes()
132: {
133: return (AttributeSet) clone();
134: }
135:
136: public boolean equals(Object obj)
137: {
138: return
139: (obj instanceof AttributeSet)
140: && this.isEqual((AttributeSet) obj);
141: }
142:
143: public Object getAttribute(Object name)
144: {
145: Object val = tab.get(name);
146: if (val != null)
147: return val;
148:
149: Object p = getResolveParent();
150: if (p != null && p instanceof AttributeSet)
151: return (((AttributeSet)p).getAttribute(name));
152:
153: return null;
154: }
155:
156: public int getAttributeCount()
157: {
158: return tab.size();
159: }
160:
161: public Enumeration getAttributeNames()
162: {
163: return tab.keys();
164: }
165:
166: public AttributeSet getResolveParent()
167: {
168: return (AttributeSet) tab.get(ResolveAttribute);
169: }
170:
171: public int hashCode()
172: {
173: return tab.hashCode();
174: }
175:
176: public boolean isDefined(Object attrName)
177: {
178: return tab.containsKey(attrName);
179: }
180:
181: public boolean isEmpty()
182: {
183: return tab.isEmpty();
184: }
185:
186:
191: public boolean isEqual(AttributeSet attr)
192: {
193: return getAttributeCount() == attr.getAttributeCount()
194: && this.containsAttributes(attr);
195: }
196:
197: public void removeAttribute(Object name)
198: {
199: tab.remove(name);
200: }
201:
202:
207: public void removeAttributes(AttributeSet attributes)
208: {
209: Enumeration e = attributes.getAttributeNames();
210: while (e.hasMoreElements())
211: {
212: Object name = e.nextElement();
213: Object val = attributes.getAttribute(name);
214: if (containsAttributeLocally(name, val))
215: removeAttribute(name);
216: }
217: }
218:
219: public void removeAttributes(Enumeration names)
220: {
221: while (names.hasMoreElements())
222: {
223: removeAttribute(names.nextElement());
224: }
225: }
226:
227: public void setResolveParent(AttributeSet parent)
228: {
229: addAttribute(ResolveAttribute, parent);
230: }
231:
232: public String toString()
233: {
234: return tab.toString();
235: }
236: }