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.MediaTracker;
33 import java.awt.Toolkit;
34 import java.awt.event.MouseAdapter;
35 import java.awt.event.MouseEvent;
38 import javax.swing.JInternalFrame;
39 import javax.swing.JLabel;
40 import javax.swing.JLayeredPane;
41 import javax.swing.JPanel;
42 import javax.swing.JTextPane;
43 import javax.swing.event.HyperlinkEvent;
44 import javax.swing.event.HyperlinkListener;
52 public class SplashScreen extends JPanel
53 implements Runnable, HyperlinkListener
55 private static final int SHOW_FOR_SECS = 5;
57 private static final int FONT_SIZE = 11;
59 private boolean visible = true;
61 private JPanel iconimg = new JPanel(new BorderLayout());
64 * as JTextPane in Java, JLabel in javascript
66 private Component splashText;
68 private JInternalFrame iframe;
72 private boolean transientDialog = false;
74 private long oldTextLength = -1;
77 * allow click in the initial splash screen to dismiss it
78 * immediately (not if opened from About menu)
80 private MouseAdapter closer = new MouseAdapter()
83 public void mousePressed(MouseEvent evt)
91 } catch (Exception ex)
99 * Constructor that displays the splash screen
102 * if true the panel removes itself on click or after a few seconds;
103 * if false it stays up until closed by the user
105 public SplashScreen(boolean isTransient)
107 this.transientDialog = isTransient;
109 if (Platform.isJS()) // BH 2019
111 splashText = new JLabel("");
122 splashText = new JTextPane();
123 Thread t = new Thread(this);
130 * ping the jalview version page then create and display the jalview
131 * splashscreen window.
133 void initSplashScreenWindow()
135 addMouseListener(closer);
139 URL url = getClass().getResource("/images/Jalview_Logo.png");
140 URL urllogo = getClass()
141 .getResource("/images/Jalview_Logo_small.png");
143 if (!Platform.isJS() && url != null)
145 image = Toolkit.getDefaultToolkit().createImage(url);
146 Image logo = Toolkit.getDefaultToolkit().createImage(urllogo);
147 MediaTracker mt = new MediaTracker(this);
148 mt.addImage(image, 0);
149 mt.addImage(logo, 1);
155 } catch (InterruptedException x)
160 System.err.println("Error when loading images!");
162 } while (!mt.checkAll());
163 Desktop.instance.setIconImage(logo);
165 } catch (Exception ex)
169 iframe = new JInternalFrame();
170 iframe.setFrameIcon(null);
171 iframe.setClosable(true);
172 this.setLayout(new BorderLayout());
173 iframe.setContentPane(this);
174 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
177 // ignore in JavaScript
186 ((JTextPane) splashText).setEditable(false);
188 SplashImage splashimg = new SplashImage(image);
189 iconimg.add(splashimg, BorderLayout.CENTER);
190 add(iconimg, BorderLayout.NORTH);
192 add(splashText, BorderLayout.CENTER);
193 splashText.addMouseListener(closer);
194 Desktop.desktop.add(iframe);
199 * update text in author text panel reflecting current version information
201 protected boolean refreshText()
203 String newtext = Desktop.instance.getAboutMessage();
204 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
205 if (oldTextLength != newtext.length())
207 iframe.setVisible(false);
208 oldTextLength = newtext.length();
209 if (Platform.isJS()) // BH 2019
212 * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
213 * to display formatted html, so we use a simple alternative
215 String text = "<html><br><br><img src=\"swingjs/j2s/images/Jalview_Logo.png\"/><br>"
216 + newtext + "</html>";
217 JLabel ta = new JLabel(text);
219 ta.setBackground(Color.white);
229 JTextPane jtp = new JTextPane();
230 jtp.setEditable(false);
231 jtp.setContentType("text/html");
232 jtp.setText("<html>" + newtext + "</html>");
233 jtp.addHyperlinkListener(this);
236 splashText.addMouseListener(closer);
238 splashText.setVisible(true);
239 splashText.setSize(new Dimension(750, 375));
240 add(splashText, BorderLayout.CENTER);
242 iframe.setBounds((Desktop.instance.getWidth() - 750) / 2,
243 (Desktop.instance.getHeight() - 375) / 2, 750,
244 splashText.getHeight() + iconimg.getHeight());
246 iframe.setVisible(true);
253 * Create splash screen, display it and clear it off again.
258 initSplashScreenWindow();
260 long startTime = System.currentTimeMillis() / 1000;
268 } catch (Exception ex)
273 && ((System.currentTimeMillis() / 1000) - startTime) > SHOW_FOR_SECS)
278 if (visible && refreshText())
282 if (!transientDialog)
289 Desktop.instance.startDialogQueue();
295 public void closeSplash()
300 iframe.setClosed(true);
301 } catch (Exception ex)
306 public class SplashImage extends JPanel
310 public SplashImage(Image todisplay)
315 setPreferredSize(new Dimension(image.getWidth(this) + 8,
316 image.getHeight(this)));
321 public Dimension getPreferredSize()
323 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
327 public void paintComponent(Graphics g)
329 g.setColor(Color.white);
330 g.fillRect(0, 0, getWidth(), getHeight());
331 g.setColor(Color.black);
332 g.setFont(new Font("Verdana", Font.BOLD, FONT_SIZE + 6));
336 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
337 (getHeight() - image.getHeight(this)) / 2, this);
343 public void hyperlinkUpdate(HyperlinkEvent e)
345 Desktop.hyperlinkUpdate(e);