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 / rtf / RTFReader$AttributeTrackingDestination.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  6.5 KB  |  371 lines

  1. package javax.swing.text.rtf;
  2.  
  3. import java.awt.Color;
  4. import java.util.Dictionary;
  5. import java.util.Enumeration;
  6. import java.util.Hashtable;
  7. import javax.swing.text.AttributeSet;
  8. import javax.swing.text.MutableAttributeSet;
  9. import javax.swing.text.SimpleAttributeSet;
  10. import javax.swing.text.Style;
  11. import javax.swing.text.StyleConstants;
  12. import javax.swing.text.TabStop;
  13.  
  14. abstract class RTFReader$AttributeTrackingDestination implements RTFReader.Destination {
  15.    MutableAttributeSet characterAttributes;
  16.    MutableAttributeSet paragraphAttributes;
  17.    MutableAttributeSet sectionAttributes;
  18.    // $FF: synthetic field
  19.    private final RTFReader this$0;
  20.  
  21.    public RTFReader$AttributeTrackingDestination(RTFReader var1) {
  22.       this.this$0 = var1;
  23.       this.characterAttributes = this.rootCharacterAttributes();
  24.       var1.parserState.put("chr", this.characterAttributes);
  25.       this.paragraphAttributes = this.rootParagraphAttributes();
  26.       var1.parserState.put("pgf", this.paragraphAttributes);
  27.       this.sectionAttributes = this.rootSectionAttributes();
  28.       var1.parserState.put("sec", this.sectionAttributes);
  29.    }
  30.  
  31.    public abstract void handleText(String var1);
  32.  
  33.    public void handleBinaryBlob(byte[] var1) {
  34.       this.this$0.warning("Unexpected binary data in RTF file.");
  35.    }
  36.  
  37.    public void begingroup() {
  38.       MutableAttributeSet var1 = this.currentTextAttributes();
  39.       MutableAttributeSet var2 = this.currentParagraphAttributes();
  40.       AttributeSet var3 = this.currentSectionAttributes();
  41.       this.characterAttributes = new SimpleAttributeSet();
  42.       this.characterAttributes.addAttributes(var1);
  43.       this.this$0.parserState.put("chr", this.characterAttributes);
  44.       this.paragraphAttributes = new SimpleAttributeSet();
  45.       this.paragraphAttributes.addAttributes(var2);
  46.       this.this$0.parserState.put("pgf", this.paragraphAttributes);
  47.       this.sectionAttributes = new SimpleAttributeSet();
  48.       this.sectionAttributes.addAttributes(var3);
  49.       this.this$0.parserState.put("sec", this.sectionAttributes);
  50.    }
  51.  
  52.    public void endgroup(Dictionary var1) {
  53.       this.characterAttributes = (MutableAttributeSet)this.this$0.parserState.get("chr");
  54.       this.paragraphAttributes = (MutableAttributeSet)this.this$0.parserState.get("pgf");
  55.       this.sectionAttributes = (MutableAttributeSet)this.this$0.parserState.get("sec");
  56.    }
  57.  
  58.    public void close() {
  59.    }
  60.  
  61.    public boolean handleKeyword(String var1) {
  62.       if (var1.equals("ulnone")) {
  63.          return this.handleKeyword("ul", 0);
  64.       } else {
  65.          Object var2 = RTFReader.access$100().get(var1);
  66.          if (var2 != null) {
  67.             RTFAttribute var3 = (RTFAttribute)var2;
  68.             boolean var4;
  69.             switch (var3.domain()) {
  70.                case 0:
  71.                   var4 = var3.set(this.characterAttributes);
  72.                   break;
  73.                case 1:
  74.                   var4 = var3.set(this.paragraphAttributes);
  75.                   break;
  76.                case 2:
  77.                   var4 = var3.set(this.sectionAttributes);
  78.                   break;
  79.                case 3:
  80.                   var4 = var3.set(this.this$0.documentAttributes);
  81.                   break;
  82.                case 4:
  83.                   RTFReader.access$200(this.this$0).backing = this.this$0.parserState;
  84.                   var4 = var3.set(RTFReader.access$200(this.this$0));
  85.                   RTFReader.access$200(this.this$0).backing = null;
  86.                   break;
  87.                default:
  88.                   var4 = false;
  89.             }
  90.  
  91.             if (var4) {
  92.                return true;
  93.             }
  94.          }
  95.  
  96.          if (var1.equals("plain")) {
  97.             this.resetCharacterAttributes();
  98.             return true;
  99.          } else if (var1.equals("pard")) {
  100.             this.resetParagraphAttributes();
  101.             return true;
  102.          } else if (var1.equals("sectd")) {
  103.             this.resetSectionAttributes();
  104.             return true;
  105.          } else {
  106.             return false;
  107.          }
  108.       }
  109.    }
  110.  
  111.    public boolean handleKeyword(String var1, int var2) {
  112.       boolean var3 = var2 != 0;
  113.       if (var1.equals("fc")) {
  114.          var1 = "cf";
  115.       }
  116.  
  117.       if (var1.equals("f")) {
  118.          this.this$0.parserState.put(var1, new Integer(var2));
  119.          return true;
  120.       } else if (var1.equals("cf")) {
  121.          this.this$0.parserState.put(var1, new Integer(var2));
  122.          return true;
  123.       } else {
  124.          Object var4 = RTFReader.access$100().get(var1);
  125.          if (var4 != null) {
  126.             RTFAttribute var5 = (RTFAttribute)var4;
  127.             boolean var6;
  128.             switch (var5.domain()) {
  129.                case 0:
  130.                   var6 = var5.set(this.characterAttributes, var2);
  131.                   break;
  132.                case 1:
  133.                   var6 = var5.set(this.paragraphAttributes, var2);
  134.                   break;
  135.                case 2:
  136.                   var6 = var5.set(this.sectionAttributes, var2);
  137.                   break;
  138.                case 3:
  139.                   var6 = var5.set(this.this$0.documentAttributes, var2);
  140.                   break;
  141.                case 4:
  142.                   RTFReader.access$200(this.this$0).backing = this.this$0.parserState;
  143.                   var6 = var5.set(RTFReader.access$200(this.this$0), var2);
  144.                   RTFReader.access$200(this.this$0).backing = null;
  145.                   break;
  146.                default:
  147.                   var6 = false;
  148.             }
  149.  
  150.             if (var6) {
  151.                return true;
  152.             }
  153.          }
  154.  
  155.          if (var1.equals("fs")) {
  156.             StyleConstants.setFontSize(this.characterAttributes, var2 / 2);
  157.             return true;
  158.          } else if (var1.equals("sl")) {
  159.             if (var2 == 1000) {
  160.                this.characterAttributes.removeAttribute(StyleConstants.LineSpacing);
  161.             } else {
  162.                StyleConstants.setLineSpacing(this.characterAttributes, (float)var2 / 20.0F);
  163.             }
  164.  
  165.             return true;
  166.          } else if (!var1.equals("tx") && !var1.equals("tb")) {
  167.             if (var1.equals("s") && this.this$0.paragraphStyles != null) {
  168.                this.this$0.parserState.put("paragraphStyle", this.this$0.paragraphStyles[var2]);
  169.                return true;
  170.             } else if (var1.equals("cs") && this.this$0.characterStyles != null) {
  171.                this.this$0.parserState.put("characterStyle", this.this$0.characterStyles[var2]);
  172.                return true;
  173.             } else if (var1.equals("ds") && this.this$0.sectionStyles != null) {
  174.                this.this$0.parserState.put("sectionStyle", this.this$0.sectionStyles[var2]);
  175.                return true;
  176.             } else {
  177.                return false;
  178.             }
  179.          } else {
  180.             float var11 = (float)var2 / 20.0F;
  181.             int var12 = 0;
  182.             Number var7 = (Number)this.this$0.parserState.get("tab_alignment");
  183.             if (var7 != null) {
  184.                var12 = var7.intValue();
  185.             }
  186.  
  187.             int var13 = 0;
  188.             var7 = (Number)this.this$0.parserState.get("tab_leader");
  189.             if (var7 != null) {
  190.                var13 = var7.intValue();
  191.             }
  192.  
  193.             if (var1.equals("tb")) {
  194.                var12 = 5;
  195.             }
  196.  
  197.             this.this$0.parserState.remove("tab_alignment");
  198.             this.this$0.parserState.remove("tab_leader");
  199.             TabStop var8 = new TabStop(var11, var12, var13);
  200.             Object var9 = (Dictionary)this.this$0.parserState.get("_tabs");
  201.             Integer var10;
  202.             if (var9 == null) {
  203.                var9 = new Hashtable();
  204.                this.this$0.parserState.put("_tabs", var9);
  205.                var10 = new Integer(1);
  206.             } else {
  207.                var10 = (Integer)((Dictionary)var9).get("stop count");
  208.                var10 = new Integer(1 + var10);
  209.             }
  210.  
  211.             ((Dictionary)var9).put(var10, var8);
  212.             ((Dictionary)var9).put("stop count", var10);
  213.             this.this$0.parserState.remove("_tabs_immutable");
  214.             return true;
  215.          }
  216.       }
  217.    }
  218.  
  219.    protected MutableAttributeSet rootCharacterAttributes() {
  220.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  221.       StyleConstants.setItalic(var1, false);
  222.       StyleConstants.setBold(var1, false);
  223.       StyleConstants.setUnderline(var1, false);
  224.       StyleConstants.setForeground(var1, this.this$0.defaultColor());
  225.       return var1;
  226.    }
  227.  
  228.    protected MutableAttributeSet rootParagraphAttributes() {
  229.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  230.       StyleConstants.setLeftIndent(var1, 0.0F);
  231.       StyleConstants.setRightIndent(var1, 0.0F);
  232.       StyleConstants.setFirstLineIndent(var1, 0.0F);
  233.       var1.setResolveParent(this.this$0.target.getStyle("default"));
  234.       return var1;
  235.    }
  236.  
  237.    protected MutableAttributeSet rootSectionAttributes() {
  238.       SimpleAttributeSet var1 = new SimpleAttributeSet();
  239.       return var1;
  240.    }
  241.  
  242.    MutableAttributeSet currentTextAttributes() {
  243.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.characterAttributes);
  244.       Integer var2 = (Integer)this.this$0.parserState.get("f");
  245.       String var4;
  246.       if (var2 != null) {
  247.          var4 = (String)this.this$0.fontTable.get(var2);
  248.       } else {
  249.          var4 = null;
  250.       }
  251.  
  252.       if (var4 != null) {
  253.          StyleConstants.setFontFamily(var1, var4);
  254.       } else {
  255.          var1.removeAttribute(StyleConstants.FontFamily);
  256.       }
  257.  
  258.       if (this.this$0.colorTable != null) {
  259.          Integer var3 = (Integer)this.this$0.parserState.get("cf");
  260.          if (var3 != null) {
  261.             Color var5 = this.this$0.colorTable[var3];
  262.             StyleConstants.setForeground(var1, var5);
  263.          } else {
  264.             var1.removeAttribute(StyleConstants.Foreground);
  265.          }
  266.       }
  267.  
  268.       if (this.this$0.colorTable != null) {
  269.          Integer var6 = (Integer)this.this$0.parserState.get("cb");
  270.          if (var6 != null) {
  271.             Color var7 = this.this$0.colorTable[var6];
  272.             var1.addAttribute(StyleConstants.Background, var7);
  273.          } else {
  274.             var1.removeAttribute(StyleConstants.Background);
  275.          }
  276.       }
  277.  
  278.       Style var8 = (Style)this.this$0.parserState.get("characterStyle");
  279.       if (var8 != null) {
  280.          var1.setResolveParent(var8);
  281.       }
  282.  
  283.       return var1;
  284.    }
  285.  
  286.    MutableAttributeSet currentParagraphAttributes() {
  287.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.paragraphAttributes);
  288.       TabStop[] var3 = (TabStop[])this.this$0.parserState.get("_tabs_immutable");
  289.       if (var3 == null) {
  290.          Dictionary var4 = (Dictionary)this.this$0.parserState.get("_tabs");
  291.          if (var4 != null) {
  292.             int var5 = (Integer)var4.get("stop count");
  293.             var3 = new TabStop[var5];
  294.  
  295.             for(int var6 = 1; var6 <= var5; ++var6) {
  296.                var3[var6 - 1] = (TabStop)var4.get(new Integer(var6));
  297.             }
  298.  
  299.             this.this$0.parserState.put("_tabs_immutable", var3);
  300.          }
  301.       }
  302.  
  303.       if (var3 != null) {
  304.          var1.addAttribute("tabs", var3);
  305.       }
  306.  
  307.       Style var7 = (Style)this.this$0.parserState.get("paragraphStyle");
  308.       if (var7 != null) {
  309.          var1.setResolveParent(var7);
  310.       }
  311.  
  312.       return var1;
  313.    }
  314.  
  315.    public AttributeSet currentSectionAttributes() {
  316.       SimpleAttributeSet var1 = new SimpleAttributeSet(this.sectionAttributes);
  317.       Style var2 = (Style)this.this$0.parserState.get("sectionStyle");
  318.       if (var2 != null) {
  319.          var1.setResolveParent(var2);
  320.       }
  321.  
  322.       return var1;
  323.    }
  324.  
  325.    protected void resetCharacterAttributes() {
  326.       this.handleKeyword("f", 0);
  327.       this.handleKeyword("cf", 0);
  328.       this.handleKeyword("fs", 24);
  329.       Enumeration var1 = RTFReader.access$100().elements();
  330.  
  331.       while(var1.hasMoreElements()) {
  332.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  333.          if (var2.domain() == 0) {
  334.             var2.setDefault(this.characterAttributes);
  335.          }
  336.       }
  337.  
  338.       this.handleKeyword("sl", 1000);
  339.       this.this$0.parserState.remove("characterStyle");
  340.    }
  341.  
  342.    protected void resetParagraphAttributes() {
  343.       this.this$0.parserState.remove("_tabs");
  344.       this.this$0.parserState.remove("_tabs_immutable");
  345.       this.this$0.parserState.remove("paragraphStyle");
  346.       StyleConstants.setAlignment(this.paragraphAttributes, 0);
  347.       Enumeration var1 = RTFReader.access$100().elements();
  348.  
  349.       while(var1.hasMoreElements()) {
  350.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  351.          if (var2.domain() == 1) {
  352.             var2.setDefault(this.characterAttributes);
  353.          }
  354.       }
  355.  
  356.    }
  357.  
  358.    protected void resetSectionAttributes() {
  359.       Enumeration var1 = RTFReader.access$100().elements();
  360.  
  361.       while(var1.hasMoreElements()) {
  362.          RTFAttribute var2 = (RTFAttribute)var1.nextElement();
  363.          if (var2.domain() == 2) {
  364.             var2.setDefault(this.characterAttributes);
  365.          }
  366.       }
  367.  
  368.       this.this$0.parserState.remove("sectionStyle");
  369.    }
  370. }
  371.