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

  1. package com.sun.java.swing.text.rtf;
  2.  
  3. import com.sun.java.swing.text.AttributeSet;
  4. import com.sun.java.swing.text.MutableAttributeSet;
  5. import com.sun.java.swing.text.SimpleAttributeSet;
  6. import com.sun.java.swing.text.Style;
  7. import com.sun.java.swing.text.StyleConstants;
  8. import com.sun.java.swing.text.TabStop;
  9. import java.awt.Color;
  10. import java.util.Dictionary;
  11. import java.util.Enumeration;
  12. import java.util.Hashtable;
  13.  
  14. abstract class RTFReader$AttributeTrackingDestination implements RTFReader.Destination {
  15.    // $FF: synthetic field
  16.    private final RTFReader this$0;
  17.    MutableAttributeSet characterAttributes;
  18.    MutableAttributeSet paragraphAttributes;
  19.    MutableAttributeSet sectionAttributes;
  20.  
  21.    public RTFReader$AttributeTrackingDestination(RTFReader var1) {
  22.       this.this$0 = var1;
  23.       this.this$0 = var1;
  24.       this.characterAttributes = this.rootCharacterAttributes();
  25.       var1.parserState.put("chr", this.characterAttributes);
  26.       this.paragraphAttributes = this.rootParagraphAttributes();
  27.       var1.parserState.put("pgf", this.paragraphAttributes);
  28.       this.sectionAttributes = this.rootSectionAttributes();
  29.       var1.parserState.put("sec", this.sectionAttributes);
  30.    }
  31.  
  32.    public abstract void handleText(String var1);
  33.  
  34.    public void handleBinaryBlob(byte[] var1) {
  35.       this.this$0.warnings.println("Unexpected binary data in RTF file.");
  36.    }
  37.  
  38.    public void begingroup() {
  39.       MutableAttributeSet var1 = this.currentTextAttributes();
  40.       MutableAttributeSet var2 = this.currentParagraphAttributes();
  41.       AttributeSet var3 = this.currentSectionAttributes();
  42.       this.characterAttributes = new SimpleAttributeSet();
  43.       this.characterAttributes.addAttributes(var1);
  44.       this.this$0.parserState.put("chr", this.characterAttributes);
  45.       this.paragraphAttributes = new SimpleAttributeSet();
  46.       this.paragraphAttributes.addAttributes(var2);
  47.       this.this$0.parserState.put("pgf", this.paragraphAttributes);
  48.       this.sectionAttributes = new SimpleAttributeSet();
  49.       this.sectionAttributes.addAttributes(var3);
  50.       this.this$0.parserState.put("sec", this.sectionAttributes);
  51.    }
  52.  
  53.    public void endgroup(Dictionary var1) {
  54.       this.characterAttributes = (MutableAttributeSet)this.this$0.parserState.get("chr");
  55.       this.paragraphAttributes = (MutableAttributeSet)this.this$0.parserState.get("pgf");
  56.       this.sectionAttributes = (MutableAttributeSet)this.this$0.parserState.get("sec");
  57.    }
  58.  
  59.    public void close() {
  60.    }
  61.  
  62.    public boolean handleKeyword(String var1) {
  63.       if (var1.equals("ulnone")) {
  64.          return this.handleKeyword("ul", 0);
  65.       } else {
  66.          Object var2 = RTFReader.access$0().get(var1);
  67.          if (var2 != null) {
  68.             RTFAttribute var3 = (RTFAttribute)var2;
  69.             boolean var4;
  70.             switch (var3.domain()) {
  71.                case 0:
  72.                   var4 = var3.set(this.characterAttributes);
  73.                   break;
  74.                case 1:
  75.                   var4 = var3.set(this.paragraphAttributes);
  76.                   break;
  77.                case 2:
  78.                   var4 = var3.set(this.sectionAttributes);
  79.                   break;
  80.                case 3:
  81.                   var4 = var3.set(this.this$0.documentAttributes);
  82.                   break;
  83.                case 4:
  84.                   RTFReader.access$1(this.this$0).backing = this.this$0.parserState;
  85.                   var4 = var3.set(RTFReader.access$1(this.this$0));
  86.                   RTFReader.access$1(this.this$0).backing = null;
  87.                   break;
  88.                default:
  89.                   var4 = false;
  90.             }
  91.  
  92.             if (var4) {
  93.                return true;
  94.             }
  95.          }
  96.  
  97.          if (var1.equals("plain")) {
  98.             this.resetCharacterAttributes();
  99.             return true;
  100.          } else if (var1.equals("pard")) {
  101.             this.resetParagraphAttributes();
  102.             return true;
  103.          } else if (var1.equals("sectd")) {
  104.             this.resetSectionAttributes();
  105.             return true;
  106.          } else {
  107.             return false;
  108.          }
  109.       }
  110.    }
  111.  
  112.    public boolean handleKeyword(String var1, int var2) {
  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 var3 = RTFReader.access$0().get(var1);
  125.          if (var3 != null) {
  126.             RTFAttribute var4 = (RTFAttribute)var3;
  127.             boolean var5;
  128.             switch (var4.domain()) {
  129.                case 0:
  130.                   var5 = var4.set(this.characterAttributes, var2);
  131.                   break;
  132.                case 1:
  133.                   var5 = var4.set(this.paragraphAttributes, var2);
  134.                   break;
  135.                case 2:
  136.                   var5 = var4.set(this.sectionAttributes, var2);
  137.                   break;
  138.                case 3:
  139.                   var5 = var4.set(this.this$0.documentAttributes, var2);
  140.                   break;
  141.                case 4:
  142.                   RTFReader.access$1(this.this$0).backing = this.this$0.parserState;
  143.                   var5 = var4.set(RTFReader.access$1(this.this$0), var2);
  144.                   RTFReader.access$1(this.this$0).backing = null;
  145.                   break;
  146.                default:
  147.                   var5 = false;
  148.             }
  149.  
  150.             if (var5) {
  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 var6 = 0;
  188.             var7 = (Number)this.this$0.parserState.get("tab_leader");
  189.             if (var7 != null) {
  190.                var6 = 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, var6);
  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[] var2 = (TabStop[])this.this$0.parserState.get("_tabs_immutable");
  289.       if (var2 == null) {
  290.          Dictionary var3 = (Dictionary)this.this$0.parserState.get("_tabs");
  291.          if (var3 != null) {
  292.             int var4 = (Integer)var3.get("stop count");
  293.             var2 = new TabStop[var4];
  294.  
  295.             for(int var5 = 1; var5 <= var4; ++var5) {
  296.                var2[var5 - 1] = (TabStop)var3.get(new Integer(var5));
  297.             }
  298.  
  299.             this.this$0.parserState.put("_tabs_immutable", var2);
  300.          }
  301.       }
  302.  
  303.       if (var2 != null) {
  304.          var1.addAttribute("tabs", var2);
  305.       }
  306.  
  307.       Style var6 = (Style)this.this$0.parserState.get("paragraphStyle");
  308.       if (var6 != null) {
  309.          var1.setResolveParent(var6);
  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$0().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$0().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$0().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.