1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.util.MessageManager; |
24 |
|
|
25 |
|
import java.awt.BorderLayout; |
26 |
|
import java.awt.Component; |
27 |
|
import java.awt.GridLayout; |
28 |
|
import java.awt.event.ActionEvent; |
29 |
|
import java.awt.event.ActionListener; |
30 |
|
import java.util.Hashtable; |
31 |
|
import java.util.Map; |
32 |
|
|
33 |
|
import javax.swing.JButton; |
34 |
|
import javax.swing.JLabel; |
35 |
|
import javax.swing.JPanel; |
36 |
|
import javax.swing.JProgressBar; |
37 |
|
import javax.swing.SwingUtilities; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 63.9% |
Uncovered Elements: 30 (83) |
Complexity: 21 |
Complexity Density: 0.38 |
|
45 |
|
public class ProgressBar implements IProgressIndicator |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
Map<Long, JPanel> progressBars; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
Map<Long, IProgressIndicatorHandler> progressBarHandlers; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private JPanel statusPanel; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private JLabel statusBar; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@param |
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
79 |
197 |
public ProgressBar(JPanel container, JLabel statusBar)... |
80 |
|
{ |
81 |
197 |
if (container == null) |
82 |
|
{ |
83 |
1 |
throw new NullPointerException(); |
84 |
|
} |
85 |
196 |
if (!GridLayout.class |
86 |
|
.isAssignableFrom(container.getLayout().getClass())) |
87 |
|
{ |
88 |
1 |
throw new IllegalArgumentException("Container must have GridLayout"); |
89 |
|
} |
90 |
195 |
this.statusPanel = container; |
91 |
195 |
this.statusBar = statusBar; |
92 |
195 |
this.progressBars = new Hashtable<>(); |
93 |
195 |
this.progressBarHandlers = new Hashtable<>(); |
94 |
|
|
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@return |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
102 |
0 |
@Override... |
103 |
|
public boolean operationInProgress() |
104 |
|
{ |
105 |
0 |
if (progressBars != null && progressBars.size() > 0) |
106 |
|
{ |
107 |
0 |
return true; |
108 |
|
} |
109 |
0 |
return false; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
14 |
@Override... |
122 |
|
public void setProgressBar(final String message, final long id) |
123 |
|
{ |
124 |
14 |
SwingUtilities.invokeLater(new Runnable() |
125 |
|
{ |
|
|
| 90.9% |
Uncovered Elements: 2 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
126 |
14 |
@Override... |
127 |
|
public void run() |
128 |
|
{ |
129 |
14 |
JPanel progressPanel = progressBars.get(id); |
130 |
14 |
if (progressPanel != null) |
131 |
|
{ |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
7 |
progressBars.remove(id); |
136 |
7 |
if (message != null && statusBar != null) |
137 |
|
{ |
138 |
1 |
statusBar.setText(message); |
139 |
|
} |
140 |
7 |
if (progressBarHandlers.containsKey(id)) |
141 |
|
{ |
142 |
0 |
progressBarHandlers.remove(id); |
143 |
|
} |
144 |
7 |
removeRow(progressPanel); |
145 |
|
} |
146 |
|
else |
147 |
|
{ |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
7 |
progressPanel = new JPanel(new BorderLayout(10, 5)); |
152 |
|
|
153 |
7 |
JProgressBar progressBar = new JProgressBar(); |
154 |
7 |
progressBar.setIndeterminate(true); |
155 |
|
|
156 |
7 |
progressPanel.add(new JLabel(message), BorderLayout.WEST); |
157 |
7 |
progressPanel.add(progressBar, BorderLayout.CENTER); |
158 |
|
|
159 |
7 |
addRow(progressPanel); |
160 |
|
|
161 |
7 |
progressBars.put(id, progressPanel); |
162 |
|
} |
163 |
|
|
164 |
14 |
refreshLayout(); |
165 |
|
} |
166 |
|
}); |
167 |
|
|
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
173 |
14 |
protected void refreshLayout()... |
174 |
|
{ |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
14 |
Component root = SwingUtilities.getRoot(statusPanel); |
179 |
14 |
if (root != null) |
180 |
|
{ |
181 |
8 |
root.validate(); |
182 |
|
} |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
@param |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
190 |
7 |
protected void removeRow(JPanel progressPanel)... |
191 |
|
{ |
192 |
7 |
synchronized (statusPanel) |
193 |
|
{ |
194 |
7 |
statusPanel.remove(progressPanel); |
195 |
7 |
GridLayout layout = (GridLayout) statusPanel.getLayout(); |
196 |
7 |
layout.setRows(layout.getRows() - 1); |
197 |
7 |
statusPanel.remove(progressPanel); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
206 |
7 |
protected void addRow(JPanel progressPanel)... |
207 |
|
{ |
208 |
7 |
synchronized (statusPanel) |
209 |
|
{ |
210 |
7 |
GridLayout layout = (GridLayout) statusPanel.getLayout(); |
211 |
7 |
layout.setRows(layout.getRows() + 1); |
212 |
7 |
statusPanel.add(progressPanel); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
220 |
0 |
@Override... |
221 |
|
public void registerHandler(final long id, |
222 |
|
final IProgressIndicatorHandler handler) |
223 |
|
{ |
224 |
0 |
final IProgressIndicator us = this; |
225 |
|
|
226 |
0 |
SwingUtilities.invokeLater(new Runnable() |
227 |
|
{ |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
228 |
0 |
@Override... |
229 |
|
public void run() |
230 |
|
{ |
231 |
0 |
final JPanel progressPanel = progressBars.get(id); |
232 |
0 |
if (progressPanel == null) |
233 |
|
{ |
234 |
0 |
System.err.println( |
235 |
|
"call setProgressBar before registering the progress bar's handler."); |
236 |
0 |
return; |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
0 |
if (!handler.canCancel()) |
243 |
|
{ |
244 |
0 |
return; |
245 |
|
} |
246 |
|
|
247 |
0 |
progressBarHandlers.put(id, handler); |
248 |
0 |
JButton cancel = new JButton( |
249 |
|
MessageManager.getString("action.cancel")); |
250 |
0 |
cancel.addActionListener(new ActionListener() |
251 |
|
{ |
252 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
253 |
0 |
@Override... |
254 |
|
public void actionPerformed(ActionEvent e) |
255 |
|
{ |
256 |
0 |
handler.cancelActivity(id); |
257 |
0 |
us.setProgressBar(MessageManager |
258 |
|
.formatMessage("label.cancelled_params", new Object[] |
259 |
|
{ ((JLabel) progressPanel.getComponent(0)).getText() }), |
260 |
|
id); |
261 |
|
} |
262 |
|
}); |
263 |
0 |
progressPanel.add(cancel, BorderLayout.EAST); |
264 |
0 |
refreshLayout(); |
265 |
|
|
266 |
|
} |
267 |
|
}); |
268 |
|
} |
269 |
|
|
270 |
|
} |