home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / text / AbstractDocument$AbstractElement.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  7.2 KB  |  261 lines

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