2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: ProgressBar.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.2 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 21:00:04 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.util.swing; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.applet.Applet; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GradientPaint; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.RenderingHints; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
public class ProgressBar extends JDialog { |
2 |
26 Feb 07 |
jari |
31 |
private Frame parent; |
2 |
26 Feb 07 |
jari |
32 |
private String title; |
2 |
26 Feb 07 |
jari |
33 |
private Color barColor1, barColor2, textColor; |
2 |
26 Feb 07 |
jari |
34 |
private int units = 0, value = 0; |
2 |
26 Feb 07 |
jari |
35 |
private Applet progressBarApplet; |
2 |
26 Feb 07 |
jari |
36 |
private Font progressBarFont; |
2 |
26 Feb 07 |
jari |
37 |
private JPanel drawingArea; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
public ProgressBar(Frame parent, String title, Color barColor1, Color barColor2, Color textColor, int units) { |
2 |
26 Feb 07 |
jari |
40 |
super(parent, title, false); |
2 |
26 Feb 07 |
jari |
41 |
this.parent = parent; |
2 |
26 Feb 07 |
jari |
42 |
this.title = title; |
2 |
26 Feb 07 |
jari |
43 |
this.barColor1 = barColor1; |
2 |
26 Feb 07 |
jari |
44 |
this.barColor2 = barColor2; |
2 |
26 Feb 07 |
jari |
45 |
this.textColor = textColor; |
2 |
26 Feb 07 |
jari |
46 |
this.units = units; |
2 |
26 Feb 07 |
jari |
47 |
progressBarApplet = new Applet(); |
2 |
26 Feb 07 |
jari |
48 |
progressBarFont = new Font("monospaced", Font.BOLD, 20); |
2 |
26 Feb 07 |
jari |
49 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
50 |
addWindowListener(new WindowAdapter() { |
2 |
26 Feb 07 |
jari |
51 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
52 |
hide(); |
2 |
26 Feb 07 |
jari |
53 |
dispose(); |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
}); |
2 |
26 Feb 07 |
jari |
56 |
drawingArea = new JPanel() { |
2 |
26 Feb 07 |
jari |
57 |
protected void paintComponent(Graphics g) { |
2 |
26 Feb 07 |
jari |
58 |
super.paintComponent(g); |
2 |
26 Feb 07 |
jari |
59 |
OnPaint(g); |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
}; |
2 |
26 Feb 07 |
jari |
// drawingArea.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
63 |
drawingArea.setPreferredSize(new Dimension(210,50)); |
2 |
26 Feb 07 |
jari |
64 |
this.getContentPane().add(drawingArea, null); |
2 |
26 Feb 07 |
jari |
65 |
this.setSize(210,50); |
2 |
26 Feb 07 |
jari |
66 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
67 |
Dimension barSize = this.getSize(); |
2 |
26 Feb 07 |
jari |
68 |
this.setLocation((screenSize.width - barSize.width) / 2, (screenSize.height - barSize.height) / 2); |
2 |
26 Feb 07 |
jari |
// this.setModal(true); |
2 |
26 Feb 07 |
jari |
70 |
this.pack(); |
2 |
26 Feb 07 |
jari |
71 |
this.show(); |
2 |
26 Feb 07 |
jari |
72 |
this.requestFocus(); |
2 |
26 Feb 07 |
jari |
73 |
this.toFront(); |
2 |
26 Feb 07 |
jari |
74 |
} |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
76 |
public void OnPaint(Graphics g) { |
2 |
26 Feb 07 |
jari |
// g.setColor(barColor); |
2 |
26 Feb 07 |
jari |
78 |
Graphics2D g2 = (Graphics2D) g; |
2 |
26 Feb 07 |
jari |
79 |
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
80 |
GradientPaint gp; |
2 |
26 Feb 07 |
jari |
81 |
gp=new GradientPaint(0,0,this.barColor1,200,0,this.barColor2); |
2 |
26 Feb 07 |
jari |
82 |
g2.setPaint(gp); |
2 |
26 Feb 07 |
jari |
83 |
g2.fillRect(5, 5, (value * 200 / units) , 40); |
2 |
26 Feb 07 |
jari |
84 |
g2.setColor(textColor); |
2 |
26 Feb 07 |
jari |
85 |
g2.drawRect(5,5,200,40); |
2 |
26 Feb 07 |
jari |
86 |
g2.setFont(progressBarFont); |
2 |
26 Feb 07 |
jari |
87 |
g2.drawString("" + (value * 100 / units) + "%", 90, 32); |
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
89 |
} |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
public ProgressBar(Frame parent, String title, int units) { |
2 |
26 Feb 07 |
jari |
92 |
this(parent, title, new Color((int) 200, (int) 200, (int) 200),new Color((int) 200, (int) 200, (int) 200), Color.black, units); |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
public ProgressBar(Frame parent, String title, Color barColor, Color textColor, int units) { |
2 |
26 Feb 07 |
jari |
96 |
this(parent, title, barColor , barColor, Color.black, units); |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
public void drawProgressBar() { |
2 |
26 Feb 07 |
jari |
100 |
if (value<units) show(); |
2 |
26 Feb 07 |
jari |
// show(); |
2 |
26 Feb 07 |
jari |
102 |
} |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
public void increment(int increment) { |
2 |
26 Feb 07 |
jari |
105 |
if (value < units) { |
2 |
26 Feb 07 |
jari |
106 |
value = value + increment; |
2 |
26 Feb 07 |
jari |
107 |
this.repaint(); |
2 |
26 Feb 07 |
jari |
108 |
} |
2 |
26 Feb 07 |
jari |
109 |
if (value >= units) { |
2 |
26 Feb 07 |
jari |
110 |
this.hide(); |
2 |
26 Feb 07 |
jari |
111 |
this.dispose(); |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
public void set(int newvalue) { |
2 |
26 Feb 07 |
jari |
116 |
value=newvalue; |
2 |
26 Feb 07 |
jari |
117 |
repaint(); |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
} |