2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.Image;
29 import java.awt.MediaTracker;
30 import java.awt.Toolkit;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JLayeredPane;
37 import javax.swing.JPanel;
38 import javax.swing.JTextPane;
39 import javax.swing.event.HyperlinkEvent;
40 import javax.swing.event.HyperlinkListener;
42 import jalview.util.Platform;
43 import javajs.async.SwingJSUtils.StateHelper;
44 import javajs.async.SwingJSUtils.StateMachine;
52 @SuppressWarnings("serial")
53 public class SplashScreen extends JPanel
54 implements HyperlinkListener, StateMachine
57 private static final int STATE_INIT = 0;
59 private static final int STATE_LOOP = 1;
61 private static final int STATE_DONE = 2;
63 private static final int SHOW_FOR_SECS = 5;
65 private int FONT_SIZE = (Platform.isJS() ? 14 : 11);
67 private JPanel imgPanel = new JPanel(new BorderLayout());
69 private JInternalFrame iframe;
73 protected boolean isInteractive = false;
75 private long oldTextLength = -1;
78 * allow click in the initial splash screen to dismiss it
79 * immediately (not if opened from About menu)
81 private MouseAdapter closer = new MouseAdapter()
84 public void mousePressed(MouseEvent evt)
91 } catch (Exception ex)
100 private StateHelper helper;
103 * Constructor that displays the splash screen
106 * if true the panel removes itself on click or after a few seconds;
107 * if false it stays up until closed by the user
109 public SplashScreen(boolean isTransient)
111 this.isInteractive = isTransient;
114 helper = new StateHelper(this);
115 helper.next(STATE_INIT);
118 private void getImages()
120 URL url = getClass().getResource("/images/Jalview_Logo.png");
121 URL urllogo = getClass()
122 .getResource("/images/Jalview_Logo_small.png");
123 image = Toolkit.getDefaultToolkit().createImage(url);
124 if (!Platform.isJS())
125 logo = Toolkit.getDefaultToolkit().createImage(urllogo);
129 * ping the jalview version page then create and display the jalview
130 * splashscreen window.
132 void initSplashScreenWindow()
134 addMouseListener(closer);
138 MediaTracker mt = new MediaTracker(this);
139 mt.addImage(image, 0);
142 mt.addImage(logo, 1);
149 } catch (InterruptedException x)
154 System.err.println("Error when loading images!");
156 } while (!mt.checkAll());
159 Desktop.getInstance().setIconImage(logo);
161 } catch (Exception ex)
164 iframe = new JInternalFrame();
165 iframe.setFrameIcon(null);
166 iframe.setClosable(true);
167 this.setLayout(new BorderLayout());
168 iframe.setContentPane(this);
169 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
171 SplashImage splashimg = new SplashImage(image);
172 imgPanel.add(splashimg, BorderLayout.CENTER);
173 add(imgPanel, BorderLayout.NORTH);
174 Desktop.getDesktopPane().add(iframe);
179 * update text in author text panel reflecting current version information
181 protected boolean refreshText()
183 String newtext = Desktop.getInstance().getAboutMessage();
184 if (oldTextLength == newtext.length())
188 oldTextLength = newtext.length();
189 iframe.setVisible(false);
190 JTextPane jtp = new JTextPane();
191 jtp.setEditable(false);
192 jtp.setContentType("text/html");
193 jtp.setText("<html>" + newtext + "</html>");
196 System.out.println("Text found: \n"+newtext+"\nEnd of newtext.");
198 jtp.addHyperlinkListener(this);
199 jtp.setFont(new Font("Verdana", Font.PLAIN, FONT_SIZE));
200 jtp.addMouseListener(closer);
201 jtp.setVisible(true);
202 jtp.setSize(new Dimension(750, 425));
203 add(jtp, BorderLayout.CENTER);
205 iframe.setBounds((Desktop.getInstance().getWidth() - 750) / 2,
207 jtp.getHeight() + imgPanel.getHeight());
209 iframe.setVisible(true);
214 protected long startTime;
217 * A simple state machine with just three states: init, loop, and done. Ideal
218 * for a simple while/sleep loop that works in Java and JavaScript
222 public boolean stateLoop()
226 switch (helper.getState())
229 initSplashScreenWindow();
230 startTime = System.currentTimeMillis() / 1000;
231 helper.setState(STATE_LOOP);
236 helper.setState(STATE_DONE);
247 helper.delayedState(SHOW_FOR_SECS * 1000, STATE_DONE);
253 Desktop.getInstance().startDialogQueue();
259 public void closeSplash()
264 iframe.setClosed(true);
265 } catch (Exception ex)
270 public class SplashImage extends JPanel
274 public SplashImage(Image todisplay)
279 setPreferredSize(new Dimension(image.getWidth(this) + 8,
280 image.getHeight(this)));
285 public Dimension getPreferredSize()
287 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
291 public void paintComponent(Graphics g)
293 g.setColor(Color.white);
294 g.fillRect(0, 0, getWidth(), getHeight());
295 g.setColor(Color.black);
299 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
300 (getHeight() - image.getHeight(this)) / 2, this);
306 public void hyperlinkUpdate(HyperlinkEvent e)
308 Desktop.hyperlinkUpdate(e);