update text and version checker
[jalview.git] / src / jalview / gui / SplashScreen.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 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
32     extends JPanel implements Runnable
33 {
34   boolean visible = true;
35   JInternalFrame iframe;
36   Image image;
37   int fontSize = 11;
38   int yoffset = 30;
39
40   /**
41    * Creates a new SplashScreen object.
42    */
43   public SplashScreen()
44   {
45     Thread t = new Thread(this);
46     t.start();
47   }
48   /**
49    * ping the jalview version page then create and display the jalview splashscreen window.
50    */
51   void initSplashScreenWindow() {
52     addMouseListener(new MouseAdapter()
53     {
54       public void mousePressed(MouseEvent evt)
55       {
56         try
57         {
58           visible=false;
59           closeSplash();
60         }
61         catch (Exception ex)
62         {
63         }
64       }
65     });
66
67     try
68     {
69       java.net.URL url = getClass().getResource("/images/logo.gif");
70
71       if (url != null)
72       {
73         image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
74
75         MediaTracker mt = new MediaTracker(this);
76         mt.addImage(image, 0);
77         mt.waitForID(0);
78         Desktop.instance.setIconImage(image);
79       }
80     }
81     catch (Exception ex)
82     {
83     }
84
85
86     iframe = new JInternalFrame();
87     iframe.setFrameIcon(null);
88     iframe.setClosable(false);
89     iframe.setContentPane(this);
90     iframe.setLayer(JLayeredPane.PALETTE_LAYER);
91
92     Desktop.desktop.add(iframe);
93
94     iframe.setVisible(true);
95     iframe.setBounds( (int) ( (Desktop.instance.getWidth() - 750) / 2),
96                       (int) ( (Desktop.instance.getHeight() - 160) / 2),
97                       750, 160);
98   }
99
100   /**
101    * Create splash screen, display it and clear it off again.
102    */
103   public void run()
104   {
105     initSplashScreenWindow();
106     long startTime = System.currentTimeMillis() / 1000;
107     
108     while (visible)
109     {
110       try
111       {
112         Thread.sleep(1000);
113       }
114       catch (Exception ex)
115       {
116       }
117
118       if ( ( (System.currentTimeMillis() / 1000) - startTime) > 5)
119       {
120         visible = false;
121       }
122       else
123         repaint();
124     }
125
126     closeSplash();
127   }
128
129   /**
130    * DOCUMENT ME!
131    */
132   public void closeSplash()
133   {
134     try
135     {
136
137       iframe.setClosed(true);
138     }
139     catch (Exception ex)
140     {  }
141   }
142
143   /**
144    * DOCUMENT ME!
145    *
146    * @param g DOCUMENT ME!
147    */
148   public void paintComponent(Graphics g)
149   {
150     g.setColor(Color.white);
151     g.fillRect(0, 0, getWidth(), getHeight());
152     g.setColor(Color.black);
153     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6));
154
155     if (image != null)
156     {
157       g.drawImage(image, 5, yoffset + 12, this);
158     }
159
160     int y = yoffset;
161
162     g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50, y);
163
164     FontMetrics fm = g.getFontMetrics();
165     int vwidth = fm.stringWidth("Jalview " +
166                                 jalview.bin.Cache.getProperty("VERSION"));
167     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2));
168     g.drawString("Last updated: " +
169                  jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
170                  50 + vwidth + 5, y);
171     if (jalview.bin.Cache.getDefault("LATEST_VERSION",
172         "Checking").equals("Checking"))
173     {
174       // Displayed when code version and jnlp version do not match
175       g.drawString("...Checking latest version...",
176                    50, y += fontSize + 10);
177       y += 5;
178       g.setColor(Color.black);
179     }
180     else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
181         jalview.bin.Cache.getProperty("VERSION")))
182     {
183       if (jalview.bin.Cache.getProperty("VERSION").toLowerCase().indexOf("automated build")==-1)
184       {
185         // Displayed when code version and jnlp version do not match and code version is not a development build
186         g.setColor(Color.red);
187       }
188       g.drawString(
189               "!! Jalview version "
190               + jalview.bin.Cache.getDefault(
191                       "LATEST_VERSION", "..Checking..")
192                       + " is available for download from http://www.jalview.org !!",
193                       50, y += fontSize + 10);
194       y += 5;
195       g.setColor(Color.black);
196     }
197
198     g.setFont(new Font("Verdana", Font.BOLD, fontSize));
199     g.drawString("Authors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton.",
200                  50, y += fontSize + 4);
201     g.drawString("Development managed by The Barton Group, University of Dundee.",
202                  50, y += fontSize + 4);
203     g.drawString("If  you use Jalview, please cite: Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004),",
204                  50, y += fontSize + 4);
205     g.drawString(
206         "\"The Jalview Java Alignment Editor\" Bioinformatics,  2004 20; 426-7.",
207         50, y += fontSize + 4);
208   }
209 }