Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File SplashScreen.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
19% of files have more coverage

Code metrics

22
93
11
2
373
230
29
0.31
8.45
5.5
2.64

Classes

Class Line # Actions
SplashScreen 49 83 24 22
0.7981651479.8%
SplashScreen.SplashImage 293 10 5 2
0.8823529588.2%
 

Contributing tests

This file is covered by 34 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
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    * DOCUMENT ME!
45    *
46    * @author $author$
47    * @version $Revision$
48    */
 
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    * either text area in javascript or in java text pane
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    * Creates a new SplashScreen object.
71    */
 
72  11 toggle public SplashScreen()
73    {
74  11 this(false);
75    }
76   
77    private boolean interactiveDialog = false;
78   
79    /**
80    *
81    * @param interactive
82    * if true - an internal dialog is opened rather than a free-floating
83    * splash screen
84    */
 
85  11 toggle public SplashScreen(boolean interactive)
86    {
87  11 this.interactiveDialog = interactive;
88    // show a splashscreen that will disapper
89  11 if (/** @j2sNative true || */ false)
90    {
91  0 authlist = new JLabel("");
92  0 run();
93    }
94    else
95    {
96    /**
97    * @j2sNative
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    {
 
110  0 toggle 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    * ping the jalview version page then create and display the jalview
127    * splashscreen window.
128    */
 
129  11 toggle 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 (/** @j2sNative false || */ 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    * we add image directly in html for javascript ?
174    * @j2sNative
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    * update text in author text panel reflecting current version information
193    */
 
194  114 toggle @SuppressWarnings("unused")
195    protected boolean refreshText()
196    {
197  114 String newtext = Desktop.instance.getAboutMessage(true).toString();
198    // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
199  113 if (oldtext != newtext.length())
200    {
201  11 iframe.setVisible(false);
202  11 oldtext = newtext.length();
203  11 if (/** @j2sNative true || */ 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    * @j2sNative
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    * Create splash screen, display it and clear it off again.
238    */
 
239  11 toggle 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    // if (interactiveDialog) {
264  0 iframe.repaint();
265    // } else {
266    // iframe.repaint();
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    * DOCUMENT ME!
281    */
 
282  10 toggle public void closeSplash()
283    {
284  10 try
285    {
286   
287  10 iframe.setClosed(true);
288    } catch (Exception ex)
289    {
290    }
291    }
292   
 
293    public class SplashImage extends JPanel
294    {
295    Image image;
296   
 
297  11 toggle 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   
 
306  26 toggle @Override
307    public Dimension getPreferredSize()
308    {
309  26 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
310    }
311   
 
312  277 toggle 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    * int y = yoffset;
327    *
328    * g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
329    * y);
330    *
331    * FontMetrics fm = g.getFontMetrics(); int vwidth =
332    * fm.stringWidth("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
333    * g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); g.drawString(
334    * "Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
335    * 50 + vwidth + 5, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION",
336    * "Checking").equals( "Checking")) { // Displayed when code version and
337    * jnlp version do not match g.drawString("...Checking latest version...",
338    * 50, y += fontSize + 10); y += 5; g.setColor(Color.black); } else if
339    * (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
340    * .equals(jalview.bin.Cache.getProperty("VERSION"))) { if
341    * (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
342    * .indexOf("automated build") == -1) { // Displayed when code version and
343    * jnlp version do not match and code // version is not a development build
344    * g.setColor(Color.red); } g.drawString( "!! Jalview version " +
345    * jalview.bin.Cache.getDefault("LATEST_VERSION", "..Checking..") +
346    * " is available for download from "
347    * +jalview.bin.Cache.getDefault("www.jalview.org"
348    * ,"http://www.jalview.org")+" !!", 50, y += fontSize + 10); y += 5;
349    * g.setColor(Color.black); }
350    *
351    * g.setFont(new Font("Verdana", Font.BOLD, fontSize)); g.drawString(
352    * "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,"
353    * , 50, y += fontSize + 4); g.drawString("David Martin & Geoff Barton.",
354    * 60, y += fontSize + 4); g.drawString(
355    * "Development managed by The Barton Group, University of Dundee.", 50, y
356    * += fontSize + 4); g.drawString("If you use Jalview, please cite: ", 50,
357    * y += fontSize + 4); g.drawString(
358    * "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
359    * , 50, y += fontSize + 4); g.drawString(
360    * "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
361    * , 50, y += fontSize + 4);
362    * g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", 50, y
363    * += fontSize + 4); }
364    */
365    }
366   
 
367  0 toggle @Override
368    public void hyperlinkUpdate(HyperlinkEvent e)
369    {
370  0 Desktop.hyperlinkUpdate(e);
371   
372    }
373    }