2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2005, 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: SlideLoaderProgressBar.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:52:17 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.file; |
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.Container; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
25 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JProgressBar; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.ISlideData; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.ISlideMetaData; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
public class SlideLoaderProgressBar extends JDialog { |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
protected static final int BUFFER_SIZE = 1024*128; |
2 |
26 Feb 07 |
jari |
43 |
private int result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
44 |
private ISlideData[] data; |
2 |
26 Feb 07 |
jari |
45 |
protected ISlideMetaData meta; |
2 |
26 Feb 07 |
jari |
46 |
private File[] files; |
2 |
26 Feb 07 |
jari |
47 |
private boolean stop = false; |
2 |
26 Feb 07 |
jari |
48 |
private Exception exception; |
2 |
26 Feb 07 |
jari |
49 |
private LoadingPanel loadingPanel = new LoadingPanel(); |
2 |
26 Feb 07 |
jari |
50 |
private boolean fillMissingSpots = false; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a <code>SlideDataLoader</code> to load data from the |
2 |
26 Feb 07 |
jari |
* specified file. |
2 |
26 Feb 07 |
jari |
55 |
*/ |
2 |
26 Feb 07 |
jari |
/* public SlideDataLoader(JFrame frame, ISlideMetaData meta, File file, boolean fillMissingSpots) { |
2 |
26 Feb 07 |
jari |
this(frame, meta, new File[] {file}, fillMissingSpots); |
2 |
26 Feb 07 |
jari |
58 |
} |
2 |
26 Feb 07 |
jari |
59 |
*/ |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a <code>SlideDataLoader</code> to load data from the |
2 |
26 Feb 07 |
jari |
* specified array of files. |
2 |
26 Feb 07 |
jari |
64 |
*/ |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
public SlideLoaderProgressBar(JFrame frame) { |
2 |
26 Feb 07 |
jari |
67 |
super(frame, "Slide Data Loading"); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
70 |
|
2 |
26 Feb 07 |
jari |
71 |
JPanel btnsPanel = createBtnsPanel(listener); |
2 |
26 Feb 07 |
jari |
72 |
|
2 |
26 Feb 07 |
jari |
73 |
Container content = getContentPane(); |
2 |
26 Feb 07 |
jari |
74 |
content.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
75 |
content.add(loadingPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
76 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
77 |
content.add(btnsPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
78 |
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 8, 4, 8), 0, 0)); |
2 |
26 Feb 07 |
jari |
79 |
|
2 |
26 Feb 07 |
jari |
80 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
81 |
pack(); |
2 |
26 Feb 07 |
jari |
82 |
} |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
// public SlideLoaderProgressBar(JFrame frame) { |
2 |
26 Feb 07 |
jari |
// super(frame, "Slide Data Loading", true); |
2 |
26 Feb 07 |
jari |
// this.loadingPanel = new LoadingPanel(); |
2 |
26 Feb 07 |
jari |
88 |
// } |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog to load files with specified type of format. |
2 |
26 Feb 07 |
jari |
93 |
*/ |
2 |
26 Feb 07 |
jari |
94 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
95 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
96 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
97 |
show(); |
2 |
26 Feb 07 |
jari |
98 |
return result; |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a panel with 'cancel' button. |
2 |
26 Feb 07 |
jari |
103 |
*/ |
2 |
26 Feb 07 |
jari |
104 |
private JPanel createBtnsPanel(ActionListener listener) { |
2 |
26 Feb 07 |
jari |
105 |
JPanel panel = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
106 |
JButton cancelButton = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
107 |
cancelButton.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
108 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
109 |
panel.add(cancelButton, BorderLayout.EAST); |
2 |
26 Feb 07 |
jari |
110 |
getRootPane().setDefaultButton(cancelButton); |
2 |
26 Feb 07 |
jari |
111 |
return panel; |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
/** |
2 |
26 Feb 07 |
jari |
* Sets max value for the 'files' progress bar. |
2 |
26 Feb 07 |
jari |
116 |
*/ |
2 |
26 Feb 07 |
jari |
117 |
public void setFilesCount(int count) { |
2 |
26 Feb 07 |
jari |
118 |
loadingPanel.setFilesCount(count); |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
/** |
2 |
26 Feb 07 |
jari |
* Sets max value for the 'file' progress bar. |
2 |
26 Feb 07 |
jari |
123 |
*/ |
2 |
26 Feb 07 |
jari |
124 |
public void setLinesCount(int count) { |
2 |
26 Feb 07 |
jari |
125 |
loadingPanel.setLinesCount(count); |
2 |
26 Feb 07 |
jari |
126 |
} |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
/** |
2 |
26 Feb 07 |
jari |
* Sets current value of the 'files' progress bar. |
2 |
26 Feb 07 |
jari |
130 |
*/ |
2 |
26 Feb 07 |
jari |
131 |
public void setFilesProgress(int value) { |
2 |
26 Feb 07 |
jari |
132 |
loadingPanel.setFilesProgress(value); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
/** |
2 |
26 Feb 07 |
jari |
* Sets current value of the 'file' progress bar. |
2 |
26 Feb 07 |
jari |
137 |
*/ |
2 |
26 Feb 07 |
jari |
138 |
public void setFileProgress(int value) { |
2 |
26 Feb 07 |
jari |
139 |
loadingPanel.setFileProgress(value); |
2 |
26 Feb 07 |
jari |
140 |
} |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
/** |
2 |
26 Feb 07 |
jari |
* Sets name of a loaded file. |
2 |
26 Feb 07 |
jari |
144 |
*/ |
2 |
26 Feb 07 |
jari |
145 |
public void setFileName(String filename) { |
2 |
26 Feb 07 |
jari |
146 |
loadingPanel.setFileName(filename); |
2 |
26 Feb 07 |
jari |
147 |
} |
2 |
26 Feb 07 |
jari |
148 |
|
2 |
26 Feb 07 |
jari |
149 |
/** |
2 |
26 Feb 07 |
jari |
* Sets common progress description. |
2 |
26 Feb 07 |
jari |
151 |
*/ |
2 |
26 Feb 07 |
jari |
152 |
public void setRemain(int count) { |
2 |
26 Feb 07 |
jari |
153 |
loadingPanel.setRemain(count); |
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to window and an action events. |
2 |
26 Feb 07 |
jari |
158 |
*/ |
2 |
26 Feb 07 |
jari |
159 |
private class Listener extends WindowAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
//abort(); |
2 |
26 Feb 07 |
jari |
//setResult(JOptionPane.CANCEL_OPTION); |
2 |
26 Feb 07 |
jari |
164 |
dispose(); |
2 |
26 Feb 07 |
jari |
165 |
} |
2 |
26 Feb 07 |
jari |
166 |
|
2 |
26 Feb 07 |
jari |
167 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
// abort(); |
2 |
26 Feb 07 |
jari |
// setResult(JOptionPane.CLOSED_OPTION); |
2 |
26 Feb 07 |
jari |
170 |
dispose(); |
2 |
26 Feb 07 |
jari |
171 |
} |
2 |
26 Feb 07 |
jari |
172 |
} |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
/** |
2 |
26 Feb 07 |
jari |
* The panel to display a loading progress. |
2 |
26 Feb 07 |
jari |
176 |
*/ |
2 |
26 Feb 07 |
jari |
177 |
private class LoadingPanel extends JPanel { |
2 |
26 Feb 07 |
jari |
178 |
|
2 |
26 Feb 07 |
jari |
179 |
private JProgressBar filesProgress = new JProgressBar(); |
2 |
26 Feb 07 |
jari |
180 |
private JProgressBar fileProgress = new JProgressBar(); |
2 |
26 Feb 07 |
jari |
181 |
private JLabel filesLabel = new JLabel("Remain: "); |
2 |
26 Feb 07 |
jari |
182 |
private JLabel fileLabel = new JLabel("File: "); |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>LoadingPanel</code>. |
2 |
26 Feb 07 |
jari |
186 |
*/ |
2 |
26 Feb 07 |
jari |
187 |
public LoadingPanel() { |
2 |
26 Feb 07 |
jari |
188 |
setPreferredSize(new Dimension(350, 120)); |
2 |
26 Feb 07 |
jari |
189 |
setBorder(new BevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
190 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
191 |
filesProgress.setStringPainted(true); |
2 |
26 Feb 07 |
jari |
192 |
fileProgress.setStringPainted(true); |
2 |
26 Feb 07 |
jari |
193 |
add(filesLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
194 |
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); |
2 |
26 Feb 07 |
jari |
195 |
add(filesProgress, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
196 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); |
2 |
26 Feb 07 |
jari |
197 |
add(fileLabel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
198 |
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); |
2 |
26 Feb 07 |
jari |
199 |
add(fileProgress, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
200 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); |
2 |
26 Feb 07 |
jari |
201 |
} |
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
203 |
/** |
2 |
26 Feb 07 |
jari |
* Sets max value for the 'files' progress bar. |
2 |
26 Feb 07 |
jari |
205 |
*/ |
2 |
26 Feb 07 |
jari |
206 |
public void setFilesCount(int count) { |
2 |
26 Feb 07 |
jari |
207 |
filesProgress.setMaximum(count); |
2 |
26 Feb 07 |
jari |
208 |
} |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
/** |
2 |
26 Feb 07 |
jari |
* Sets max value for the 'file' progress bar. |
2 |
26 Feb 07 |
jari |
212 |
*/ |
2 |
26 Feb 07 |
jari |
213 |
public void setLinesCount(int count) { |
2 |
26 Feb 07 |
jari |
214 |
fileProgress.setMaximum(count); |
2 |
26 Feb 07 |
jari |
215 |
} |
2 |
26 Feb 07 |
jari |
216 |
|
2 |
26 Feb 07 |
jari |
217 |
/** |
2 |
26 Feb 07 |
jari |
* Sets current value of the 'files' progress bar. |
2 |
26 Feb 07 |
jari |
219 |
*/ |
2 |
26 Feb 07 |
jari |
220 |
public void setFilesProgress(int value) { |
2 |
26 Feb 07 |
jari |
221 |
filesProgress.setValue(value); |
2 |
26 Feb 07 |
jari |
222 |
} |
2 |
26 Feb 07 |
jari |
223 |
|
2 |
26 Feb 07 |
jari |
224 |
/** |
2 |
26 Feb 07 |
jari |
* Sets current value of the 'file' progress bar. |
2 |
26 Feb 07 |
jari |
226 |
*/ |
2 |
26 Feb 07 |
jari |
227 |
public void setFileProgress(int value) { |
2 |
26 Feb 07 |
jari |
228 |
fileProgress.setValue(value); |
2 |
26 Feb 07 |
jari |
229 |
} |
2 |
26 Feb 07 |
jari |
230 |
|
2 |
26 Feb 07 |
jari |
231 |
/** |
2 |
26 Feb 07 |
jari |
* Sets name of a loaded file. |
2 |
26 Feb 07 |
jari |
233 |
*/ |
2 |
26 Feb 07 |
jari |
234 |
public void setFileName(String filename) { |
2 |
26 Feb 07 |
jari |
235 |
fileLabel.setText("File: "+filename); |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
/** |
2 |
26 Feb 07 |
jari |
* Sets common progress description. |
2 |
26 Feb 07 |
jari |
240 |
*/ |
2 |
26 Feb 07 |
jari |
241 |
public void setRemain(int count) { |
2 |
26 Feb 07 |
jari |
242 |
filesLabel.setText(String.valueOf(count)+" file(s) remaining to load."); |
2 |
26 Feb 07 |
jari |
243 |
} |
2 |
26 Feb 07 |
jari |
244 |
} |
2 |
26 Feb 07 |
jari |
245 |
} |