updated jalview reference
[jalview.git] / src / jalview / gui / SplashScreen.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24
25 /**
26  * DOCUMENT ME!
27  * 
28  * @author $author$
29  * @version $Revision$
30  */
31 public class SplashScreen extends JPanel implements Runnable
32 {
33   boolean visible = true;
34
35   JInternalFrame iframe;
36
37   Image image;
38
39   int fontSize = 11;
40
41   int yoffset = 30;
42
43   /**
44    * Creates a new SplashScreen object.
45    */
46   public SplashScreen()
47   {
48     Thread t = new Thread(this);
49     t.start();
50   }
51
52   /**
53    * ping the jalview version page then create and display the jalview
54    * splashscreen window.
55    */
56   void initSplashScreenWindow()
57   {
58     addMouseListener(new MouseAdapter()
59     {
60       public void mousePressed(MouseEvent evt)
61       {
62         try
63         {
64           visible = false;
65           closeSplash();
66         } catch (Exception ex)
67         {
68         }
69       }
70     });
71
72     try
73     {
74       java.net.URL url = getClass().getResource("/images/logo.gif");
75
76       if (url != null)
77       {
78         image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
79
80         MediaTracker mt = new MediaTracker(this);
81         mt.addImage(image, 0);
82         mt.waitForID(0);
83         Desktop.instance.setIconImage(image);
84       }
85     } catch (Exception ex)
86     {
87     }
88
89     iframe = new JInternalFrame();
90     iframe.setFrameIcon(null);
91     iframe.setClosable(false);
92     iframe.setContentPane(this);
93     iframe.setLayer(JLayeredPane.PALETTE_LAYER);
94
95     Desktop.desktop.add(iframe);
96
97     iframe.setVisible(true);
98     iframe.setBounds((int) ((Desktop.instance.getWidth() - 750) / 2),
99             (int) ((Desktop.instance.getHeight() - 160) / 2), 750, 190);
100   }
101
102   /**
103    * Create splash screen, display it and clear it off again.
104    */
105   public void run()
106   {
107     initSplashScreenWindow();
108     long startTime = System.currentTimeMillis() / 1000;
109
110     while (visible)
111     {
112       try
113       {
114         Thread.sleep(1000);
115       } catch (Exception ex)
116       {
117       }
118
119       if (((System.currentTimeMillis() / 1000) - startTime) > 5)
120       {
121         visible = false;
122       }
123       else
124         repaint();
125     }
126
127     closeSplash();
128   }
129
130   /**
131    * DOCUMENT ME!
132    */
133   public void closeSplash()
134   {
135     try
136     {
137
138       iframe.setClosed(true);
139     } catch (Exception ex)
140     {
141     }
142   }
143
144   /**
145    * DOCUMENT ME!
146    * 
147    * @param g
148    *                DOCUMENT ME!
149    */
150   public void paintComponent(Graphics g)
151   {
152     g.setColor(Color.white);
153     g.fillRect(0, 0, getWidth(), getHeight());
154     g.setColor(Color.black);
155     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6));
156
157     if (image != null)
158     {
159       g.drawImage(image, 5, yoffset + 12, this);
160     }
161
162     int y = yoffset;
163
164     g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
165             y);
166
167     FontMetrics fm = g.getFontMetrics();
168     int vwidth = fm.stringWidth("Jalview "
169             + jalview.bin.Cache.getProperty("VERSION"));
170     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2));
171     g.drawString("Last updated: "
172             + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
173             50 + vwidth + 5, y);
174     if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
175             "Checking"))
176     {
177       // Displayed when code version and jnlp version do not match
178       g.drawString("...Checking latest version...", 50, y += fontSize + 10);
179       y += 5;
180       g.setColor(Color.black);
181     }
182     else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
183             .equals(jalview.bin.Cache.getProperty("VERSION")))
184     {
185       if (jalview.bin.Cache.getProperty("VERSION").toLowerCase().indexOf(
186               "automated build") == -1)
187       {
188         // Displayed when code version and jnlp version do not match and code
189         // version is not a development build
190         g.setColor(Color.red);
191       }
192       g
193               .drawString(
194                       "!! Jalview version "
195                               + jalview.bin.Cache.getDefault(
196                                       "LATEST_VERSION", "..Checking..")
197                               + " is available for download from http://www.jalview.org !!",
198                       50, y += fontSize + 10);
199       y += 5;
200       g.setColor(Color.black);
201     }
202
203     g.setFont(new Font("Verdana", Font.BOLD, fontSize));
204     g
205             .drawString(
206                     "Authors: Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,",
207                     50, y += fontSize + 4);
208     g.drawString("David Martin & Geoff Barton.", 60, y += fontSize + 4);
209     g
210             .drawString(
211                     "Development managed by The Barton Group, University of Dundee.",
212                     50, y += fontSize + 4);
213     g
214             .drawString(
215                     "If  you use Jalview, please cite: ",50,y+=fontSize+4);
216     g.drawString("Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)",50,y+=fontSize+4);
217         g.drawString("Jalview Version 2 - a multiple sequence alignment editor and analysis workbench",50,y+=fontSize+4);
218         g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033",50,y+=fontSize+4);
219   }
220 }