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;
39 import javax.swing.JInternalFrame;
40 import javax.swing.JLabel;
41 import javax.swing.JLayeredPane;
42 import javax.swing.JPanel;
43 import javax.swing.JTextPane;
44 import javax.swing.Timer;
45 import javax.swing.border.EmptyBorder;
46 import javax.swing.event.HyperlinkEvent;
47 import javax.swing.event.HyperlinkListener;
55 public class SplashScreen extends JPanel
56 implements Runnable, HyperlinkListener
58 private static final int STATE_INIT = 0;
60 private static final int STATE_LOOP = 1;
62 private static final int STATE_DONE = 2;
64 boolean visible = true;
66 JPanel iconimg = new JPanel(new BorderLayout());
69 * either text area in javascript or in java text pane
73 JInternalFrame iframe;
82 * Creates a new SplashScreen object.
89 protected boolean interactiveDialog = false;
94 * if true - an internal dialog is opened rather than a free-floating
97 public SplashScreen(boolean interactive)
99 this.interactiveDialog = interactive;
100 // show a splashscreen that will disapper
101 if (Platform.isJS()) // BH 2019
103 htmlPane = new JLabel("");
114 htmlPane = new JTextPane();
115 Thread t = new Thread(this, "SplashScreen");
122 MouseAdapter closer = new MouseAdapter()
125 public void mousePressed(MouseEvent evt)
129 if (!interactiveDialog)
134 } catch (Exception ex)
141 * ping the jalview version page then create and display the jalview
142 * splashscreen window.
144 protected void initSplashScreenWindow()
146 addMouseListener(closer);
149 java.net.URL url = getClass().getResource("/images/Jalview_Logo.png");
150 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
151 MediaTracker mt = new MediaTracker(this);
152 mt.addImage(image, 0);
153 Image logo = (Platform.isJS() ? null
154 : java.awt.Toolkit.getDefaultToolkit().createImage(getClass()
155 .getResource("/images/Jalview_Logo_small.png")));
158 mt.addImage(logo, 1);
165 } catch (InterruptedException x)
170 System.err.println("Error when loading images!");
172 } while (!mt.checkAll());
175 Desktop.getInstance().setIconImage(logo);
177 } catch (Exception ex)
180 iframe = new JInternalFrame();
181 iframe.setFrameIcon(null);
182 iframe.setClosable(interactiveDialog);
183 this.setLayout(new BorderLayout());
184 iframe.setContentPane(this);
185 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
186 if (htmlPane instanceof JTextPane)
188 ((JTextPane) htmlPane).setEditable(false);
190 SplashImage splashimg = new SplashImage(image);
191 iconimg.add(splashimg, BorderLayout.CENTER);
192 add(iconimg, BorderLayout.NORTH);
193 add(htmlPane, BorderLayout.CENTER);
194 htmlPane.addMouseListener(closer);
195 Desktop.getDesktopPane().add(iframe);
201 private int mainState;
204 * update text in author text panel reflecting current version information
206 protected boolean refreshText()
208 Desktop desktop = Desktop.getInstance();
209 String newtext = desktop.getAboutMessage(true).toString();
210 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
211 if (oldtext != newtext.length())
213 iframe.setVisible(false);
214 oldtext = newtext.length();
215 System.out.println(newtext);
216 if (Platform.isJS()) // BH 2019
218 // BH TODO SwingJS does not implement HTML style. Could rethink this.
220 htmlPane = new JLabel(newtext);
222 .setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
223 ((JLabel) htmlPane).setOpaque(true);
224 ((JLabel) htmlPane).setBackground(Color.white);
233 htmlPane = new JTextPane();
234 ((JTextPane) htmlPane).setEditable(false);
235 ((JTextPane) htmlPane).setContentType("text/html");
236 ((JTextPane) htmlPane).setText(newtext);
237 ((JTextPane) htmlPane).addHyperlinkListener(this);
239 htmlPane.addMouseListener(closer);
241 htmlPane.setVisible(true);
242 htmlPane.setSize(new Dimension(750, 375));
243 add(htmlPane, BorderLayout.CENTER);
245 iframe.setBounds((desktop.getWidth() - 750) / 2,
246 (desktop.getHeight() - 375) / 2, 750,
247 htmlPane.getHeight() + iconimg.getHeight());
249 iframe.setVisible(true);
256 * Create splash screen, display it and clear it off again.
261 mainState = STATE_INIT;
265 protected long startTime;
267 protected void mainLoop()
273 mainState = STATE_DONE;
278 initSplashScreenWindow();
279 startTime = System.currentTimeMillis() / 1000;
280 mainState = STATE_LOOP;
283 if (!interactiveDialog
284 && ((System.currentTimeMillis() / 1000) - startTime) > 5)
289 if (visible && refreshText())
293 if (interactiveDialog)
297 Timer timer = new Timer(500, new ActionListener()
300 public void actionPerformed(ActionEvent e)
310 Desktop.getInstance().startDialogQueue();
318 * Close the internal frame, either from the timer expiring or from the mouse
321 public void closeSplash()
326 iframe.setClosed(true);
327 } catch (Exception ex)
332 public class SplashImage extends JPanel
336 public SplashImage(Image todisplay)
341 setPreferredSize(new Dimension(image.getWidth(this) + 8,
342 image.getHeight(this)));
347 public Dimension getPreferredSize()
349 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
353 public void paintComponent(Graphics g)
355 g.setColor(Color.white);
356 g.fillRect(0, 0, getWidth(), getHeight());
357 g.setColor(Color.black);
358 g.setFont(new Font("Verdana", Font.BOLD, fontSize + 6));
362 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
363 (getHeight() - image.getHeight(this)) / 2, this);
369 * g.drawString("Jalview " + jalview.bin.Cache.getProperty("VERSION"), 50,
372 * FontMetrics fm = g.getFontMetrics(); int vwidth =
373 * fm.stringWidth("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
374 * g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); g.drawString(
375 * "Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"),
376 * 50 + vwidth + 5, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION",
377 * "Checking").equals( "Checking")) { // Displayed when code version and
378 * jnlp version do not match g.drawString("...Checking latest version...",
379 * 50, y += fontSize + 10); y += 5; g.setColor(Color.black); } else if
380 * (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
381 * .equals(jalview.bin.Cache.getProperty("VERSION"))) { if
382 * (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
383 * .indexOf("automated build") == -1) { // Displayed when code version and
384 * jnlp version do not match and code // version is not a development build
385 * g.setColor(Color.red); } g.drawString( "!! Jalview version " +
386 * jalview.bin.Cache.getDefault("LATEST_VERSION", "..Checking..") +
387 * " is available for download from "
388 * +jalview.bin.Cache.getDefault("www.jalview.org"
389 * ,"http://www.jalview.org")+" !!", 50, y += fontSize + 10); y += 5;
390 * g.setColor(Color.black); }
392 * g.setFont(new Font("Verdana", Font.BOLD, fontSize)); g.drawString(
393 * "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,"
394 * , 50, y += fontSize + 4); g.drawString("David Martin & Geoff Barton.",
395 * 60, y += fontSize + 4); g.drawString(
396 * "Development managed by The Barton Group, University of Dundee.", 50, y
397 * += fontSize + 4); g.drawString("If you use Jalview, please cite: ", 50,
398 * y += fontSize + 4); g.drawString(
399 * "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
400 * , 50, y += fontSize + 4); g.drawString(
401 * "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
402 * , 50, y += fontSize + 4);
403 * g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", 50, y
404 * += fontSize + 4); }
409 public void hyperlinkUpdate(HyperlinkEvent e)
411 Desktop.hyperlinkUpdate(e);