SimpleAttributeSet.java [plain text]
package javax.swing.text;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
public class SimpleAttributeSet
implements MutableAttributeSet, Serializable, Cloneable
{
public static final AttributeSet EMPTY = new SimpleAttributeSet();
Hashtable tab;
public SimpleAttributeSet()
{
this(null);
}
public SimpleAttributeSet(AttributeSet a)
{
tab = new Hashtable();
if (a != null)
addAttributes(a);
}
public void addAttribute(Object name, Object value)
{
tab.put(name, value);
}
public void addAttributes(AttributeSet attributes)
{
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
Object name = e.nextElement();
Object val = attributes.getAttribute(name);
tab.put(name, val);
}
}
public Object clone()
{
SimpleAttributeSet s = new SimpleAttributeSet();
s.tab = (Hashtable) tab.clone();
return s;
}
public boolean containsAttribute(Object name, Object value)
{
return tab.containsKey(name)
&& tab.get(name).equals(value);
}
public boolean containsAttributes(AttributeSet attributes)
{
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
Object name = e.nextElement();
Object val = attributes.getAttribute(name);
if (! containsAttribute(name, val))
return false;
}
return true;
}
public AttributeSet copyAttributes()
{
return (AttributeSet) clone();
}
public boolean equals(Object obj)
{
return (obj != null)
&& (obj instanceof SimpleAttributeSet)
&& ((SimpleAttributeSet)obj).tab.equals(this.tab);
}
public Object getAttribute(Object name)
{
Object val = tab.get(name);
if (val != null)
return val;
Object p = getResolveParent();
if (p != null && p instanceof AttributeSet)
return (((AttributeSet)p).getAttribute(name));
return null;
}
public int getAttributeCount()
{
return tab.size();
}
public Enumeration getAttributeNames()
{
return tab.keys();
}
public AttributeSet getResolveParent()
{
return (AttributeSet) tab.get(ResolveAttribute);
}
public int hashCode()
{
return tab.hashCode();
}
public boolean isDefined(Object attrName)
{
return tab.containsKey(attrName);
}
public boolean isEmpty()
{
return tab.isEmpty();
}
public boolean isEqual(AttributeSet attr)
{
return this.equals(attr);
}
public void removeAttribute(Object name)
{
tab.remove(name);
}
public void removeAttributes(AttributeSet attributes)
{
removeAttributes(attributes.getAttributeNames());
}
public void removeAttributes(Enumeration names)
{
while (names.hasMoreElements())
{
removeAttribute(names.nextElement());
}
}
public void setResolveParent(AttributeSet parent)
{
addAttribute(ResolveAttribute, parent);
}
public String toString()
{
return tab.toString();
}
}