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: Progress.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:50 $ |
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.microarray.mev.cluster.gui.impl.dialogs; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.BorderLayout; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Container; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Dimension; |
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.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JProgressBar; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
public class Progress extends JDialog { |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
private JProgressBar progress; |
2 |
26 Feb 07 |
jari |
40 |
private JLabel description; |
2 |
26 Feb 07 |
jari |
41 |
private static final String DESCRIPTION = "Description: "; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a <code>Progress</code> with specified parent, a title and |
2 |
26 Feb 07 |
jari |
* dialog listener. |
2 |
26 Feb 07 |
jari |
46 |
*/ |
2 |
26 Feb 07 |
jari |
47 |
public Progress(Frame parent, String title, DialogListener listener) { |
2 |
26 Feb 07 |
jari |
48 |
super(parent, title); |
2 |
26 Feb 07 |
jari |
49 |
this.description = new JLabel(); |
2 |
26 Feb 07 |
jari |
50 |
setDescription(""); |
2 |
26 Feb 07 |
jari |
51 |
this.progress = new JProgressBar(); |
2 |
26 Feb 07 |
jari |
52 |
this.progress.setStringPainted(true); |
2 |
26 Feb 07 |
jari |
53 |
JPanel progressPanel = createProgressPanel(this.description, this.progress); |
2 |
26 Feb 07 |
jari |
54 |
progressPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
55 |
JPanel btnsPanel = createBtnsPanel(listener); |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
Container content = getContentPane(); |
2 |
26 Feb 07 |
jari |
58 |
content.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
59 |
content.add(new HeaderImagePanel(), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
60 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
61 |
content.add(progressPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
62 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 3, 0, 3), 0, 0)); |
2 |
26 Feb 07 |
jari |
63 |
content.add(btnsPanel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
64 |
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 8, 4, 8), 0, 0)); |
2 |
26 Feb 07 |
jari |
65 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
66 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
67 |
pack(); |
2 |
26 Feb 07 |
jari |
68 |
} |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
72 |
*/ |
2 |
26 Feb 07 |
jari |
73 |
public void show() { |
2 |
26 Feb 07 |
jari |
74 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
75 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
76 |
super.show(); |
2 |
26 Feb 07 |
jari |
77 |
} |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
/** |
2 |
26 Feb 07 |
jari |
* Sets progress max value. |
2 |
26 Feb 07 |
jari |
81 |
*/ |
2 |
26 Feb 07 |
jari |
82 |
public void setUnits(int units) { |
2 |
26 Feb 07 |
jari |
83 |
progress.setMaximum(units); |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
/** |
2 |
26 Feb 07 |
jari |
* Sets progress value. |
2 |
26 Feb 07 |
jari |
88 |
*/ |
2 |
26 Feb 07 |
jari |
89 |
public void setValue(int value) { |
2 |
26 Feb 07 |
jari |
90 |
progress.setValue(value); |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
/** |
2 |
26 Feb 07 |
jari |
* Sets description. |
2 |
26 Feb 07 |
jari |
95 |
*/ |
2 |
26 Feb 07 |
jari |
96 |
public void setDescription(String text) { |
2 |
26 Feb 07 |
jari |
97 |
if (text == null) { |
2 |
26 Feb 07 |
jari |
98 |
text = ""; |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
description.setText(DESCRIPTION+text); |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
104 |
Progress p = new Progress(new Frame(), "Test Progress", null); |
2 |
26 Feb 07 |
jari |
105 |
p.show(); |
2 |
26 Feb 07 |
jari |
// System.exit(0); |
2 |
26 Feb 07 |
jari |
107 |
} |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a progress bar panel. |
2 |
26 Feb 07 |
jari |
111 |
*/ |
2 |
26 Feb 07 |
jari |
112 |
private JPanel createProgressPanel(JLabel description, JProgressBar progress) { |
2 |
26 Feb 07 |
jari |
113 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
114 |
panel.setBorder(new BevelBorder(BevelBorder.LOWERED)); |
2 |
26 Feb 07 |
jari |
115 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
116 |
gbc.insets = new Insets(5, 5, 5, 5); |
2 |
26 Feb 07 |
jari |
117 |
gbc.gridx = 0; |
2 |
26 Feb 07 |
jari |
118 |
gbc.fill = GridBagConstraints.BOTH; |
2 |
26 Feb 07 |
jari |
119 |
gbc.weightx = 1.0; |
2 |
26 Feb 07 |
jari |
120 |
gbc.weighty = 1.0; |
2 |
26 Feb 07 |
jari |
121 |
panel.add(progress, gbc); |
2 |
26 Feb 07 |
jari |
122 |
gbc.insets = new Insets(0, 5, 5, 5); |
2 |
26 Feb 07 |
jari |
123 |
gbc.gridy = 1; |
2 |
26 Feb 07 |
jari |
124 |
gbc.weighty = 0.0; |
2 |
26 Feb 07 |
jari |
125 |
panel.add(description, gbc); |
2 |
26 Feb 07 |
jari |
126 |
panel.setPreferredSize(new Dimension(400, 65)); |
2 |
26 Feb 07 |
jari |
127 |
return panel; |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a panel with cancel button. |
2 |
26 Feb 07 |
jari |
132 |
*/ |
2 |
26 Feb 07 |
jari |
133 |
private JPanel createBtnsPanel(ActionListener listener) { |
2 |
26 Feb 07 |
jari |
134 |
JPanel panel = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
135 |
JButton cancelButton = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
136 |
cancelButton.setBorder(javax.swing.BorderFactory.createBevelBorder(BevelBorder.RAISED, new Color(240,240,240), new Color(180,180,180), new Color(10,0,0), new Color(10,10,10) )); |
2 |
26 Feb 07 |
jari |
137 |
cancelButton.setPreferredSize(new Dimension(80,25)); |
2 |
26 Feb 07 |
jari |
138 |
cancelButton.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
139 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
140 |
cancelButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
141 |
panel.add(cancelButton, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
142 |
getRootPane().setDefaultButton(cancelButton); |
2 |
26 Feb 07 |
jari |
143 |
return panel; |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
|
2 |
26 Feb 07 |
jari |
146 |
public class HeaderImagePanel extends JPanel{ |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
public HeaderImagePanel(){ |
2 |
26 Feb 07 |
jari |
149 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
150 |
JLabel iconLabel = new JLabel(GUIFactory.getIcon("dialog_banner2.gif")); |
2 |
26 Feb 07 |
jari |
151 |
iconLabel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
152 |
iconLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); |
2 |
26 Feb 07 |
jari |
153 |
FillPanel fillPanel = new FillPanel(); |
2 |
26 Feb 07 |
jari |
154 |
fillPanel.setBackground(Color.blue); |
2 |
26 Feb 07 |
jari |
155 |
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 |
156 |
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 |
157 |
} |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
public class FillPanel extends JPanel{ |
2 |
26 Feb 07 |
jari |
161 |
GradientPaint gp; |
2 |
26 Feb 07 |
jari |
162 |
Color backgroundColor = new Color(25,25,169); |
2 |
26 Feb 07 |
jari |
163 |
Color fadeColor = new Color(140,220,240); |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
public void paint(Graphics g){ |
2 |
26 Feb 07 |
jari |
166 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
167 |
Graphics2D g2 = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
168 |
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 |
170 |
gp = new GradientPaint(0,dim.height/2,backgroundColor,dim.width,dim.height/2,fadeColor); |
2 |
26 Feb 07 |
jari |
171 |
g2.setPaint(gp); |
2 |
26 Feb 07 |
jari |
172 |
g2.fillRect(0,0,dim.width, dim.height); |
2 |
26 Feb 07 |
jari |
173 |
g2.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
} |