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

  1. package com.sun.java.swing.text;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.io.PrintStream;
  7. import java.io.Serializable;
  8. import java.util.Enumeration;
  9.  
  10. public abstract class AbstractDocument$AbstractElement implements Element, MutableAttributeSet, Serializable {
  11.    // $FF: synthetic field
  12.    private final AbstractDocument this$0;
  13.    private Element parent;
  14.    private transient AttributeSet attributes;
  15.  
  16.    public AbstractDocument$AbstractElement(AbstractDocument var1, Element var2, AttributeSet var3) {
  17.       this.this$0 = var1;
  18.       this.this$0 = var1;
  19.       this.attributes = var3 != null ? var3.copyAttributes() : var1.getAttributeContext().getEmptySet();
  20.       this.parent = var2;
  21.    }
  22.  
  23.    private final void indent(PrintStream var1, int var2) {
  24.       for(int var3 = 0; var3 < var2; ++var3) {
  25.          var1.print("  ");
  26.       }
  27.  
  28.    }
  29.  
  30.    public void dump(PrintStream var1, int var2) {
  31.       this.indent(var1, var2);
  32.       if (this.getName() == null) {
  33.          var1.print("<??");
  34.       } else {
  35.          var1.print("<" + this.getName());
  36.       }
  37.  
  38.       if (this.getAttributeCount() > 0) {
  39.          var1.println("");
  40.          Enumeration var3 = this.attributes.getAttributeNames();
  41.  
  42.          while(var3.hasMoreElements()) {
  43.             Object var4 = var3.nextElement();
  44.             this.indent(var1, var2 + 1);
  45.             var1.println(var4 + "=" + this.getAttribute(var4));
  46.          }
  47.  
  48.          this.indent(var1, var2);
  49.       }
  50.  
  51.       var1.println(">");
  52.       if (this.isLeaf()) {
  53.          this.indent(var1, var2 + 1);
  54.          var1.print("[" + this.getStartOffset() + "," + this.getEndOffset() + "]");
  55.          AbstractDocument.Content var8 = this.this$0.getContent();
  56.  
  57.          try {
  58.             String var10 = var8.getString(this.getStartOffset(), this.getEndOffset() - this.getStartOffset()).trim();
  59.             if (var10.length() > 40) {
  60.                var10 = var10.substring(0, 40) + "...";
  61.             }
  62.  
  63.             var1.println(var10);
  64.          } catch (BadLocationException var6) {
  65.          }
  66.       } else {
  67.          int var7 = this.getElementCount();
  68.  
  69.          for(int var9 = 0; var9 < var7; ++var9) {
  70.             AbstractDocument$AbstractElement var5 = (AbstractDocument$AbstractElement)this.getElement(var9);
  71.             var5.dump(var1, var2 + 1);
  72.          }
  73.  
  74.       }
  75.    }
  76.  
  77.    protected void finalize() throws Throwable {
  78.       AbstractDocument.AttributeContext var1 = this.this$0.getAttributeContext();
  79.       var1.reclaim(this.attributes);
  80.    }
  81.  
  82.    public int getAttributeCount() {
  83.       return this.attributes.getAttributeCount();
  84.    }
  85.  
  86.    public boolean isDefined(Object var1) {
  87.       return this.attributes.isDefined(var1);
  88.    }
  89.  
  90.    public boolean isEqual(AttributeSet var1) {
  91.       return this.attributes.isEqual(var1);
  92.    }
  93.  
  94.    public AttributeSet copyAttributes() {
  95.       return this.attributes;
  96.    }
  97.  
  98.    public Object getAttribute(Object var1) {
  99.       Object var2 = this.attributes.getAttribute(var1);
  100.       if (var2 == null) {
  101.          AttributeSet var3 = this.getResolveParent();
  102.          if (var3 != null) {
  103.             var2 = var3.getAttribute(var1);
  104.          }
  105.       }
  106.  
  107.       return var2;
  108.    }
  109.  
  110.    public Enumeration getAttributeNames() {
  111.       return this.attributes.getAttributeNames();
  112.    }
  113.  
  114.    public boolean containsAttribute(Object var1, Object var2) {
  115.       return this.attributes.containsAttribute(var1, var2);
  116.    }
  117.  
  118.    public boolean containsAttributes(AttributeSet var1) {
  119.       return this.attributes.containsAttributes(var1);
  120.    }
  121.  
  122.    public AttributeSet getResolveParent() {
  123.       AttributeSet var1 = this.attributes.getResolveParent();
  124.       if (var1 == null && this.parent != null) {
  125.          var1 = this.parent.getAttributes();
  126.       }
  127.  
  128.       return var1;
  129.    }
  130.  
  131.    public void addAttribute(Object var1, Object var2) {
  132.       this.checkForIllegalCast();
  133.       AbstractDocument.AttributeContext var3 = this.this$0.getAttributeContext();
  134.       this.attributes = var3.addAttribute(this.attributes, var1, var2);
  135.    }
  136.  
  137.    public void addAttributes(AttributeSet var1) {
  138.       this.checkForIllegalCast();
  139.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  140.       this.attributes = var2.addAttributes(this.attributes, var1);
  141.    }
  142.  
  143.    public void removeAttribute(Object var1) {
  144.       this.checkForIllegalCast();
  145.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  146.       this.attributes = var2.removeAttribute(this.attributes, var1);
  147.    }
  148.  
  149.    public void removeAttributes(Enumeration var1) {
  150.       this.checkForIllegalCast();
  151.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  152.       this.attributes = var2.removeAttributes(this.attributes, var1);
  153.    }
  154.  
  155.    public void removeAttributes(AttributeSet var1) {
  156.       this.checkForIllegalCast();
  157.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  158.       if (var1 == this) {
  159.          this.attributes = var2.getEmptySet();
  160.       } else {
  161.          this.attributes = var2.removeAttributes(this.attributes, var1);
  162.       }
  163.    }
  164.  
  165.    public void setResolveParent(AttributeSet var1) {
  166.       this.checkForIllegalCast();
  167.       AbstractDocument.AttributeContext var2 = this.this$0.getAttributeContext();
  168.       if (var1 != null) {
  169.          this.attributes = var2.addAttribute(this.attributes, StyleConstants.ResolveAttribute, var1);
  170.       } else {
  171.          this.attributes = var2.removeAttribute(this.attributes, StyleConstants.ResolveAttribute);
  172.       }
  173.    }
  174.  
  175.    private final void checkForIllegalCast() {
  176.       Thread var1 = this.this$0.getCurrentWriter();
  177.       if (var1 == null || var1 != Thread.currentThread()) {
  178.          throw new StateInvariantError("Illegal cast to MutableAttributeSet");
  179.       }
  180.    }
  181.  
  182.    public Document getDocument() {
  183.       return this.this$0;
  184.    }
  185.  
  186.    public Element getParentElement() {
  187.       return this.parent;
  188.    }
  189.  
  190.    public AttributeSet getAttributes() {
  191.       return this;
  192.    }
  193.  
  194.    public String getName() {
  195.       return this.attributes.isDefined("$ename") ? (String)this.attributes.getAttribute("$ename") : null;
  196.    }
  197.  
  198.    public abstract int getStartOffset();
  199.  
  200.    public abstract int getEndOffset();
  201.  
  202.    public abstract Element getElement(int var1);
  203.  
  204.    public abstract int getElementCount();
  205.  
  206.    public abstract int getElementIndex(int var1);
  207.  
  208.    public abstract boolean isLeaf();
  209.  
  210.    private void writeObject(ObjectOutputStream var1) throws IOException {
  211.       var1.defaultWriteObject();
  212.       StyleContext.writeAttributeSet(var1, this.attributes);
  213.    }
  214.  
  215.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  216.       var1.defaultReadObject();
  217.       SimpleAttributeSet var2 = new SimpleAttributeSet();
  218.       StyleContext.readAttributeSet(var1, var2);
  219.       AbstractDocument.AttributeContext var3 = this.this$0.getAttributeContext();
  220.       this.attributes = var3.addAttributes(SimpleAttributeSet.EMPTY, var2);
  221.    }
  222. }
  223.