home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / JASP1_1C.EXE / AMDProgressBar.class (.txt) next >
Encoding:
Java Class File  |  1997-04-27  |  5.0 KB  |  334 lines

  1. import java.awt.Canvas;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.image.ImageObserver;
  9.  
  10. public class AMDProgressBar extends Canvas {
  11.    int width_;
  12.    int height_;
  13.    Color outerBorderColor_;
  14.    Color innerBorderColor_;
  15.    Color boxColorA_;
  16.    Color boxColorB_;
  17.    Color barColor_;
  18.    Color backTopColor_;
  19.    Color backBottomColor_;
  20.    Color textColor_;
  21.    Color textShadowColor_;
  22.    Font font_;
  23.    String text_;
  24.    int sinePeriod_;
  25.    int colorSegment_;
  26.    Graphics graphics_;
  27.    Image image_;
  28.    double percent_;
  29.    boolean updateTrim_;
  30.    boolean updateLocations_;
  31.    boolean updateBar_;
  32.    int lastDigits_;
  33.    int halfY_;
  34.    int textX_;
  35.    int textY_;
  36.    // $FF: renamed from: r_ int
  37.    int field_0;
  38.    // $FF: renamed from: g_ int
  39.    int field_1;
  40.    // $FF: renamed from: b_ int
  41.    int field_2;
  42.    int r2_;
  43.    int g2_;
  44.    int b2_;
  45.  
  46.    public AMDProgressBar() {
  47.       this.outerBorderColor_ = Color.black;
  48.       this.innerBorderColor_ = Color.black;
  49.       this.boxColorA_ = new Color(244, 224, 32);
  50.       this.boxColorB_ = new Color(120, 80, 4);
  51.       this.barColor_ = new Color(52, 112, 4);
  52.       this.backTopColor_ = new Color(40, 40, 40);
  53.       this.backBottomColor_ = new Color(76, 76, 76);
  54.       this.textColor_ = new Color(208, 192, 28);
  55.       this.textShadowColor_ = Color.black;
  56.       this.font_ = new Font("TimesRoman", 1, 14);
  57.       this.sinePeriod_ = 87;
  58.       this.colorSegment_ = 7;
  59.       this.lastDigits_ = 1;
  60.       this.setPercent((double)0.0F);
  61.       this.updateTrim_ = true;
  62.       this.updateLocations_ = true;
  63.       this.updateBar_ = true;
  64.    }
  65.  
  66.    public void reshape(int var1, int var2, int var3, int var4) {
  67.       super.reshape(var1, var2, var3, var4);
  68.       this.width_ = var3;
  69.       this.height_ = var4;
  70.       if (this.graphics_ != null) {
  71.          this.graphics_.dispose();
  72.          this.graphics_ = null;
  73.       }
  74.  
  75.       ((Component)this).repaint();
  76.    }
  77.  
  78.    public void update(Graphics var1) {
  79.       this.paint(var1);
  80.    }
  81.  
  82.    public void paint(Graphics var1) {
  83.       if (this.graphics_ == null) {
  84.          this.image_ = ((Component)this).createImage(this.width_, this.height_);
  85.          this.graphics_ = this.image_.getGraphics();
  86.          this.updateTrim_ = true;
  87.          this.updateLocations_ = true;
  88.          this.updateBar_ = true;
  89.       }
  90.  
  91.       if (this.updateTrim_) {
  92.          this.updateTrim();
  93.       }
  94.  
  95.       if (this.updateLocations_) {
  96.          this.updateLocations();
  97.       }
  98.  
  99.       if (this.updateBar_) {
  100.          int var2 = (int)((double)(this.width_ - 6) * this.percent_);
  101.          int var3 = this.width_ - 6 - var2;
  102.          this.graphics_.translate(3, 3);
  103.          if (var2 > 0) {
  104.             this.graphics_.setColor(this.barColor_);
  105.             this.graphics_.fillRect(0, 0, var2, this.height_ - 6);
  106.          }
  107.  
  108.          if (var3 > 0) {
  109.             this.graphics_.setColor(this.backTopColor_);
  110.             this.graphics_.fillRect(var2, 0, var3, this.halfY_);
  111.             this.graphics_.setColor(this.backBottomColor_);
  112.             this.graphics_.fillRect(var2, this.halfY_, var3, this.height_ - 6 - this.halfY_);
  113.          }
  114.  
  115.          this.graphics_.translate(-3, -3);
  116.          this.graphics_.setFont(this.font_);
  117.          this.graphics_.setColor(this.textShadowColor_);
  118.          String var4;
  119.          if (this.text_ == null) {
  120.             var4 = (int)(this.percent_ * (double)100.0F) + "%";
  121.          } else {
  122.             var4 = this.text_;
  123.          }
  124.  
  125.          this.graphics_.drawString(var4, this.textX_ + 1, this.textY_ + 1);
  126.          this.graphics_.setColor(this.textColor_);
  127.          this.graphics_.drawString(var4, this.textX_, this.textY_);
  128.          this.updateBar_ = false;
  129.       }
  130.  
  131.       var1.drawImage(this.image_, 0, 0, (ImageObserver)null);
  132.    }
  133.  
  134.    Color getColor(int var1) {
  135.       double var2 = Math.sin((double)(var1 % this.sinePeriod_) * (double)2.0F * Math.PI / (double)this.sinePeriod_) + (double)1.0F;
  136.       return new Color(this.field_0 + (int)(var2 * (double)(this.r2_ - this.field_0) / (double)2.0F), this.field_1 + (int)(var2 * (double)(this.g2_ - this.field_1) / (double)2.0F), this.field_2 + (int)(var2 * (double)(this.b2_ - this.field_2) / (double)2.0F));
  137.    }
  138.  
  139.    int drawSineLine(int var1, int var2, int var3, int var4, int var5, int var6) {
  140.       boolean var7 = var3 == var5;
  141.       if (var7) {
  142.          int var8 = var3;
  143.          var3 = var4;
  144.          var4 = var8;
  145.          var5 = var6;
  146.       }
  147.  
  148.       boolean var11 = var3 > var5;
  149.       if (var11) {
  150.          var2 *= -1;
  151.       }
  152.  
  153.       this.graphics_.setColor(this.getColor(var1));
  154.       if (var7) {
  155.          this.graphics_.drawLine(var4, var3, var4, var3 + var2);
  156.       } else {
  157.          this.graphics_.drawLine(var3, var4, var3 + var2, var4);
  158.       }
  159.  
  160.       int var9 = 1;
  161.       if (!var11) {
  162.          var2 += this.colorSegment_;
  163.       }
  164.  
  165.       for(var1 += this.colorSegment_; var11 && var3 + var2 - this.colorSegment_ > var5 || !var11 && var3 + var2 < var5; ++var9) {
  166.          this.graphics_.setColor(this.getColor(var1));
  167.          if (var7) {
  168.             this.graphics_.drawLine(var4, var3 + var2 - this.colorSegment_, var4, var3 + var2);
  169.          } else {
  170.             this.graphics_.drawLine(var3 + var2 - this.colorSegment_, var4, var3 + var2, var4);
  171.          }
  172.  
  173.          var2 += var11 ? -this.colorSegment_ : this.colorSegment_;
  174.          var1 += this.colorSegment_;
  175.       }
  176.  
  177.       if (var11) {
  178.          var2 += this.colorSegment_;
  179.       }
  180.  
  181.       this.graphics_.setColor(this.getColor(var1));
  182.       if (var7) {
  183.          this.graphics_.drawLine(var4, var3 + var2 - this.colorSegment_, var4, var5);
  184.       } else {
  185.          this.graphics_.drawLine(var3 + var2 - this.colorSegment_, var4, var5, var4);
  186.       }
  187.  
  188.       return var9;
  189.    }
  190.  
  191.    void drawSineBox(Color var1, Color var2, int var3, int var4, int var5, int var6) {
  192.       this.field_0 = var1.getRed();
  193.       this.field_1 = var1.getGreen();
  194.       this.field_2 = var1.getBlue();
  195.       this.r2_ = var2.getRed();
  196.       this.g2_ = var2.getGreen();
  197.       this.b2_ = var2.getBlue();
  198.       int var7 = var3 + var5;
  199.       int var8 = var4 + var6;
  200.       int var9 = 0;
  201.       int var10 = (int)((double)this.sinePeriod_ / (double)4.0F);
  202.       int var11 = this.drawSineLine(var10, var9, var3, var4, var7, var4);
  203.       var10 += var11 * this.colorSegment_;
  204.       var9 += var11 * this.colorSegment_ - var7 + 1;
  205.       var11 = this.drawSineLine(var10, var9, var7, var4, var7, var8);
  206.       var10 += var11 * this.colorSegment_;
  207.       var9 += var11 * this.colorSegment_ - var8 + 1;
  208.       var11 = this.drawSineLine(var10, var9, var7, var8, var3, var8);
  209.       var10 += var11 * this.colorSegment_;
  210.       var9 += var11 * this.colorSegment_ - var7 + 1;
  211.       this.drawSineLine(var10, var9, var3, var8, var3, var4);
  212.    }
  213.  
  214.    void updateTrim() {
  215.       this.graphics_.setColor(this.outerBorderColor_);
  216.       this.graphics_.drawRect(0, 0, this.width_ - 1, this.height_ - 1);
  217.       this.graphics_.setColor(this.innerBorderColor_);
  218.       this.graphics_.drawRect(2, 2, this.width_ - 5, this.height_ - 5);
  219.       if (this.boxColorB_ != null && !this.boxColorA_.equals(this.boxColorB_)) {
  220.          this.drawSineBox(this.boxColorA_, this.boxColorB_, 1, 1, this.width_ - 3, this.height_ - 3);
  221.       } else {
  222.          this.graphics_.setColor(this.boxColorA_);
  223.          this.graphics_.drawRect(1, 1, this.width_ - 3, this.height_ - 3);
  224.       }
  225.  
  226.       this.updateTrim_ = false;
  227.    }
  228.  
  229.    void updateLocations() {
  230.       this.halfY_ = (this.height_ - 6) / 2;
  231.       FontMetrics var1 = ((Component)this).getFontMetrics(this.font_);
  232.       String var2;
  233.       if (this.text_ == null) {
  234.          if (this.lastDigits_ == 1) {
  235.             var2 = "3";
  236.          } else if (this.lastDigits_ == 2) {
  237.             var2 = "30";
  238.          } else {
  239.             var2 = "100";
  240.          }
  241.       } else {
  242.          var2 = this.text_;
  243.       }
  244.  
  245.       this.textX_ = (this.width_ - var1.stringWidth(var2)) / 2;
  246.       this.textY_ = (this.height_ + var1.getAscent() - var1.getDescent()) / 2;
  247.       this.updateLocations_ = false;
  248.    }
  249.  
  250.    public void setPercent(double var1) {
  251.       if (var1 < (double)0.0F) {
  252.          this.percent_ = (double)0.0F;
  253.       } else if (var1 > (double)1.0F) {
  254.          this.percent_ = (double)1.0F;
  255.       } else {
  256.          this.percent_ = var1;
  257.       }
  258.  
  259.       this.updateBar_ = true;
  260.       byte var3;
  261.       if (var1 < 0.1) {
  262.          var3 = 1;
  263.       } else if (var1 < (double)1.0F) {
  264.          var3 = 2;
  265.       } else {
  266.          var3 = 3;
  267.       }
  268.  
  269.       if (var3 != this.lastDigits_) {
  270.          this.lastDigits_ = var3;
  271.          if (this.text_ == null) {
  272.             this.updateLocations_ = true;
  273.          }
  274.       }
  275.  
  276.       ((Component)this).repaint();
  277.    }
  278.  
  279.    public void setText(String var1) {
  280.       this.text_ = var1;
  281.       this.updateLocations_ = true;
  282.       this.updateBar_ = true;
  283.       ((Component)this).repaint();
  284.    }
  285.  
  286.    public void setBorderColors(Color var1, Color var2) {
  287.       this.outerBorderColor_ = var1;
  288.       this.innerBorderColor_ = var2;
  289.       this.updateTrim_ = true;
  290.       ((Component)this).repaint();
  291.    }
  292.  
  293.    public void setBoxColors(Color var1, Color var2) {
  294.       this.boxColorA_ = var1;
  295.       this.boxColorB_ = var2;
  296.       this.updateTrim_ = true;
  297.       ((Component)this).repaint();
  298.    }
  299.  
  300.    public void setBarColor(Color var1) {
  301.       this.barColor_ = var1;
  302.       this.updateBar_ = true;
  303.       ((Component)this).repaint();
  304.    }
  305.  
  306.    public void setBackgroundColors(Color var1, Color var2) {
  307.       this.backTopColor_ = var1;
  308.       this.backBottomColor_ = var2;
  309.       this.updateBar_ = true;
  310.       ((Component)this).repaint();
  311.    }
  312.  
  313.    public void setTextColors(Color var1, Color var2) {
  314.       this.textColor_ = var1;
  315.       this.textShadowColor_ = var2;
  316.       this.updateBar_ = true;
  317.       ((Component)this).repaint();
  318.    }
  319.  
  320.    public void setFont(Font var1) {
  321.       this.font_ = var1;
  322.       this.updateLocations_ = true;
  323.       this.updateBar_ = true;
  324.       ((Component)this).repaint();
  325.    }
  326.  
  327.    public void setSineProperties(int var1, int var2) {
  328.       this.sinePeriod_ = var1;
  329.       this.colorSegment_ = var2;
  330.       this.updateTrim_ = true;
  331.       ((Component)this).repaint();
  332.    }
  333. }
  334.