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 boolean isNew = (htmlPane == null);
200 if (!newtext.equals(oldtext))
202 iframe.setVisible(false);
204 if (Platform.isJS()) // BH 2019
206 // BH TODO SwingJS does not implement HTML style. Could rethink this.
210 htmlPane = new JLabel();
212 JLabel l = (JLabel) htmlPane;
214 Font f = htmlPane.getFont();
215 l.setFont(new Font(f.getFamily(), Font.PLAIN, f.getSize()));
216 l.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
218 l.setBackground(Color.white);
230 htmlPane = new JTextPane();
232 JTextPane pane = (JTextPane) htmlPane;
233 pane.setEditable(false);
234 pane.setContentType("text/html");
235 pane.setText(newtext);
236 pane.addHyperlinkListener(this);
241 htmlPane.addMouseListener(closer);
242 htmlPane.setSize(new Dimension(750, 375));
243 add(htmlPane, BorderLayout.CENTER);
244 int h = htmlPane.getHeight() + iconimg.getHeight();
245 iframe.setBounds(Math.max(0, (desktop.getWidth() - 750) / 2),
246 Math.max(0, (desktop.getHeight() - h) / 2), 750, h);
247 iframe.setVisible(true);
255 * Create splash screen, display it and clear it off again.
260 mainState = STATE_INIT;
264 protected long startTime;
267 * A simple state machine with just three states: init, loop, and done. Ideal
268 * for a simple while/sleep loop that works in Java and JavaScript
272 protected void mainLoop()
279 initSplashScreenWindow();
280 startTime = System.currentTimeMillis() / 1000;
281 mainState = STATE_LOOP;
286 mainState = STATE_DONE;
290 && ((System.currentTimeMillis() / 1000) - startTime) > 5)
295 if (isVisible() && refreshText())
303 Timer timer = new Timer(500, new ActionListener()
306 public void actionPerformed(ActionEvent e)
308 System.out.println(htmlPane.getFont());
313 timer.setRepeats(false);
318 Desktop.getInstance().startDialogQueue();
326 * Close the internal frame, either from the timer expiring or from the mouse
329 public void closeSplash()
334 iframe.setClosed(true);
335 } catch (PropertyVetoException e)
340 private class SplashImage extends JPanel
344 public SplashImage(Image todisplay)
349 setPreferredSize(new Dimension(image.getWidth(this) + 8,
350 image.getHeight(this)));
355 public Dimension getPreferredSize()
357 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
361 public void paintComponent(Graphics g)
363 g.setColor(Color.white);
364 g.fillRect(0, 0, getWidth(), getHeight());
365 g.setColor(Color.black);
366 g.setFont(largeFont);
370 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
371 (getHeight() - image.getHeight(this)) / 2, this);
377 * g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
380 * FontMetrics fm = g.getFontMetrics(); int vwidth =
381 * fm.stringWidth("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
382 * g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); g.drawString(
383 * "Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
384 * 50 + vwidth + 5, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION",
385 * "Checking").equals( "Checking")) { // Displayed when code version and
386 * jnlp version do not match g.drawString("...Checking latest version...",
387 * 50, y += fontSize + 10); y += 5; g.setColor(Color.black); } else if
388 * (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
389 * .equals(jalview.bin.Cache.getProperty("VERSION"))) { if
390 * (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
391 * .indexOf("automated build") == -1) { // Displayed when code version and
392 * jnlp version do not match and code // version is not a development build
393 * g.setColor(Color.red); } g.drawString( "!! Jalview version " +
394 * jalview.bin.Cache.getDefault("LATEST_VERSION", "..Checking..") +
395 * " is available for download from "
396 * +jalview.bin.Cache.getDefault("www.jalview.org"
397 * ,"http://www.jalview.org")+" !!", 50, y += fontSize + 10); y += 5;
398 * g.setColor(Color.black); }
400 * g.setFont(new Font("Verdana", Font.BOLD, fontSize)); g.drawString(
401 * "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,"
402 * , 50, y += fontSize + 4); g.drawString("David Martin & Geoff Barton.",
403 * 60, y += fontSize + 4); g.drawString(
404 * "Development managed by The Barton Group, University of Dundee.", 50, y
405 * += fontSize + 4); g.drawString("If you use Jalview, please cite: ", 50,
406 * y += fontSize + 4); g.drawString(
407 * "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
408 * , 50, y += fontSize + 4); g.drawString(
409 * "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
410 * , 50, y += fontSize + 4);
411 * g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", 50, y
412 * += fontSize + 4); }
417 public void hyperlinkUpdate(HyperlinkEvent e)
419 Desktop.hyperlinkUpdate(e);