home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.awt;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
-
- public class ProgressBar extends Canvas {
- float Progress;
- float Minimum;
- float Maximum = 100.0F;
- int progressWidth;
- Image img;
- String percentString = "0 % completed";
- Color barColor;
- Color frameColor;
- Color Background;
-
- public void setBackground(Color var1) {
- this.Background = var1;
- }
-
- public Color getBackground() {
- return this.Background;
- }
-
- public void paint(Graphics var1) {
- Dimension var2 = ((Component)this).getSize();
- if (this.img == null) {
- this.img = ((Component)this).createImage(var2.width, var2.height);
- }
-
- Graphics var3 = this.img.getGraphics();
- FontMetrics var4 = var3.getFontMetrics();
- int var5 = (var2.width - var4.stringWidth(this.percentString)) / 2;
- int var6 = var2.height / 2 + var4.getMaxDescent();
- var3.setColor(this.Background);
- var3.fillRect(this.progressWidth, 0, var2.width - this.progressWidth, var2.height);
- var3.setColor(this.barColor);
- var3.drawString(this.percentString, var5, var6);
- var3.fillRect(0, 0, this.progressWidth, var2.height);
- var3.setColor(this.frameColor);
- var3.drawRect(0, 0, var2.width, var2.height);
- var3.setClip(0, 0, this.progressWidth, var2.height);
- var3.setColor(this.Background);
- var3.drawString(this.percentString, var5, var6);
- var1.drawImage(this.img, 0, 0, this);
- var3.dispose();
- }
-
- public void setFrameColor(Color var1) {
- this.frameColor = var1;
- }
-
- public Color getFrameColor() {
- return this.frameColor;
- }
-
- public ProgressBar() {
- this.barColor = Color.blue;
- this.frameColor = Color.black;
- this.Background = Color.white;
- }
-
- public ProgressBar(float var1, float var2) {
- this.barColor = Color.blue;
- this.frameColor = Color.black;
- this.Background = Color.white;
- this.Minimum = var1;
- this.Maximum = var2;
- this.setBackground(Color.white);
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public void setMaximum(float var1) {
- this.Maximum = var1;
- Dimension var2 = ((Component)this).getSize();
- this.progressWidth = (int)(this.Progress / this.Maximum * (float)var2.width);
- this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " % completed";
- }
-
- public void setProgress(float var1) {
- this.Progress = var1;
- Dimension var2 = ((Component)this).getSize();
- this.progressWidth = (int)(var1 / this.Maximum * (float)var2.width);
- this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " % completed";
- ((Component)this).repaint();
- }
-
- public Dimension getMinimumSize() {
- return new Dimension(50, 10);
- }
-
- public void setSize(int var1, int var2) {
- super.setSize(var1, var2);
- this.progressWidth = (int)(this.Progress / this.Maximum * (float)((Component)this).getSize().width);
- this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " %";
- this.img = null;
- }
-
- public Dimension getPreferredSize() {
- return new Dimension(200, 20);
- }
-
- public void setBounds(int var1, int var2, int var3, int var4) {
- super.setBounds(var1, var2, var3, var4);
- this.progressWidth = (int)(this.Progress / this.Maximum * (float)((Component)this).getSize().width);
- this.percentString = Integer.toString((int)(this.Progress / this.Maximum * 100.0F)) + " %";
- this.img = null;
- }
-
- public void setBarColor(Color var1) {
- this.barColor = var1;
- }
-
- public Color getBarColor() {
- return this.barColor;
- }
- }
-