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.JTextPane; |
39 |
|
import javax.swing.SwingUtilities; |
40 |
|
import javax.swing.event.HyperlinkEvent; |
41 |
|
import javax.swing.event.HyperlinkListener; |
42 |
|
|
43 |
|
import jalview.util.ChannelProperties; |
44 |
|
import jalview.util.Platform; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@author |
50 |
|
@version |
51 |
|
|
|
|
| 80.5% |
Uncovered Elements: 30 (154) |
Complexity: 33 |
Complexity Density: 0.29 |
|
52 |
|
public class SplashScreen extends JPanel |
53 |
|
implements Runnable, HyperlinkListener |
54 |
|
{ |
55 |
|
private static final int SHOW_FOR_SECS = 5; |
56 |
|
|
57 |
|
private static final int FONT_SIZE = 11; |
58 |
|
|
59 |
|
private boolean visible = true; |
60 |
|
|
61 |
|
private JPanel iconimg = new JPanel(new BorderLayout()); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private static Color bg = Color.WHITE; |
66 |
|
|
67 |
|
private static Color fg = Color.BLACK; |
68 |
|
|
69 |
|
private static Font font = new Font("SansSerif", Font.PLAIN, FONT_SIZE); |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
private Component splashText; |
75 |
|
|
76 |
|
private JInternalFrame iframe; |
77 |
|
|
78 |
|
private Image image; |
79 |
|
|
80 |
|
private boolean transientDialog = false; |
81 |
|
|
82 |
|
private long oldTextLength = -1; |
83 |
|
|
84 |
|
public static int logoSize = 32; |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
private MouseAdapter closer = new MouseAdapter() |
91 |
|
{ |
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
92 |
0 |
@Override... |
93 |
|
public void mousePressed(MouseEvent evt) |
94 |
|
{ |
95 |
0 |
if (transientDialog) |
96 |
|
{ |
97 |
0 |
try |
98 |
|
{ |
99 |
0 |
visible = false; |
100 |
0 |
closeSplash(); |
101 |
|
} catch (Exception ex) |
102 |
|
{ |
103 |
|
} |
104 |
|
} |
105 |
|
} |
106 |
|
}; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
|
113 |
|
|
114 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
115 |
50 |
public SplashScreen(boolean isTransient)... |
116 |
|
{ |
117 |
50 |
this.transientDialog = isTransient; |
118 |
50 |
if (this.transientDialog) |
119 |
|
{ |
120 |
50 |
Desktop.instance.acquireDialogQueue(); |
121 |
|
} |
122 |
|
|
123 |
50 |
if (Platform.isJS()) |
124 |
|
{ |
125 |
0 |
splashText = new JLabel(""); |
126 |
0 |
run(); |
127 |
|
} |
128 |
|
else |
129 |
|
{ |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
{ |
136 |
50 |
splashText = new JTextPane(); |
137 |
50 |
splashText.setBackground(bg); |
138 |
50 |
splashText.setForeground(fg); |
139 |
50 |
splashText.setFont(font); |
140 |
50 |
Thread t = new Thread(this); |
141 |
50 |
t.start(); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
|
|
| 86.8% |
Uncovered Elements: 7 (53) |
Complexity: 9 |
Complexity Density: 0.22 |
|
150 |
50 |
void initSplashScreenWindow()... |
151 |
|
{ |
152 |
50 |
addMouseListener(closer); |
153 |
|
|
154 |
50 |
try |
155 |
|
{ |
156 |
50 |
if (!Platform.isJS()) |
157 |
|
{ |
158 |
50 |
image = ChannelProperties.getImage("banner"); |
159 |
50 |
Image logo = ChannelProperties.getImage("logo.48"); |
160 |
50 |
MediaTracker mt = new MediaTracker(this); |
161 |
50 |
if (image != null) |
162 |
|
{ |
163 |
50 |
mt.addImage(image, 0); |
164 |
|
} |
165 |
50 |
if (logo != null) |
166 |
|
{ |
167 |
50 |
mt.addImage(logo, 1); |
168 |
|
} |
169 |
50 |
do |
170 |
|
{ |
171 |
50 |
try |
172 |
|
{ |
173 |
50 |
mt.waitForAll(); |
174 |
|
} catch (InterruptedException x) |
175 |
|
{ |
176 |
|
} |
177 |
50 |
if (mt.isErrorAny()) |
178 |
|
{ |
179 |
0 |
jalview.bin.Console.errPrintln("Error when loading images!"); |
180 |
|
} |
181 |
50 |
} while (!mt.checkAll()); |
182 |
50 |
Desktop.instance.setIconImages(ChannelProperties.getIconList()); |
183 |
|
} |
184 |
|
} catch (Exception ex) |
185 |
|
{ |
186 |
|
} |
187 |
|
|
188 |
50 |
this.setBackground(bg); |
189 |
50 |
this.setForeground(fg); |
190 |
50 |
this.setFont(font); |
191 |
|
|
192 |
50 |
iframe = new JInternalFrame(); |
193 |
50 |
iframe.setFrameIcon(null); |
194 |
50 |
iframe.setClosable(true); |
195 |
50 |
this.setLayout(new BorderLayout()); |
196 |
50 |
iframe.setContentPane(this); |
197 |
50 |
iframe.setLayer(JLayeredPane.PALETTE_LAYER); |
198 |
50 |
iframe.setBackground(bg); |
199 |
50 |
iframe.setForeground(fg); |
200 |
50 |
iframe.setFont(font); |
201 |
|
|
202 |
50 |
if (Platform.isJS()) |
203 |
|
{ |
204 |
|
|
205 |
|
} |
206 |
|
else |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
{ |
213 |
50 |
((JTextPane) splashText).setEditable(false); |
214 |
50 |
splashText.setBackground(bg); |
215 |
50 |
splashText.setForeground(fg); |
216 |
50 |
splashText.setFont(font); |
217 |
|
|
218 |
50 |
SplashImage splashimg = new SplashImage(image); |
219 |
50 |
iconimg.add(splashimg, BorderLayout.LINE_START); |
220 |
50 |
iconimg.setBackground(bg); |
221 |
50 |
add(iconimg, BorderLayout.NORTH); |
222 |
|
} |
223 |
50 |
add(splashText, BorderLayout.CENTER); |
224 |
50 |
splashText.addMouseListener(closer); |
225 |
50 |
Desktop.desktop.add(iframe); |
226 |
50 |
refreshText(); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
|
|
| 82.5% |
Uncovered Elements: 7 (40) |
Complexity: 4 |
Complexity Density: 0.12 |
|
232 |
558 |
protected boolean refreshText()... |
233 |
|
{ |
234 |
559 |
String newtext = Desktop.instance.getAboutMessage(); |
235 |
|
|
236 |
|
|
237 |
559 |
if (oldTextLength != newtext.length()) |
238 |
|
{ |
239 |
71 |
iframe.setVisible(false); |
240 |
71 |
oldTextLength = newtext.length(); |
241 |
71 |
if (Platform.isJS()) |
242 |
|
{ |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
0 |
String text = "<html><br><img src=\"" |
248 |
|
+ ChannelProperties.getImageURL("banner") + "\"/>" + newtext |
249 |
|
+ "<br></html>"; |
250 |
0 |
JLabel ta = new JLabel(text); |
251 |
0 |
ta.setOpaque(true); |
252 |
0 |
ta.setBackground(Color.white); |
253 |
0 |
splashText = ta; |
254 |
|
} |
255 |
|
else |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
{ |
262 |
71 |
JTextPane jtp = new JTextPane(); |
263 |
71 |
jtp.setEditable(false); |
264 |
71 |
jtp.setBackground(bg); |
265 |
71 |
jtp.setForeground(fg); |
266 |
71 |
jtp.setFont(font); |
267 |
71 |
jtp.setContentType("text/html"); |
268 |
71 |
jtp.setText("<html>" + newtext + "</html>"); |
269 |
71 |
jtp.addHyperlinkListener(this); |
270 |
71 |
splashText = jtp; |
271 |
|
} |
272 |
71 |
splashText.addMouseListener(closer); |
273 |
|
|
274 |
71 |
splashText.setVisible(true); |
275 |
71 |
splashText.setSize(new Dimension(750, |
276 |
71 |
425 + logoSize + (Platform.isJS() ? 40 : 0))); |
277 |
71 |
splashText.setBackground(bg); |
278 |
71 |
splashText.setForeground(fg); |
279 |
71 |
splashText.setFont(font); |
280 |
71 |
add(splashText, BorderLayout.CENTER); |
281 |
71 |
revalidate(); |
282 |
71 |
int width = Math.max(splashText.getWidth(), iconimg.getWidth()); |
283 |
71 |
int height = splashText.getHeight() + iconimg.getHeight(); |
284 |
71 |
iframe.setBounds( |
285 |
|
Math.max(0, (Desktop.instance.getWidth() - width) / 2), |
286 |
|
Math.max(0, (Desktop.instance.getHeight() - height) / 2), |
287 |
|
width, height); |
288 |
71 |
iframe.validate(); |
289 |
71 |
iframe.setVisible(true); |
290 |
71 |
return true; |
291 |
|
} |
292 |
488 |
return false; |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
|
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 8 |
Complexity Density: 0.62 |
|
298 |
50 |
@Override... |
299 |
|
public void run() |
300 |
|
{ |
301 |
50 |
initSplashScreenWindow(); |
302 |
|
|
303 |
50 |
long startTime = System.currentTimeMillis() / 1000; |
304 |
|
|
305 |
608 |
while (visible) |
306 |
|
{ |
307 |
559 |
iframe.repaint(); |
308 |
559 |
try |
309 |
|
{ |
310 |
559 |
Thread.sleep(500); |
311 |
|
} catch (Exception ex) |
312 |
|
{ |
313 |
|
} |
314 |
|
|
315 |
558 |
if (transientDialog && ((System.currentTimeMillis() / 1000) |
316 |
|
- startTime) > SHOW_FOR_SECS) |
317 |
|
{ |
318 |
49 |
visible = false; |
319 |
|
} |
320 |
|
|
321 |
558 |
if (visible && refreshText()) |
322 |
|
{ |
323 |
21 |
iframe.repaint(); |
324 |
|
} |
325 |
557 |
if (!transientDialog) |
326 |
|
{ |
327 |
0 |
return; |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
49 |
closeSplash(); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
337 |
49 |
public void closeSplash()... |
338 |
|
{ |
339 |
49 |
if (this.transientDialog) |
340 |
|
{ |
341 |
49 |
Desktop.instance.releaseDialogQueue(); |
342 |
|
} |
343 |
49 |
try |
344 |
|
{ |
345 |
49 |
final JInternalFrame frme = iframe; |
346 |
49 |
SwingUtilities.invokeLater(new Runnable() |
347 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
348 |
49 |
@Override... |
349 |
|
public void run() |
350 |
|
{ |
351 |
49 |
try |
352 |
|
{ |
353 |
49 |
frme.setClosed(true); |
354 |
|
} catch (Exception ex) |
355 |
|
{ |
356 |
|
} |
357 |
|
} |
358 |
|
}); |
359 |
|
} catch (Exception ex) |
360 |
|
{ |
361 |
|
} |
362 |
|
} |
363 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 5 |
Complexity Density: 0.5 |
|
364 |
|
public class SplashImage extends JPanel |
365 |
|
{ |
366 |
|
Image image; |
367 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
368 |
50 |
public SplashImage(Image todisplay)... |
369 |
|
{ |
370 |
50 |
image = todisplay; |
371 |
50 |
if (image != null) |
372 |
|
{ |
373 |
50 |
setPreferredSize(new Dimension(image.getWidth(this) + 8, |
374 |
|
image.getHeight(this))); |
375 |
|
} |
376 |
|
} |
377 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
378 |
200 |
@Override... |
379 |
|
public Dimension getPreferredSize() |
380 |
|
{ |
381 |
200 |
return new Dimension(image.getWidth(this) + 8, image.getHeight(this)); |
382 |
|
} |
383 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
384 |
773 |
@Override... |
385 |
|
public void paintComponent(Graphics g) |
386 |
|
{ |
387 |
773 |
g.setColor(bg); |
388 |
773 |
g.fillRect(0, 0, getWidth(), getHeight()); |
389 |
773 |
g.setColor(fg); |
390 |
773 |
g.setFont(new Font(font.getFontName(), Font.BOLD, FONT_SIZE + 6)); |
391 |
|
|
392 |
773 |
if (image != null) |
393 |
|
{ |
394 |
773 |
g.drawImage(image, (getWidth() - image.getWidth(this)) / 2, |
395 |
|
(getHeight() - image.getHeight(this)) / 2, this); |
396 |
|
} |
397 |
|
} |
398 |
|
} |
399 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
400 |
0 |
@Override... |
401 |
|
public void hyperlinkUpdate(HyperlinkEvent e) |
402 |
|
{ |
403 |
0 |
Desktop.hyperlinkUpdate(e); |
404 |
|
|
405 |
|
} |
406 |
|
} |