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

  1. package webeq3.schema;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import webeq3.app.Equation;
  6. import webeq3.constants.FontMapper;
  7. import webeq3.fonts.ExtendedChar;
  8.  
  9. public class MFrac extends LineBreakRewriter {
  10.    int mid = 0;
  11.    int dxheight = 0;
  12.    int linethickness = 1;
  13.    int spacing = 0;
  14.  
  15.    public MFrac() {
  16.       super.type = 4;
  17.    }
  18.  
  19.    public MFrac(Box var1) {
  20.       super(var1);
  21.       super.type = 4;
  22.    }
  23.  
  24.    public MFrac(Equation var1) {
  25.       super(var1);
  26.       super.type = 4;
  27.    }
  28.  
  29.    public void size() {
  30.       super.useLinearForm = false;
  31.       Box var1 = ((Box)this).getChild(0);
  32.       Box var2 = ((Box)this).getChild(1);
  33.       String var3 = ((Box)this).getAttributeString(24);
  34.  
  35.       try {
  36.          this.linethickness = Integer.parseInt(var3);
  37.       } catch (NumberFormatException var13) {
  38.          if ("thick".equals(var3)) {
  39.             this.linethickness = 3;
  40.          } else if ("medium".equals(var3)) {
  41.             this.linethickness = 2;
  42.          } else if ("thin".equals(var3)) {
  43.             this.linethickness = 1;
  44.          } else {
  45.             var3 = ((Box)this).getAttributeByIndex(24);
  46.  
  47.             try {
  48.                float var5 = Float.valueOf(var3) * (float)((Box)this).getXHeight();
  49.                this.linethickness = (int)var5;
  50.                if ((double)var5 > 0.001 && this.linethickness == 0) {
  51.                   this.linethickness = 1;
  52.                }
  53.             } catch (NumberFormatException var12) {
  54.             }
  55.          }
  56.       }
  57.  
  58.       this.linethickness = super.my_view.standardPointsize(super.depth) > 18 && this.linethickness != 0 ? this.linethickness + 1 : this.linethickness;
  59.       super.fgcolor = ((Box)this).resolveColor(4);
  60.       super.bgcolor = ((Box)this).resolveColor(17);
  61.       ((Box)this).setfont(super.depth);
  62.       int var4 = super.depth == 0 && "true".equals(((Box)this).getAttributeByIndex(21)) ? 0 : 1;
  63.       var1.depth = super.depth + var4;
  64.       var2.depth = super.depth + var4;
  65.       super.attribute_stack[21].push("false");
  66.       var1.layout();
  67.       var2.layout();
  68.       super.attribute_stack[21].pop();
  69.       super.embellished_op = var1.embellished_op;
  70.       int var15 = var1.getWidth();
  71.       int var6 = var2.getWidth();
  72.       super.width = var15 > var6 ? var15 : var6;
  73.       int var7 = (int)((double)super.width * 1.2);
  74.       if (var7 - super.width > 10) {
  75.          var7 = super.width + 10;
  76.       }
  77.  
  78.       if (var7 - super.width < 2) {
  79.          var7 = super.width + 2;
  80.       }
  81.  
  82.       this.spacing = (int)(0.08 * (double)super.my_view.standardPointsize(super.depth));
  83.       super.width = var7 + 2 * this.spacing;
  84.       int var8 = super.my_view.getDisplayWidth();
  85.       if (super.my_view.linebreak && (double)super.width > 0.85 * (double)(var8 - super.my_view.indent)) {
  86.          super.useLinearForm = true;
  87.          if (super.lb_rewrite == null) {
  88.             super.lb_rewrite = new MRow(super.parent);
  89.             MRow var16 = new MRow(super.lb_rewrite);
  90.             super.lb_rewrite.addChild(var16);
  91.             MO var18 = new MO(var16);
  92.             ((Box)var18).addData("(");
  93.             ((Box)var16).addChild(var18);
  94.             ((Box)var16).addChild(var1);
  95.             var1.setParent(this);
  96.             var18 = new MO(var16);
  97.             ((Box)var18).addData(")");
  98.             ((Box)var16).addChild(var18);
  99.             MO var11 = new MO(super.lb_rewrite);
  100.             ((Box)var11).addData("/");
  101.             super.lb_rewrite.addChild(var11);
  102.             var16 = new MRow(super.lb_rewrite);
  103.             super.lb_rewrite.addChild(var16);
  104.             var18 = new MO(var16);
  105.             ((Box)var18).addData("(");
  106.             ((Box)var16).addChild(var18);
  107.             ((Box)var16).addChild(var2);
  108.             var2.setParent(this);
  109.             var18 = new MO(var16);
  110.             ((Box)var18).addData(")");
  111.             ((Box)var16).addChild(var18);
  112.          }
  113.  
  114.          super.lb_rewrite.layout();
  115.          super.width = super.lb_rewrite.getWidth();
  116.          super.ascent = super.lb_rewrite.getAscent();
  117.          super.descent = super.lb_rewrite.getDescent();
  118.          super.height = super.ascent + super.descent;
  119.       } else {
  120.          ((Box)this).setfont(var2.depth);
  121.          this.dxheight = super.xheight;
  122.          ((Box)this).setfont(super.depth);
  123.          ExtendedChar var9 = FontMapper.get('ΓêÆ');
  124.          var9.setFont(super.fn, super.my_view.getHandler().getComponent());
  125.          double var10 = 0.9 * (double)var9.getAscent();
  126.          super.ascent = var1.getAscent() + (int)(var10 + 0.35 * (double)this.dxheight + (double)(this.linethickness / 2));
  127.          if (0.35 * (double)this.dxheight - (double)(this.linethickness / 2) < (double)(var1.getDescent() + 2)) {
  128.             super.ascent += (int)((double)var1.getDescent() - 0.35 * (double)this.dxheight + (double)(this.linethickness / 2) + (double)2.0F);
  129.          }
  130.  
  131.          super.descent = var2.getDescent() + (int)(1.8 * (double)this.dxheight - var10);
  132.          if (var2.getHeight() > super.descent + (int)(var10 - (double)0.25F * (double)this.dxheight - (double)(this.linethickness / 2))) {
  133.             super.descent = var2.getHeight() - (int)(var10 - (double)0.25F * (double)this.dxheight - (double)(this.linethickness / 2));
  134.          }
  135.  
  136.          super.height = super.ascent + super.descent;
  137.          this.mid = super.ascent - (int)(var10 + (double)(this.linethickness / 2) + (double)0.5F);
  138.       }
  139.  
  140.    }
  141.  
  142.    public void position() {
  143.       Box var1 = ((Box)this).getChild(0);
  144.       Box var2 = ((Box)this).getChild(1);
  145.       if (super.useLinearForm) {
  146.          super.lb_rewrite.setLeft(0);
  147.          super.lb_rewrite.setTop(0);
  148.       } else {
  149.          var1.setLeft((super.width - var1.getWidth()) / 2);
  150.          var2.setLeft((super.width - var2.getWidth()) / 2);
  151.          var1.setTop(super.top);
  152.          var2.setTop(super.top + super.height - var2.getHeight());
  153.       }
  154.  
  155.    }
  156.  
  157.    public void paint(Graphics var1, int var2, int var3) {
  158.       if (super.useLinearForm) {
  159.          super.lb_rewrite.paint(var1, var2 + super.left, var3 + super.top);
  160.       } else {
  161.          ((Box)this).paintBackground(var1, var2, var3);
  162.          ((Box)this).getChild(0).paint(var1, var2 + super.left, var3 + super.top);
  163.          ((Box)this).getChild(1).paint(var1, var2 + super.left, var3 + super.top);
  164.          if (super.reverse_video) {
  165.             var1.setColor(super.bgcolor);
  166.          } else {
  167.             var1.setColor(super.fgcolor);
  168.          }
  169.  
  170.          var1.fillRect(var2 + super.left + super.my_view.offsetx + this.spacing, var3 + super.top + super.my_view.offsety + this.mid, super.width - 2 * this.spacing, this.linethickness);
  171.          var1.setColor(Color.black);
  172.       }
  173.  
  174.       super.absleft = var2 + super.left;
  175.       super.abstop = var3 + super.top;
  176.    }
  177. }
  178.