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 jalview.util.Platform;
25 import java.awt.BorderLayout;
26 import java.awt.Color;
27 import java.awt.Component;
28 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Image;
32 import java.awt.Insets;
33 import java.awt.MediaTracker;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.MouseAdapter;
37 import java.awt.event.MouseEvent;
38 import java.beans.PropertyVetoException;
40 import javax.swing.JInternalFrame;
41 import javax.swing.JLabel;
42 import javax.swing.JLayeredPane;
43 import javax.swing.JPanel;
44 import javax.swing.JTextPane;
45 import javax.swing.Timer;
46 import javax.swing.border.EmptyBorder;
47 import javax.swing.event.HyperlinkEvent;
48 import javax.swing.event.HyperlinkListener;
51 * A class that serves both as an initial 5-second splash screen (interactive
52 * false) as well as for the Help menu item action (interactive true).
54 * As a splash screen, the frame closes if clicked by the user.
56 * Closure loop converted from a while/sleep loop to a JavaScript-compatible
57 * state machine by Bob Hanson 2019.11.26.
59 * TODO: get JTextPane working for read-only HTML.
62 @SuppressWarnings("serial")
63 public class SplashScreen extends JPanel
64 implements Runnable, HyperlinkListener
66 private static final int STATE_INIT = 0;
68 private static final int STATE_LOOP = 1;
70 private static final int STATE_DONE = 2;
72 // boolean visible = true;
74 private JPanel iconimg = new JPanel(new BorderLayout());
77 * Temporary SwingJS Hack: Either a JLabel in JavaScript or a JTextPane in
80 protected Component htmlPane;
82 private JInternalFrame iframe;
86 private final static int fontSize = 11;
88 protected final static Font largeFont = new Font("Verdana", Font.BOLD,
94 * Creates a new SplashScreen object.
101 protected boolean isInteractive = false;
106 * if true - an internal dialog is opened rather than a free-floating
109 public SplashScreen(boolean isInteractive)
111 this.isInteractive = isInteractive;
112 Thread t = new Thread(this, "SplashScreen");
116 MouseAdapter closer = new MouseAdapter()
119 public void mousePressed(MouseEvent evt)
128 } catch (Exception ex)
135 * ping the jalview version page then create and display the jalview
136 * splashscreen window.
138 protected void initSplashScreenWindow()
140 addMouseListener(closer);
143 java.net.URL url = getClass().getResource("/images/Jalview_Logo.png");
144 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
145 MediaTracker mt = new MediaTracker(this);
146 mt.addImage(image, 0);
147 Image logo = (Platform.isJS() ? null
148 : java.awt.Toolkit.getDefaultToolkit().createImage(getClass()
149 .getResource("/images/Jalview_Logo_small.png")));
152 mt.addImage(logo, 1);
159 } catch (InterruptedException x)
164 System.err.println("Error when loading images!");
166 } while (!mt.checkAll());
169 Desktop.getInstance().setIconImage(logo);
171 } catch (Exception ex)
174 iframe = new JInternalFrame();
175 iframe.setFrameIcon(null);
176 iframe.setClosable(isInteractive);
177 this.setLayout(new BorderLayout());
178 iframe.setContentPane(this);
179 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
180 SplashImage splashimg = new SplashImage(image);
181 iconimg.add(splashimg, BorderLayout.CENTER);
182 add(iconimg, BorderLayout.NORTH);
183 Desktop.getDesktopPane().add(iframe);
189 private int mainState;
192 * update text in author text panel reflecting current version information
194 protected boolean refreshText()
196 Desktop desktop = Desktop.getInstance();
197 String newtext = desktop.getAboutMessage(true).toString();
198 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
199 if (!newtext.equals(oldtext))
201 iframe.setVisible(false);
203 if (Platform.isJS()) // BH 2019
205 // BH TODO SwingJS does not implement HTML style. Could rethink this.
207 if (htmlPane == null)
209 htmlPane = new JLabel();
211 JLabel l = (JLabel)htmlPane;
213 Font f = htmlPane.getFont();
214 l.setFont(new Font(f.getFamily(), Font.PLAIN, f.getSize()));
215 l.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
217 l.setBackground(Color.white);
227 if (htmlPane == null)
229 htmlPane = new JTextPane();
231 JTextPane pane = (JTextPane)htmlPane;
232 pane.setEditable(false);
233 pane.setContentType("text/html");
234 pane.setText(newtext);
235 pane.addHyperlinkListener(this);
238 htmlPane.addMouseListener(closer);
239 htmlPane.setSize(new Dimension(750, 375));
240 add(htmlPane, BorderLayout.CENTER);
241 int h = htmlPane.getHeight() + iconimg.getHeight();
242 iframe.setBounds(Math.max(0, (desktop.getWidth() - 750) / 2),
243 Math.max(0, (desktop.getHeight() - h) / 2), 750, h);
244 iframe.setVisible(true);
251 * Create splash screen, display it and clear it off again.
256 mainState = STATE_INIT;
260 protected long startTime;
263 * A simple state machine with just three states: init, loop, and done. Ideal
264 * for a simple while/sleep loop that works in Java and JavaScript
268 protected void mainLoop()
275 initSplashScreenWindow();
276 startTime = System.currentTimeMillis() / 1000;
277 mainState = STATE_LOOP;
282 mainState = STATE_DONE;
286 && ((System.currentTimeMillis() / 1000) - startTime) > 5)
291 if (isVisible() && refreshText())
299 Timer timer = new Timer(500, new ActionListener()
302 public void actionPerformed(ActionEvent e)
308 timer.setRepeats(false);
313 Desktop.getInstance().startDialogQueue();
321 * Close the internal frame, either from the timer expiring or from the mouse
324 public void closeSplash()
329 iframe.setClosed(true);
330 } catch (PropertyVetoException e)
335 private class SplashImage extends JPanel
339 public SplashImage(Image todisplay)
344 setPreferredSize(new Dimension(image.getWidth(this) + 8,
345 image.getHeight(this)));
350 public Dimension getPreferredSize()
352 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
356 public void paintComponent(Graphics g)
358 g.setColor(Color.white);
359 g.fillRect(0, 0, getWidth(), getHeight());
360 g.setColor(Color.black);
361 g.setFont(largeFont);
365 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
366 (getHeight() - image.getHeight(this)) / 2, this);
372 * g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
375 * FontMetrics fm = g.getFontMetrics(); int vwidth =
376 * fm.stringWidth("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
377 * g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); g.drawString(
378 * "Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
379 * 50 + vwidth + 5, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION",
380 * "Checking").equals( "Checking")) { // Displayed when code version and
381 * jnlp version do not match g.drawString("...Checking latest version...",
382 * 50, y += fontSize + 10); y += 5; g.setColor(Color.black); } else if
383 * (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
384 * .equals(jalview.bin.Cache.getProperty("VERSION"))) { if
385 * (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
386 * .indexOf("automated build") == -1) { // Displayed when code version and
387 * jnlp version do not match and code // version is not a development build
388 * g.setColor(Color.red); } g.drawString( "!! Jalview version " +
389 * jalview.bin.Cache.getDefault("LATEST_VERSION", "..Checking..") +
390 * " is available for download from "
391 * +jalview.bin.Cache.getDefault("www.jalview.org"
392 * ,"http://www.jalview.org")+" !!", 50, y += fontSize + 10); y += 5;
393 * g.setColor(Color.black); }
395 * g.setFont(new Font("Verdana", Font.BOLD, fontSize)); g.drawString(
396 * "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,"
397 * , 50, y += fontSize + 4); g.drawString("David Martin & Geoff Barton.",
398 * 60, y += fontSize + 4); g.drawString(
399 * "Development managed by The Barton Group, University of Dundee.", 50, y
400 * += fontSize + 4); g.drawString("If you use Jalview, please cite: ", 50,
401 * y += fontSize + 4); g.drawString(
402 * "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
403 * , 50, y += fontSize + 4); g.drawString(
404 * "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
405 * , 50, y += fontSize + 4);
406 * g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", 50, y
407 * += fontSize + 4); }
412 public void hyperlinkUpdate(HyperlinkEvent e)
414 Desktop.hyperlinkUpdate(e);