d819d982691230663491368165ceac43d13da378
[jalview.git] / src / jalview / gui / SplashScreen.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2006 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
24 import javax.swing.*;
25
26
27 /**
28  * DOCUMENT ME!
29  *
30  * @author $author$
31  * @version $Revision$
32  */
33 public class SplashScreen extends JPanel implements Runnable
34 {
35     boolean visible = true;
36     JInternalFrame iframe;
37     Image image;
38     int fontSize = 11;
39     int yoffset = 30;
40
41     /**
42      * Creates a new SplashScreen object.
43      *
44      * @param iframe DOCUMENT ME!
45      * @param i DOCUMENT ME!
46      */
47     public SplashScreen(JInternalFrame iframe, Image i)
48     {
49         this.iframe = iframe;
50         image = i;
51
52         Thread t = new Thread(this);
53         t.start();
54         addMouseListener(new MouseAdapter()
55             {
56                 public void mousePressed(MouseEvent evt)
57                 {
58                     try
59                     {
60                         closeSplash();
61                     }
62                     catch (Exception ex)
63                     {
64                     }
65                 }
66             });
67     }
68
69     /**
70      * DOCUMENT ME!
71      */
72     public void run()
73     {
74         long startTime = System.currentTimeMillis() / 1000;
75
76         while (visible)
77         {
78             if (((System.currentTimeMillis() / 1000) - startTime) > 5)
79             {
80                 visible = false;
81             }
82
83             try
84             {
85                 Thread.sleep(1000);
86                 repaint();
87             }
88             catch (Exception ex)
89             {
90             }
91         }
92
93         closeSplash();
94     }
95
96     /**
97      * DOCUMENT ME!
98      */
99     public void closeSplash()
100     {
101         try
102         {
103             iframe.setClosed(true);
104         }
105         catch (Exception ex)
106         {
107           ex.printStackTrace();
108         }
109     }
110
111     /**
112      * DOCUMENT ME!
113      *
114      * @param g DOCUMENT ME!
115      */
116     public void paintComponent(Graphics g)
117     {
118         g.setColor(Color.white);
119         g.fillRect(0, 0, getWidth(), getHeight());
120         g.setColor(Color.black);
121         g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6));
122
123         if (image != null)
124         {
125             g.drawImage(image, 5, yoffset + 12, this);
126         }
127
128         int y = yoffset;
129
130         g.drawString("Jalview "+jalview.bin.Cache.getProperty("VERSION"), 50, y);
131
132         FontMetrics fm = g.getFontMetrics();
133         int vwidth = fm.stringWidth("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
134         g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2));
135         g.drawString("Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
136                      50 + vwidth +5, y);
137
138         if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals("Checking"))
139         {
140           // Displayed when code version and jnlp version do not match
141           g.drawString("...Checking latest version...",
142                        50, y += fontSize + 10);
143           y += 5;
144           g.setColor(Color.black);
145         }
146         else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
147             jalview.bin.Cache.getProperty("VERSION")))
148         {
149           // Displayed when code version and jnlp version do not match
150           g.setColor(Color.red);
151           g.drawString("!! Jalview version " +
152                        jalview.bin.Cache.getDefault("LATEST_VERSION", "..Checking..")
153                        + " is available for download from http://www.jalview.org !!",
154                        50, y += fontSize + 10);
155           y += 5;
156           g.setColor(Color.black);
157         }
158
159         g.setFont(new Font("Verdana", Font.BOLD, fontSize));
160         g.drawString("Authors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton.",
161             50, y+=fontSize+4);
162         g.drawString("Current development managed by Andrew Waterhouse; Barton Group, University of Dundee.",
163             50,  y+=fontSize+4);
164         g.drawString("If  you use JalView, please cite: Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004),",
165             50, y+=fontSize+4);
166         g.drawString("\"The Jalview Java Alignment Editor\" Bioinformatics,  2004 20; 426-7.",
167             50, y+=fontSize+4);
168     }
169 }