home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / text / SimpleAttributeSet.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  3.5 KB  |  140 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Enumeration;
  5. import java.util.Hashtable;
  6.  
  7. public class SimpleAttributeSet implements MutableAttributeSet, Serializable {
  8.    public static final AttributeSet EMPTY = new SimpleAttributeSet();
  9.    private Hashtable table = new Hashtable(3);
  10.  
  11.    public SimpleAttributeSet() {
  12.    }
  13.  
  14.    public SimpleAttributeSet(AttributeSet var1) {
  15.       this.addAttributes(var1);
  16.    }
  17.  
  18.    private SimpleAttributeSet(Hashtable var1) {
  19.       this.table = var1;
  20.    }
  21.  
  22.    public boolean isEmpty() {
  23.       return this.table.isEmpty();
  24.    }
  25.  
  26.    public int getAttributeCount() {
  27.       return this.table.size();
  28.    }
  29.  
  30.    public boolean isDefined(Object var1) {
  31.       return this.table.containsKey(var1);
  32.    }
  33.  
  34.    public boolean isEqual(AttributeSet var1) {
  35.       return this.getAttributeCount() == var1.getAttributeCount() && this.containsAttributes(var1);
  36.    }
  37.  
  38.    public AttributeSet copyAttributes() {
  39.       return (AttributeSet)this.clone();
  40.    }
  41.  
  42.    public Enumeration getAttributeNames() {
  43.       return this.table.keys();
  44.    }
  45.  
  46.    public Object getAttribute(Object var1) {
  47.       Object var2 = this.table.get(var1);
  48.       if (var2 == null) {
  49.          AttributeSet var3 = this.getResolveParent();
  50.          if (var3 != null) {
  51.             var2 = var3.getAttribute(var1);
  52.          }
  53.       }
  54.  
  55.       return var2;
  56.    }
  57.  
  58.    public boolean containsAttribute(Object var1, Object var2) {
  59.       return var2.equals(this.getAttribute(var1));
  60.    }
  61.  
  62.    public boolean containsAttributes(AttributeSet var1) {
  63.       boolean var2 = true;
  64.  
  65.       Object var4;
  66.       for(Enumeration var3 = var1.getAttributeNames(); var2 && var3.hasMoreElements(); var2 = var1.getAttribute(var4).equals(this.getAttribute(var4))) {
  67.          var4 = var3.nextElement();
  68.       }
  69.  
  70.       return var2;
  71.    }
  72.  
  73.    public void addAttribute(Object var1, Object var2) {
  74.       this.table.put(var1, var2);
  75.    }
  76.  
  77.    public void addAttributes(AttributeSet var1) {
  78.       Enumeration var2 = var1.getAttributeNames();
  79.  
  80.       while(var2.hasMoreElements()) {
  81.          Object var3 = var2.nextElement();
  82.          this.addAttribute(var3, var1.getAttribute(var3));
  83.       }
  84.  
  85.    }
  86.  
  87.    public void removeAttribute(Object var1) {
  88.       this.table.remove(var1);
  89.    }
  90.  
  91.    public void removeAttributes(Enumeration var1) {
  92.       while(var1.hasMoreElements()) {
  93.          this.removeAttribute(var1.nextElement());
  94.       }
  95.  
  96.    }
  97.  
  98.    public void removeAttributes(AttributeSet var1) {
  99.       Enumeration var2 = var1.getAttributeNames();
  100.  
  101.       while(var2.hasMoreElements()) {
  102.          Object var3 = var2.nextElement();
  103.          Object var4 = var1.getAttribute(var3);
  104.          if (var4.equals(this.getAttribute(var3))) {
  105.             this.removeAttribute(var3);
  106.          }
  107.       }
  108.  
  109.    }
  110.  
  111.    public Object clone() {
  112.       return new SimpleAttributeSet((Hashtable)this.table.clone());
  113.    }
  114.  
  115.    public AttributeSet getResolveParent() {
  116.       return (AttributeSet)this.table.get(StyleConstants.ResolveAttribute);
  117.    }
  118.  
  119.    public void setResolveParent(AttributeSet var1) {
  120.       this.addAttribute(StyleConstants.ResolveAttribute, var1);
  121.    }
  122.  
  123.    public String toString() {
  124.       String var1 = "";
  125.       Enumeration var2 = this.getAttributeNames();
  126.  
  127.       while(var2.hasMoreElements()) {
  128.          String var3 = var2.nextElement().toString();
  129.          Object var4 = this.getAttribute(var3);
  130.          if (var4 instanceof AttributeSet) {
  131.             var1 = var1 + var3 + "=**AttributeSet** ";
  132.          } else {
  133.             var1 = var1 + var3 + "=" + var4 + " ";
  134.          }
  135.       }
  136.  
  137.       return var1;
  138.    }
  139. }
  140.