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.Component;
26 import java.awt.Dimension;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.MediaTracker;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
34 import javax.swing.JInternalFrame;
35 import javax.swing.JLabel;
36 import javax.swing.JLayeredPane;
37 import javax.swing.JPanel;
38 import javax.swing.JTextPane;
39 import javax.swing.SwingUtilities;
40 import javax.swing.event.HyperlinkEvent;
41 import javax.swing.event.HyperlinkListener;
43 import jalview.util.ChannelProperties;
44 import jalview.util.Platform;
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());
63 // could change fg, bg, font later to use ChannelProperties (these are not
64 // actually being used!)
65 private static Color bg = Color.WHITE;
67 private static Color fg = Color.BLACK;
69 private static Font font = new Font("SansSerif", Font.PLAIN, FONT_SIZE);
72 * as JTextPane in Java, JLabel in javascript
74 private Component splashText;
76 private JInternalFrame iframe;
80 private boolean transientDialog = false;
82 private long oldTextLength = -1;
84 public static int logoSize = 32;
87 * allow click in the initial splash screen to dismiss it
88 * immediately (not if opened from About menu)
90 private MouseAdapter closer = new MouseAdapter()
93 public void mousePressed(MouseEvent evt)
101 } catch (Exception ex)
109 * Constructor that displays the splash screen
112 * if true the panel removes itself on click or after a few seconds;
113 * if false it stays up until closed by the user
115 public SplashScreen(boolean isTransient)
117 this.transientDialog = isTransient;
118 if (this.transientDialog)
120 Desktop.instance.acquireDialogQueue();
123 if (Platform.isJS()) // BH 2019
125 splashText = new JLabel("");
136 splashText = new JTextPane();
137 splashText.setBackground(bg);
138 splashText.setForeground(fg);
139 splashText.setFont(font);
140 Thread t = new Thread(this);
147 * ping the jalview version page then create and display the jalview
148 * splashscreen window.
150 void initSplashScreenWindow()
152 addMouseListener(closer);
156 if (!Platform.isJS())
158 image = ChannelProperties.getImage("banner");
159 Image logo = ChannelProperties.getImage("logo.48");
160 MediaTracker mt = new MediaTracker(this);
163 mt.addImage(image, 0);
167 mt.addImage(logo, 1);
174 } catch (InterruptedException x)
179 jalview.bin.Console.errPrintln("Error when loading images!");
181 } while (!mt.checkAll());
182 Desktop.instance.setIconImages(ChannelProperties.getIconList());
184 } catch (Exception ex)
188 this.setBackground(bg);
189 this.setForeground(fg);
192 iframe = new JInternalFrame();
193 iframe.setFrameIcon(null);
194 iframe.setClosable(true);
195 this.setLayout(new BorderLayout());
196 iframe.setContentPane(this);
197 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
198 iframe.setBackground(bg);
199 iframe.setForeground(fg);
200 iframe.setFont(font);
204 // ignore in JavaScript
213 ((JTextPane) splashText).setEditable(false);
214 splashText.setBackground(bg);
215 splashText.setForeground(fg);
216 splashText.setFont(font);
218 SplashImage splashimg = new SplashImage(image);
219 iconimg.add(splashimg, BorderLayout.LINE_START);
220 iconimg.setBackground(bg);
221 add(iconimg, BorderLayout.NORTH);
223 add(splashText, BorderLayout.CENTER);
224 splashText.addMouseListener(closer);
225 Desktop.desktop.add(iframe);
230 * update text in author text panel reflecting current version information
232 protected boolean refreshText()
234 String newtext = Desktop.instance.getAboutMessage();
235 // jalview.bin.Console.errPrintln("Text found: \n"+newtext+"\nEnd of
237 if (oldTextLength != newtext.length())
239 iframe.setVisible(false);
240 oldTextLength = newtext.length();
241 if (Platform.isJS()) // BH 2019
244 * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
245 * to display formatted html, so we use a simple alternative
247 String text = "<html><br><img src=\""
248 + ChannelProperties.getImageURL("banner") + "\"/>" + newtext
250 JLabel ta = new JLabel(text);
252 ta.setBackground(Color.white);
262 JTextPane jtp = new JTextPane();
263 jtp.setEditable(false);
264 jtp.setBackground(bg);
265 jtp.setForeground(fg);
267 jtp.setContentType("text/html");
268 jtp.setText("<html>" + newtext + "</html>");
269 jtp.addHyperlinkListener(this);
272 splashText.addMouseListener(closer);
274 splashText.setVisible(true);
275 splashText.setSize(new Dimension(750,
276 425 + logoSize + (Platform.isJS() ? 40 : 0)));
277 splashText.setBackground(bg);
278 splashText.setForeground(fg);
279 splashText.setFont(font);
280 add(splashText, BorderLayout.CENTER);
282 int width = Math.max(splashText.getWidth(), iconimg.getWidth());
283 int height = splashText.getHeight() + iconimg.getHeight();
285 Math.max(0, (Desktop.instance.getWidth() - width) / 2),
286 Math.max(0, (Desktop.instance.getHeight() - height) / 2),
289 iframe.setVisible(true);
296 * Create splash screen, display it and clear it off again.
301 initSplashScreenWindow();
303 long startTime = System.currentTimeMillis() / 1000;
311 } catch (Exception ex)
315 if (transientDialog && ((System.currentTimeMillis() / 1000)
316 - startTime) > SHOW_FOR_SECS)
321 if (visible && refreshText())
325 if (!transientDialog)
337 public void closeSplash()
339 if (this.transientDialog)
341 Desktop.instance.releaseDialogQueue();
345 final JInternalFrame frme = iframe;
346 SwingUtilities.invokeLater(new Runnable()
353 frme.setClosed(true);
354 } catch (Exception ex)
359 } catch (Exception ex)
364 public class SplashImage extends JPanel
368 public SplashImage(Image todisplay)
373 setPreferredSize(new Dimension(image.getWidth(this) + 8,
374 image.getHeight(this)));
379 public Dimension getPreferredSize()
381 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
385 public void paintComponent(Graphics g)
388 g.fillRect(0, 0, getWidth(), getHeight());
390 g.setFont(new Font(font.getFontName(), Font.BOLD, FONT_SIZE + 6));
394 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
395 (getHeight() - image.getHeight(this)) / 2, this);
401 public void hyperlinkUpdate(HyperlinkEvent e)
403 Desktop.hyperlinkUpdate(e);