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: ProgressDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
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.awt; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Container; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GradientPaint; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
24 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.ImageIcon; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
public class ProgressDialog extends JDialog { |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
protected JFrame parent; |
2 |
26 Feb 07 |
jari |
35 |
protected String title; |
2 |
26 Feb 07 |
jari |
36 |
protected Container contentPane; |
2 |
26 Feb 07 |
jari |
37 |
protected GBA gba; |
2 |
26 Feb 07 |
jari |
38 |
protected JPanel labelPanel; |
2 |
26 Feb 07 |
jari |
39 |
protected JPanel mainPanel; |
2 |
26 Feb 07 |
jari |
40 |
protected JLabel[] labels; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
protected Vector timers; |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
public ProgressDialog(JFrame parent, String title, boolean modal, int labelCount) { |
2 |
26 Feb 07 |
jari |
45 |
super(parent, title, modal); |
2 |
26 Feb 07 |
jari |
46 |
this.parent = parent; |
2 |
26 Feb 07 |
jari |
47 |
this.title = title; |
2 |
26 Feb 07 |
jari |
48 |
labels = new JLabel[labelCount]; |
2 |
26 Feb 07 |
jari |
49 |
mainPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
50 |
contentPane = getContentPane(); |
2 |
26 Feb 07 |
jari |
51 |
gba = new GBA(); |
2 |
26 Feb 07 |
jari |
52 |
timers = new Vector(); |
2 |
26 Feb 07 |
jari |
53 |
initializeGUI(); |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
public void initializeGUI() { |
2 |
26 Feb 07 |
jari |
57 |
mainPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,5,0,5)); |
2 |
26 Feb 07 |
jari |
58 |
contentPane.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
59 |
contentPane.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
// contentPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,5,0,5)); |
2 |
26 Feb 07 |
jari |
61 |
labelPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
62 |
labelPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
63 |
labelPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
64 |
labelPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
for (int i = 0; i < labels.length; i++) { |
2 |
26 Feb 07 |
jari |
69 |
labels[i] = new JLabel(title); |
2 |
26 Feb 07 |
jari |
70 |
labels[i].setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
71 |
gba.add(labelPanel, labels[i], 0, i, 1, 1, 1, 0, GBA.H, GBA.C); |
2 |
26 Feb 07 |
jari |
72 |
} |
2 |
26 Feb 07 |
jari |
73 |
gba.add(mainPanel, labelPanel, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
gba.add(contentPane, new HeaderImagePanel(), 0, 0, 1, 1, 1, 0, GBA.B, GBA.W); |
2 |
26 Feb 07 |
jari |
76 |
gba.add(contentPane, mainPanel, 0, 1, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
79 |
Dimension mySize = getSize(); |
2 |
26 Feb 07 |
jari |
80 |
setLocation((screenSize.width - mySize.width) / 2, (screenSize.height - mySize.height) / 2); |
2 |
26 Feb 07 |
jari |
81 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
82 |
pack(); |
2 |
26 Feb 07 |
jari |
83 |
setSize(405, 350); |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
public JPanel getLabelPanel() { |
2 |
26 Feb 07 |
jari |
87 |
return this.labelPanel; |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
public void setMainPanel(JPanel panel) { |
2 |
26 Feb 07 |
jari |
//contentPane.removeAll(); |
2 |
26 Feb 07 |
jari |
92 |
gba.add(mainPanel, panel, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
93 |
repaint(); |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
public void setMessage(int labelIndex, String message) { |
2 |
26 Feb 07 |
jari |
97 |
setMessage(labelIndex, message, Color.black); |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
public void setMessage(int labelIndex, String message, Color color) { |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
102 |
if (labelIndex >= labels.length) throw new ArrayIndexOutOfBoundsException(); |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
JLabel label = labels[labelIndex]; |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
if (label != null) { |
2 |
26 Feb 07 |
jari |
107 |
label.setForeground(color); |
2 |
26 Feb 07 |
jari |
108 |
label.setText(message); |
2 |
26 Feb 07 |
jari |
109 |
label.repaint(); |
2 |
26 Feb 07 |
jari |
110 |
} |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
public void dismiss() { |
2 |
26 Feb 07 |
jari |
114 |
setVisible(false); |
2 |
26 Feb 07 |
jari |
115 |
for (int i = 0; i < timers.size(); i++) { |
2 |
26 Feb 07 |
jari |
116 |
((TimerThread) timers.elementAt(i)).setRunning(false); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
dispose(); |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
public void setTimerLabel(final int labelIndex, final String preString, final String postString, final int ms) { |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
TimerThread timerThread = new TimerThread(labelIndex, preString, postString, ms); |
2 |
26 Feb 07 |
jari |
124 |
timerThread.setPriority(Thread.MIN_PRIORITY); |
2 |
26 Feb 07 |
jari |
125 |
timers.addElement(timerThread); |
2 |
26 Feb 07 |
jari |
126 |
timerThread.start(); |
2 |
26 Feb 07 |
jari |
127 |
} |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
130 |
ProgressDialog d = new ProgressDialog(new JFrame(), "Test Progress Dialog", true, 5); |
2 |
26 Feb 07 |
jari |
131 |
d.show(); |
2 |
26 Feb 07 |
jari |
132 |
System.exit(0); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
private class TimerThread extends Thread { |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
public boolean running = true; |
2 |
26 Feb 07 |
jari |
138 |
private int labelIndex; |
2 |
26 Feb 07 |
jari |
139 |
private String preString; |
2 |
26 Feb 07 |
jari |
140 |
private String postString; |
2 |
26 Feb 07 |
jari |
141 |
private int ms; |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
public TimerThread(int labelIndex, String preString, String postString, int ms) { |
2 |
26 Feb 07 |
jari |
144 |
this.labelIndex = labelIndex; |
2 |
26 Feb 07 |
jari |
145 |
this.preString = preString; |
2 |
26 Feb 07 |
jari |
146 |
this.postString = postString; |
2 |
26 Feb 07 |
jari |
147 |
this.ms = ms; |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
150 |
public void run() { |
2 |
26 Feb 07 |
jari |
151 |
try { |
2 |
26 Feb 07 |
jari |
152 |
long startTime = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
while (running) { |
2 |
26 Feb 07 |
jari |
155 |
long currentTime = System.currentTimeMillis(); |
2 |
26 Feb 07 |
jari |
156 |
long seconds = (long) ((currentTime - startTime) / 1000f); |
2 |
26 Feb 07 |
jari |
157 |
setMessage(labelIndex, preString + seconds + postString); |
2 |
26 Feb 07 |
jari |
158 |
sleep(ms); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
} catch (InterruptedException ie) {;} |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
public void setRunning(boolean value) { |
2 |
26 Feb 07 |
jari |
165 |
running = value; |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
|
2 |
26 Feb 07 |
jari |
169 |
public class HeaderImagePanel extends JPanel{ |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
public HeaderImagePanel(){ |
2 |
26 Feb 07 |
jari |
172 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
173 |
java.net.URL url = HeaderImagePanel.class.getResource("/org/tigr/microarray/mev/cluster/gui/impl/images/dialog_banner2.gif"); |
2 |
26 Feb 07 |
jari |
174 |
JLabel iconLabel; |
2 |
26 Feb 07 |
jari |
175 |
ImageIcon icon; |
2 |
26 Feb 07 |
jari |
176 |
if (url != null){ |
2 |
26 Feb 07 |
jari |
177 |
icon = new ImageIcon(url); |
2 |
26 Feb 07 |
jari |
178 |
iconLabel = new JLabel(icon); |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
else |
2 |
26 Feb 07 |
jari |
181 |
iconLabel = new JLabel(); |
2 |
26 Feb 07 |
jari |
// JLabel iconLabel = new JLabel(javax.swing.UIManager.getIcon("/org/tigr/microarray/mev/cluster/gui/impl/images/dialog_banner2.gif")); |
2 |
26 Feb 07 |
jari |
183 |
iconLabel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
184 |
iconLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); |
2 |
26 Feb 07 |
jari |
185 |
FillPanel fillPanel = new FillPanel(); |
2 |
26 Feb 07 |
jari |
186 |
fillPanel.setBackground(Color.blue); |
2 |
26 Feb 07 |
jari |
187 |
add(iconLabel, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,new Insets(0,5,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
188 |
add(fillPanel, new GridBagConstraints(1,0,1,1,1.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
189 |
} |
2 |
26 Feb 07 |
jari |
190 |
} |
2 |
26 Feb 07 |
jari |
191 |
|
2 |
26 Feb 07 |
jari |
192 |
public class FillPanel extends JPanel{ |
2 |
26 Feb 07 |
jari |
193 |
GradientPaint gp; |
2 |
26 Feb 07 |
jari |
194 |
Color backgroundColor = new Color(25,25,169); |
2 |
26 Feb 07 |
jari |
195 |
Color fadeColor = new Color(140,220,240); |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
public void paint(Graphics g){ |
2 |
26 Feb 07 |
jari |
198 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
199 |
Graphics2D g2 = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
200 |
Dimension dim = this.getSize(); |
2 |
26 Feb 07 |
jari |
// gp = new GradientPaint(dim.width/2,0,backgroundColor,dim.width/2,dim.height/2,fadeColor); |
2 |
26 Feb 07 |
jari |
202 |
gp = new GradientPaint(0,dim.height/2,backgroundColor,dim.width,dim.height/2,fadeColor); |
2 |
26 Feb 07 |
jari |
203 |
g2.setPaint(gp); |
2 |
26 Feb 07 |
jari |
204 |
g2.fillRect(0,0,dim.width, dim.height); |
2 |
26 Feb 07 |
jari |
205 |
g2.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
} |