View Javadoc

1   package junit.swingui;
2   
3   import java.awt.Color;
4   
5   import javax.swing.JProgressBar;
6   
7   /***
8    * A progress bar showing the green/red status
9    */
10  class ProgressBar extends JProgressBar {
11  	boolean fError= false;
12  	
13  	public ProgressBar() {
14  		super(); 
15  		setForeground(getStatusColor());
16  	}
17  	
18  	protected Color getStatusColor() {
19  		if (fError)
20  			return Color.red;
21  		return Color.green;
22  	}
23  		
24  	public void reset() {
25  		fError= false;
26  		updateBarColor();
27  		setValue(0);
28  	}
29  	
30  	public void start(int total) {
31  		setMaximum(total);
32  		reset();
33  	}
34  	
35  	public void step(int value, boolean successful) {
36  		setValue(value);
37  		if (!fError && !successful) {
38  			fError= true;
39  			updateBarColor();
40  		}
41  		}
42  	
43  	protected void updateBarColor() {
44  		setForeground(getStatusColor());
45  	}
46  }