home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / IAVAZIP.EXE / DATA.Z / ProgressBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-18  |  2.9 KB  |  126 lines

  1. package com.sfs.awt;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10.  
  11. public class ProgressBar extends Canvas {
  12.    float Progress;
  13.    float Minimum;
  14.    float Maximum = 100.0F;
  15.    int progressWidth;
  16.    Image img;
  17.    String percentString = "0 % completed";
  18.    Color barColor;
  19.    Color frameColor;
  20.    Color Background;
  21.  
  22.    public void setBackground(Color var1) {
  23.       this.Background = var1;
  24.    }
  25.  
  26.    public Color getBackground() {
  27.       return this.Background;
  28.    }
  29.  
  30.    public void paint(Graphics var1) {
  31.       Dimension var2 = ((Component)this).getSize();
  32.       if (this.img == null) {
  33.          this.img = ((Component)this).createImage(var2.width, var2.height);
  34.       }
  35.  
  36.       Graphics var3 = this.img.getGraphics();
  37.       FontMetrics var4 = var3.getFontMetrics();
  38.       int var5 = (var2.width - var4.stringWidth(this.percentString)) / 2;
  39.       int var6 = var2.height / 2 + var4.getMaxDescent();
  40.       var3.setColor(this.Background);
  41.       var3.fillRect(this.progressWidth, 0, var2.width - this.progressWidth, var2.height);
  42.       var3.setColor(this.barColor);
  43.       var3.drawString(this.percentString, var5, var6);
  44.       var3.fillRect(0, 0, this.progressWidth, var2.height);
  45.       var3.setColor(this.frameColor);
  46.       var3.drawRect(0, 0, var2.width, var2.height);
  47.       var3.setClip(0, 0, this.progressWidth, var2.height);
  48.       var3.setColor(this.Background);
  49.       var3.drawString(this.percentString, var5, var6);
  50.       var1.drawImage(this.img, 0, 0, this);
  51.       var3.dispose();
  52.    }
  53.  
  54.    public void setFrameColor(Color var1) {
  55.       this.frameColor = var1;
  56.    }
  57.  
  58.    public Color getFrameColor() {
  59.       return this.frameColor;
  60.    }
  61.  
  62.    public ProgressBar() {
  63.       this.barColor = Color.blue;
  64.       this.frameColor = Color.black;
  65.       this.Background = Color.white;
  66.    }
  67.  
  68.    public ProgressBar(float var1, float var2) {
  69.       this.barColor = Color.blue;
  70.       this.frameColor = Color.black;
  71.       this.Background = Color.white;
  72.       this.Minimum = var1;
  73.       this.Maximum = var2;
  74.       this.setBackground(Color.white);
  75.    }
  76.  
  77.    public void update(Graphics var1) {
  78.       this.paint(var1);
  79.    }
  80.  
  81.    public void setMaximum(float var1) {
  82.       this.Maximum = var1;
  83.       Dimension var2 = ((Component)this).getSize();
  84.       this.progressWidth = (int)(this.Progress / this.Maximum * (float)var2.width);
  85.       this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " % completed";
  86.    }
  87.  
  88.    public void setProgress(float var1) {
  89.       this.Progress = var1;
  90.       Dimension var2 = ((Component)this).getSize();
  91.       this.progressWidth = (int)(var1 / this.Maximum * (float)var2.width);
  92.       this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " % completed";
  93.       ((Component)this).repaint();
  94.    }
  95.  
  96.    public Dimension getMinimumSize() {
  97.       return new Dimension(50, 10);
  98.    }
  99.  
  100.    public void setSize(int var1, int var2) {
  101.       super.setSize(var1, var2);
  102.       this.progressWidth = (int)(this.Progress / this.Maximum * (float)((Component)this).getSize().width);
  103.       this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " %";
  104.       this.img = null;
  105.    }
  106.  
  107.    public Dimension getPreferredSize() {
  108.       return new Dimension(200, 20);
  109.    }
  110.  
  111.    public void setBounds(int var1, int var2, int var3, int var4) {
  112.       super.setBounds(var1, var2, var3, var4);
  113.       this.progressWidth = (int)(this.Progress / this.Maximum * (float)((Component)this).getSize().width);
  114.       this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " %";
  115.       this.img = null;
  116.    }
  117.  
  118.    public void setBarColor(Color var1) {
  119.       this.barColor = var1;
  120.    }
  121.  
  122.    public Color getBarColor() {
  123.       return this.barColor;
  124.    }
  125. }
  126.