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 java.awt.BorderLayout; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.Component; |
26 |
|
import java.awt.Dimension; |
27 |
|
import java.awt.Font; |
28 |
|
import java.awt.Graphics; |
29 |
|
import java.awt.Image; |
30 |
|
import java.awt.MediaTracker; |
31 |
|
import java.awt.event.MouseAdapter; |
32 |
|
import java.awt.event.MouseEvent; |
33 |
|
|
34 |
|
import javax.swing.JInternalFrame; |
35 |
|
import javax.swing.JLabel; |
36 |
|
import javax.swing.JLayeredPane; |
37 |
|
import javax.swing.JPanel; |
38 |
|
import javax.swing.JTextField; |
39 |
|
import javax.swing.JTextPane; |
40 |
|
import javax.swing.event.HyperlinkEvent; |
41 |
|
import javax.swing.event.HyperlinkListener; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
@version |
48 |
|
|
|
|
| 79.8% |
Uncovered Elements: 22 (109) |
Complexity: 24 |
Complexity Density: 0.29 |
|
49 |
|
public class SplashScreen extends JPanel |
50 |
|
implements Runnable, HyperlinkListener |
51 |
|
{ |
52 |
|
boolean visible = true; |
53 |
|
|
54 |
|
JPanel iconimg = new JPanel(new BorderLayout()); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
Component authlist; |
60 |
|
|
61 |
|
JInternalFrame iframe; |
62 |
|
|
63 |
|
Image image; |
64 |
|
|
65 |
|
int fontSize = 11; |
66 |
|
|
67 |
|
int yoffset = 30; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
11 |
public SplashScreen()... |
73 |
|
{ |
74 |
11 |
this(false); |
75 |
|
} |
76 |
|
|
77 |
|
private boolean interactiveDialog = false; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
|
83 |
|
|
84 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
85 |
11 |
public SplashScreen(boolean interactive)... |
86 |
|
{ |
87 |
11 |
this.interactiveDialog = interactive; |
88 |
|
|
89 |
11 |
if ( false) |
90 |
|
{ |
91 |
0 |
authlist = new JLabel(""); |
92 |
0 |
run(); |
93 |
|
} |
94 |
|
else |
95 |
|
{ |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
{ |
100 |
11 |
authlist = new JTextPane(); |
101 |
11 |
Thread t = new Thread(this); |
102 |
11 |
t.start(); |
103 |
|
} |
104 |
|
} |
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
|
MouseAdapter closer = new MouseAdapter() |
109 |
|
{ |
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
110 |
0 |
public void mousePressed(MouseEvent evt)... |
111 |
|
{ |
112 |
0 |
try |
113 |
|
{ |
114 |
0 |
if (!interactiveDialog) |
115 |
|
{ |
116 |
0 |
visible = false; |
117 |
0 |
closeSplash(); |
118 |
|
} |
119 |
|
} catch (Exception ex) |
120 |
|
{ |
121 |
|
} |
122 |
|
} |
123 |
|
}; |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
|
|
| 89.2% |
Uncovered Elements: 4 (37) |
Complexity: 6 |
Complexity Density: 0.19 |
|
129 |
11 |
void initSplashScreenWindow()... |
130 |
|
{ |
131 |
11 |
addMouseListener(closer); |
132 |
11 |
try |
133 |
|
{ |
134 |
11 |
java.net.URL url = getClass().getResource("/images/Jalview_Logo.png"); |
135 |
11 |
java.net.URL urllogo = getClass() |
136 |
|
.getResource("/images/Jalview_Logo_small.png"); |
137 |
|
|
138 |
11 |
if ( url != null) |
139 |
|
{ |
140 |
11 |
image = java.awt.Toolkit.getDefaultToolkit().createImage(url); |
141 |
11 |
Image logo = java.awt.Toolkit.getDefaultToolkit() |
142 |
|
.createImage(urllogo); |
143 |
11 |
MediaTracker mt = new MediaTracker(this); |
144 |
11 |
mt.addImage(image, 0); |
145 |
11 |
mt.addImage(logo, 1); |
146 |
11 |
do |
147 |
|
{ |
148 |
11 |
try |
149 |
|
{ |
150 |
11 |
mt.waitForAll(); |
151 |
|
} catch (InterruptedException x) |
152 |
|
{ |
153 |
|
} |
154 |
11 |
; |
155 |
11 |
if (mt.isErrorAny()) |
156 |
|
{ |
157 |
0 |
System.err.println("Error when loading images!"); |
158 |
|
} |
159 |
11 |
} while (!mt.checkAll()); |
160 |
11 |
Desktop.instance.setIconImage(logo); |
161 |
|
} |
162 |
|
} catch (Exception ex) |
163 |
|
{ |
164 |
|
} |
165 |
|
|
166 |
11 |
iframe = new JInternalFrame(); |
167 |
11 |
iframe.setFrameIcon(null); |
168 |
11 |
iframe.setClosable(interactiveDialog); |
169 |
11 |
this.setLayout(new BorderLayout()); |
170 |
11 |
iframe.setContentPane(this); |
171 |
11 |
iframe.setLayer(JLayeredPane.PALETTE_LAYER); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
{ |
177 |
11 |
((JTextPane) authlist).setEditable(false); |
178 |
|
|
179 |
11 |
SplashImage splashimg = new SplashImage(image); |
180 |
11 |
iconimg.add(splashimg, BorderLayout.CENTER); |
181 |
11 |
add(iconimg, BorderLayout.NORTH); |
182 |
|
} |
183 |
11 |
add(authlist, BorderLayout.CENTER); |
184 |
11 |
authlist.addMouseListener(closer); |
185 |
11 |
Desktop.desktop.add(iframe); |
186 |
11 |
refreshText(); |
187 |
|
} |
188 |
|
|
189 |
|
long oldtext = -1; |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 2 |
Complexity Density: 0.09 |
|
194 |
114 |
@SuppressWarnings("unused")... |
195 |
|
protected boolean refreshText() |
196 |
|
{ |
197 |
114 |
String newtext = Desktop.instance.getAboutMessage(true).toString(); |
198 |
|
|
199 |
113 |
if (oldtext != newtext.length()) |
200 |
|
{ |
201 |
11 |
iframe.setVisible(false); |
202 |
11 |
oldtext = newtext.length(); |
203 |
11 |
if ( false) |
204 |
|
{ |
205 |
0 |
authlist = new JLabel("<html><br/><br/><img src=\"swingjs/j2s/images/Jalview_Logo.png\"/><br/>"+newtext); |
206 |
0 |
((JLabel) authlist).setOpaque(true); |
207 |
0 |
((JLabel) authlist).setBackground(Color.white); |
208 |
|
} else { |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
{ |
213 |
11 |
authlist = new JTextPane(); |
214 |
11 |
((JTextPane) authlist).setEditable(false); |
215 |
11 |
((JTextPane) authlist).setContentType("text/html"); |
216 |
11 |
((JTextPane) authlist).setText(newtext); |
217 |
11 |
((JTextPane) authlist).addHyperlinkListener(this); |
218 |
|
} |
219 |
|
} |
220 |
11 |
authlist.addMouseListener(closer); |
221 |
|
|
222 |
11 |
authlist.setVisible(true); |
223 |
11 |
authlist.setSize(new Dimension(750, 375)); |
224 |
11 |
add(authlist, BorderLayout.CENTER); |
225 |
11 |
revalidate(); |
226 |
11 |
iframe.setBounds((Desktop.instance.getWidth() - 750) / 2, |
227 |
|
(Desktop.instance.getHeight() - 375) / 2, 750, |
228 |
|
authlist.getHeight() + iconimg.getHeight()); |
229 |
11 |
iframe.validate(); |
230 |
11 |
iframe.setVisible(true); |
231 |
11 |
return true; |
232 |
|
} |
233 |
103 |
return false; |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
|
|
| 81.8% |
Uncovered Elements: 4 (22) |
Complexity: 8 |
Complexity Density: 0.57 |
|
239 |
11 |
public void run()... |
240 |
|
{ |
241 |
11 |
initSplashScreenWindow(); |
242 |
|
|
243 |
11 |
long startTime = System.currentTimeMillis() / 1000; |
244 |
|
|
245 |
124 |
while (visible) |
246 |
|
{ |
247 |
114 |
iframe.repaint(); |
248 |
114 |
try |
249 |
|
{ |
250 |
114 |
Thread.sleep(500); |
251 |
|
} catch (Exception ex) |
252 |
|
{ |
253 |
|
} |
254 |
|
|
255 |
113 |
if (!interactiveDialog |
256 |
|
&& ((System.currentTimeMillis() / 1000) - startTime) > 5) |
257 |
|
{ |
258 |
10 |
visible = false; |
259 |
|
} |
260 |
|
|
261 |
113 |
if (visible && refreshText()) |
262 |
|
{ |
263 |
|
|
264 |
0 |
iframe.repaint(); |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
} |
269 |
113 |
if (interactiveDialog) |
270 |
|
{ |
271 |
0 |
return; |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
10 |
closeSplash(); |
276 |
10 |
Desktop.instance.startDialogQueue(); |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
282 |
10 |
public void closeSplash()... |
283 |
|
{ |
284 |
10 |
try |
285 |
|
{ |
286 |
|
|
287 |
10 |
iframe.setClosed(true); |
288 |
|
} catch (Exception ex) |
289 |
|
{ |
290 |
|
} |
291 |
|
} |
292 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 5 |
Complexity Density: 0.5 |
|
293 |
|
public class SplashImage extends JPanel |
294 |
|
{ |
295 |
|
Image image; |
296 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
297 |
11 |
public SplashImage(Image todisplay)... |
298 |
|
{ |
299 |
11 |
image = todisplay; |
300 |
11 |
if (image!=null) |
301 |
11 |
{ setPreferredSize(new Dimension(image.getWidth(this) + 8, |
302 |
|
image.getHeight(this))); |
303 |
|
} |
304 |
|
} |
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
26 |
@Override... |
307 |
|
public Dimension getPreferredSize() |
308 |
|
{ |
309 |
26 |
return new Dimension(image.getWidth(this) + 8, image.getHeight(this)); |
310 |
|
} |
311 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
312 |
277 |
public void paintComponent(Graphics g)... |
313 |
|
{ |
314 |
277 |
g.setColor(Color.white); |
315 |
277 |
g.fillRect(0, 0, getWidth(), getHeight()); |
316 |
277 |
g.setColor(Color.black); |
317 |
277 |
g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6)); |
318 |
|
|
319 |
277 |
if (image != null) |
320 |
|
{ |
321 |
277 |
g.drawImage(image, (getWidth() - image.getWidth(this)) / 2, |
322 |
|
(getHeight() - image.getHeight(this)) / 2, this); |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
} |
366 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
367 |
0 |
@Override... |
368 |
|
public void hyperlinkUpdate(HyperlinkEvent e) |
369 |
|
{ |
370 |
0 |
Desktop.hyperlinkUpdate(e); |
371 |
|
|
372 |
|
} |
373 |
|
} |