home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2001 December / dppcpro1201.iso / Extras / maple / Viewer / WebEQ / MMLViewerInstall.cab / MMLViewerApplet.cab / webeq3 / schema / MMultiscripts.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-05-24  |  7.2 KB  |  285 lines

  1. package webeq3.schema;
  2.  
  3. import java.awt.Graphics;
  4. import webeq3.app.Equation;
  5. import webeq3.util.OutputHandler;
  6.  
  7. public class MMultiscripts extends Box {
  8.    double itc = (double)0.0F;
  9.    boolean stretchy = false;
  10.    Box base = null;
  11.    Box script = null;
  12.    int num_postscripts = 0;
  13.    int truebasewidth = 0;
  14.    int lspace = 0;
  15.    int rspace = 0;
  16.    int sub_asc = 0;
  17.    int sub_desc = 0;
  18.    int sup_asc = 0;
  19.    int sup_desc = 0;
  20.    int sub_height = 0;
  21.    int sup_height = 0;
  22.    int sub_bottom = 0;
  23.    int sup_top = 0;
  24.    int pre_width = 0;
  25.    int post_width = 0;
  26.    int[] col_widths = null;
  27.  
  28.    public MMultiscripts(Box var1) {
  29.       super(var1);
  30.       super.type = 8;
  31.    }
  32.  
  33.    public MMultiscripts() {
  34.       super.type = 8;
  35.    }
  36.  
  37.    public MMultiscripts(Equation var1) {
  38.       super(var1);
  39.       super.type = 8;
  40.    }
  41.  
  42.    public void postscripts_done() {
  43.       this.num_postscripts = super.children.size();
  44.    }
  45.  
  46.    public void size() {
  47.       this.sub_asc = 0;
  48.       this.sub_desc = 0;
  49.       this.sup_asc = 0;
  50.       this.sup_desc = 0;
  51.       this.sub_height = 0;
  52.       this.sup_height = 0;
  53.       this.sub_bottom = 0;
  54.       this.sup_top = 0;
  55.       this.pre_width = 0;
  56.       this.post_width = 0;
  57.       this.col_widths = new int[(super.children.size() - 1) / 2 + 1];
  58.       if (this.num_postscripts == 0) {
  59.          this.num_postscripts = super.children.size();
  60.       }
  61.  
  62.       ((Box)this).setfont(super.depth);
  63.       super.bgcolor = ((Box)this).resolveColor(17);
  64.       super.fgcolor = ((Box)this).resolveColor(4);
  65.       this.base = ((Box)this).getChild(0);
  66.       this.base.depth = super.depth;
  67.       this.base.layout();
  68.       super.embellished_op = this.base.embellished_op;
  69.  
  70.       Box var1;
  71.       for(var1 = this.base; this.italic_base_check(var1); var1 = var1.getChild(0)) {
  72.       }
  73.  
  74.       if (var1.isItalic()) {
  75.          this.itc = 0.14;
  76.       }
  77.  
  78.       this.truebasewidth = this.base.getWidth();
  79.       if (!this.base.isItalic()) {
  80.          this.truebasewidth += (int)(0.2 * (double)super.xheight);
  81.       }
  82.  
  83.       if (this.base instanceof MO) {
  84.          this.lspace = ((MO)this.base).op.lspace;
  85.          this.rspace = ((MO)this.base).op.rspace;
  86.          this.truebasewidth = this.truebasewidth - this.lspace - this.rspace;
  87.          if (((MO)this.base).op.stretchy) {
  88.             this.stretchy = true;
  89.          }
  90.       }
  91.  
  92.       for(int var2 = 1; var2 < super.children.size(); ++var2) {
  93.          this.script = ((Box)this).getChild(var2);
  94.          this.script.depth = super.depth + 1;
  95.          this.script.layout();
  96.          if (var2 % 2 != 0) {
  97.             this.col_widths[(var2 - 1) / 2] = this.script.getWidth();
  98.             if (this.sub_asc < this.script.getAscent()) {
  99.                this.sub_asc = this.script.getAscent();
  100.             }
  101.  
  102.             if (this.sub_desc < this.script.getDescent()) {
  103.                this.sub_desc = this.script.getDescent();
  104.             }
  105.          } else {
  106.             if (this.col_widths[(var2 - 2) / 2] < this.script.getWidth()) {
  107.                this.col_widths[(var2 - 2) / 2] = this.script.getWidth();
  108.             }
  109.  
  110.             if (this.sup_asc < this.script.getAscent()) {
  111.                this.sup_asc = this.script.getAscent();
  112.             }
  113.  
  114.             if (this.sup_desc < this.script.getDescent()) {
  115.                this.sup_desc = this.script.getDescent();
  116.             }
  117.          }
  118.       }
  119.  
  120.       this.sup_height = this.sup_asc + this.sup_desc;
  121.       this.sub_height = this.sub_asc + this.sub_desc;
  122.  
  123.       for(int var3 = 0; var3 < (this.num_postscripts - 1) / 2; ++var3) {
  124.          this.post_width += this.col_widths[var3];
  125.       }
  126.  
  127.       for(int var4 = (this.num_postscripts - 1) / 2; var4 < (super.children.size() - 1) / 2; ++var4) {
  128.          this.pre_width += this.col_widths[var4];
  129.       }
  130.  
  131.       super.width = this.pre_width + this.post_width + (int)(this.itc * (double)this.base.getHeight());
  132.       super.width += this.lspace + this.truebasewidth + this.rspace;
  133.       if (super.my_view.linebreak && this.truebasewidth > 8 * super.fm.charWidth('M') || (double)super.width > (double)super.my_view.getDisplayWidth() - (double)1.5F * (double)super.my_view.indent) {
  134.          super.atomic = false;
  135.       }
  136.  
  137.       if (this.sub_height != 0) {
  138.          this.sub_bottom = (int)(0.3 * (double)super.xheight) + this.sub_desc;
  139.          if (this.sub_bottom < this.base.getDescent() - (int)(0.2 * (double)super.xheight)) {
  140.             this.sub_bottom = this.base.getDescent() + (int)(0.1 * (double)super.xheight);
  141.          }
  142.  
  143.          if (this.sup_height != 0) {
  144.             if (this.sub_height - this.sub_bottom > (int)(0.65 * (double)super.xheight)) {
  145.                this.sub_bottom = this.sub_height - (int)(0.65 * (double)super.xheight);
  146.             }
  147.          } else if (this.sub_height - this.sub_bottom > (int)(0.8 * (double)super.xheight)) {
  148.             this.sub_bottom = this.sub_height - (int)(0.8 * (double)super.xheight);
  149.          }
  150.       }
  151.  
  152.       if (this.sup_height != 0) {
  153.          double var5 = this.base.depth >= 2 ? 0.55 : 0.8;
  154.          this.sup_top = (int)(var5 * (double)super.xheight) + this.sup_asc;
  155.          if (this.sup_top < this.base.getAscent() + this.sup_asc - (int)(0.8 * (double)super.xheight)) {
  156.             this.sup_top = this.base.getAscent() + this.sup_asc - (int)(0.8 * (double)super.xheight);
  157.          }
  158.  
  159.          if (this.sub_height != 0) {
  160.             if (this.sup_top - this.sup_height < (int)(0.8 * (double)super.xheight)) {
  161.                this.sup_top = this.sup_height + (int)(0.8 * (double)super.xheight);
  162.             }
  163.          } else if (this.sup_top - this.sup_height < (int)((double)0.25F * (double)super.xheight)) {
  164.             this.sup_top = this.sup_height + (int)((double)0.25F * (double)super.xheight);
  165.          }
  166.       }
  167.  
  168.       super.ascent = this.base.getAscent() < this.sup_top ? this.sup_top : this.base.getAscent();
  169.       super.descent = this.base.getDescent() < this.sub_bottom ? this.sub_bottom : this.base.getDescent();
  170.       super.height = super.ascent + super.descent;
  171.    }
  172.  
  173.    public void position() {
  174.       this.base.setTop(super.ascent - this.base.getAscent());
  175.       this.base.setLeft(this.pre_width - (int)(this.itc * (double)this.base.getDescent()));
  176.       this.position_scripts(this.num_postscripts, super.children.size(), this.lspace);
  177.       this.position_scripts(1, this.num_postscripts, this.pre_width + this.truebasewidth + (int)(this.itc * (double)this.base.getAscent()));
  178.    }
  179.  
  180.    void position_scripts(int var1, int var2, int var3) {
  181.       for(int var4 = var1; var4 < var2; ++var4) {
  182.          this.script = ((Box)this).getChild(var4);
  183.          if (var4 % 2 != 0) {
  184.             this.script.setTop(super.ascent + this.sub_bottom - this.sub_desc - this.script.getAscent());
  185.             this.script.setLeft(var3 + (this.col_widths[(var4 - 1) / 2] - this.script.getWidth()) / 2 - (int)(this.itc * (double)this.base.getDescent()));
  186.          } else {
  187.             this.script.setTop(super.ascent - this.sup_top + this.sup_asc - this.script.getAscent());
  188.             this.script.setLeft(var3 + (this.col_widths[(var4 - 1) / 2] - this.script.getWidth()) / 2 + (int)(this.itc * (double)this.base.getAscent()));
  189.             var3 += this.col_widths[(var4 - 2) / 2];
  190.          }
  191.       }
  192.  
  193.    }
  194.  
  195.    public boolean stretchTo(int var1, int var2) {
  196.       Box var3 = ((Box)this).getChild(0);
  197.       boolean var4 = false;
  198.       if (var3.embellished_op) {
  199.          var4 |= var3.stretchTo(var1, var2);
  200.          this.size();
  201.          this.position();
  202.       }
  203.  
  204.       return var4;
  205.    }
  206.  
  207.    public void printSelected(String var1, OutputHandler var2, boolean var3, boolean var4, String var5, boolean var6, int var7) {
  208.       if (var3 && !super.reverse_video) {
  209.          for(int var10 = 0; var10 < super.children.size(); ++var10) {
  210.             ((Box)this).getChild(var10).printSelected(var1, var2, var3, var4, var5, var6, var7);
  211.          }
  212.       } else if (var6 && super.cpeer != null) {
  213.          super.cpeer.printSelected(var1, var2, var3, var4, var5, var6, var7);
  214.       } else if (super.children.size() == 0) {
  215.          var2.println(var1 + ((Box)this).make_head(false, var5) + "</" + ((Box)this).make_tag(var5) + ">");
  216.       } else {
  217.          var2.println(var1 + ((Box)this).make_head(false, var5));
  218.  
  219.          for(int var9 = 0; var9 < super.children.size(); ++var9) {
  220.             Box var8 = ((Box)this).getChild(var9);
  221.             if (!"".equals(var5)) {
  222.                var5 = var5 + ":";
  223.             }
  224.  
  225.             if (var9 == this.num_postscripts) {
  226.                var2.println(var1 + "  " + "<" + var5 + "mprescripts/>");
  227.             }
  228.  
  229.             if (var8.getClass().getName().equals("webeq3.schema.Box")) {
  230.                var2.println(var1 + "  " + "<" + var5 + "none/>");
  231.             } else {
  232.                var8.printSelected(var1 + "  ", var2, var3, var4, var5, var6, var7);
  233.             }
  234.          }
  235.  
  236.          var2.println(var1 + "</" + ((Box)this).make_tag(var5) + ">");
  237.       }
  238.  
  239.    }
  240.  
  241.    private boolean italic_base_check(Box var1) {
  242.       if (var1 instanceof MRow && var1.getNumChildren() == 1) {
  243.          return true;
  244.       } else {
  245.          return var1 instanceof MUnder | var1 instanceof MOver | var1 instanceof MUnderover | var1 instanceof MSubsup | var1 instanceof MSub | var1 instanceof MSup;
  246.       }
  247.    }
  248.  
  249.    public void paint(Graphics var1, int var2, int var3) {
  250.       ((Box)this).paintBackground(var1, var2, var3);
  251.       if (super.my_view.linebreak) {
  252.          int var4 = var2 + super.left + super.my_view.offsetx;
  253.          int var5 = super.my_view.getDisplayWidth();
  254.          Box var6 = ((Box)this).getChild(0);
  255.          if (var5 - (var4 + var6.getLeft() + super.fm.charWidth('M') + super.breakLookAhead) < 0) {
  256.             super.my_view.offsetx = super.my_view.indent - (var2 + super.left);
  257.             Equation var10000 = super.my_view;
  258.             var10000.offsety += 5 + super.my_view.root.getHeight();
  259.             Integer var7 = new Integer(var2 + super.left);
  260.             super.my_view.breaks.addElement(var7);
  261.          }
  262.  
  263.          for(int var11 = this.num_postscripts; var11 < super.children.size(); ++var11) {
  264.             ((Box)this).getChild(var11).paint(var1, var2 + super.left, var3 + super.top);
  265.          }
  266.  
  267.          int var8 = super.width - (var6.getLeft() + var6.getWidth());
  268.          var6.setLookAhead(super.breakLookAhead + var8);
  269.          var6.paint(var1, var2 + super.left, var3 + super.top);
  270.          var6.setLookAhead(super.breakLookAhead);
  271.  
  272.          for(int var9 = 1; var9 < this.num_postscripts; ++var9) {
  273.             ((Box)this).getChild(var9).paint(var1, var2 + super.left, var3 + super.top);
  274.          }
  275.       } else {
  276.          for(int var10 = 0; var10 < super.children.size(); ++var10) {
  277.             ((Box)this).getChild(var10).paint(var1, var2 + super.left, var3 + super.top);
  278.          }
  279.       }
  280.  
  281.       super.absleft = var2 + super.left;
  282.       super.abstop = var3 + super.top;
  283.    }
  284. }
  285.