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