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