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