update author list in license for (JAL-826)
[jalview.git] / src / jalview / gui / SplashScreen.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3   * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23
24 /**
25  * DOCUMENT ME!
26  * 
27  * @author $author$
28  * @version $Revision$
29  */
30 public class SplashScreen extends JPanel implements Runnable
31 {
32   boolean visible = true;
33
34   JInternalFrame iframe;
35
36   Image image;
37
38   int fontSize = 11;
39
40   int yoffset = 30;
41
42   /**
43    * Creates a new SplashScreen object.
44    */
45   public SplashScreen()
46   {
47     Thread t = new Thread(this);
48     t.start();
49   }
50
51   /**
52    * ping the jalview version page then create and display the jalview
53    * splashscreen window.
54    */
55   void initSplashScreenWindow()
56   {
57     addMouseListener(new MouseAdapter()
58     {
59       public void mousePressed(MouseEvent evt)
60       {
61         try
62         {
63           visible = false;
64           closeSplash();
65         } catch (Exception ex)
66         {
67         }
68       }
69     });
70
71     try
72     {
73       java.net.URL url = getClass().getResource("/images/logo.gif");
74
75       if (url != null)
76       {
77         image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
78
79         MediaTracker mt = new MediaTracker(this);
80         mt.addImage(image, 0);
81         mt.waitForID(0);
82         Desktop.instance.setIconImage(image);
83       }
84     } catch (Exception ex)
85     {
86     }
87
88     iframe = new JInternalFrame();
89     iframe.setFrameIcon(null);
90     iframe.setClosable(false);
91     iframe.setContentPane(this);
92     iframe.setLayer(JLayeredPane.PALETTE_LAYER);
93
94     Desktop.desktop.add(iframe);
95
96     iframe.setVisible(true);
97     iframe.setBounds((int) ((Desktop.instance.getWidth() - 750) / 2),
98             (int) ((Desktop.instance.getHeight() - 160) / 2), 750, 190);
99   }
100
101   /**
102    * Create splash screen, display it and clear it off again.
103    */
104   public void run()
105   {
106     initSplashScreenWindow();
107     long startTime = System.currentTimeMillis() / 1000;
108
109     while (visible)
110     {
111       try
112       {
113         Thread.sleep(1000);
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     } catch (Exception ex)
139     {
140     }
141   }
142
143   /**
144    * DOCUMENT ME!
145    * 
146    * @param g
147    *          DOCUMENT ME!
148    */
149   public void paintComponent(Graphics g)
150   {
151     g.setColor(Color.white);
152     g.fillRect(0, 0, getWidth(), getHeight());
153     g.setColor(Color.black);
154     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6));
155
156     if (image != null)
157     {
158       g.drawImage(image, 5, yoffset + 12, this);
159     }
160
161     int y = yoffset;
162
163     g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
164             y);
165
166     FontMetrics fm = g.getFontMetrics();
167     int vwidth = fm.stringWidth("Jalview "
168             + jalview.bin.Cache.getProperty("VERSION"));
169     g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2));
170     g.drawString(
171             "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()
186               .indexOf("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.drawString(
193               "!! Jalview version "
194                       + jalview.bin.Cache.getDefault("LATEST_VERSION",
195                               "..Checking..")
196                       + " is available for download from "+jalview.bin.Cache.getDefault("www.jalview.org","http://www.jalview.org")+" !!",
197               50, y += fontSize + 10);
198       y += 5;
199       g.setColor(Color.black);
200     }
201
202     g.setFont(new Font("Verdana", Font.BOLD, fontSize));
203     g.drawString(
204             "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,",
205             50, y += fontSize + 4);
206     g.drawString("David Martin & Geoff Barton.", 60, y += fontSize + 4);
207     g.drawString(
208             "Development managed by The Barton Group, University of Dundee.",
209             50, y += fontSize + 4);
210     g.drawString("If  you use Jalview, please cite: ", 50,
211             y += fontSize + 4);
212     g.drawString(
213             "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)",
214             50, y += fontSize + 4);
215     g.drawString(
216             "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench",
217             50, y += fontSize + 4);
218     g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", 50,
219             y += fontSize + 4);
220   }
221 }