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.event.HyperlinkEvent;
40 import javax.swing.event.HyperlinkListener;
42 import jalview.util.ChannelProperties;
43 import jalview.util.Platform;
51 public class SplashScreen extends JPanel
52 implements Runnable, HyperlinkListener
54 private static final int SHOW_FOR_SECS = 5;
56 private static final int FONT_SIZE = 11;
58 private boolean visible = true;
60 private JPanel iconimg = new JPanel(new BorderLayout());
62 // could change fg, bg, font later to use ChannelProperties
63 private static Color bg = Color.WHITE;
65 private static Color fg = Color.BLACK;
67 private static Font font = new Font("SansSerif", Font.PLAIN, FONT_SIZE);
70 * as JTextPane in Java, JLabel in javascript
72 private Component splashText;
74 private JInternalFrame iframe;
78 private boolean transientDialog = false;
80 private long oldTextLength = -1;
82 public static int logoSize = 32;
85 * allow click in the initial splash screen to dismiss it
86 * immediately (not if opened from About menu)
88 private MouseAdapter closer = new MouseAdapter()
91 public void mousePressed(MouseEvent evt)
99 } catch (Exception ex)
107 * Constructor that displays the splash screen
110 * if true the panel removes itself on click or after a few seconds;
111 * if false it stays up until closed by the user
113 public SplashScreen(boolean isTransient)
115 this.transientDialog = isTransient;
117 if (Platform.isJS()) // BH 2019
119 splashText = new JLabel("");
130 splashText = new JTextPane();
131 splashText.setBackground(bg);
132 splashText.setForeground(fg);
133 splashText.setFont(font);
134 Thread t = new Thread(this);
141 * ping the jalview version page then create and display the jalview
142 * splashscreen window.
144 void initSplashScreenWindow()
146 addMouseListener(closer);
150 if (!Platform.isJS())
152 image = ChannelProperties.getImage("banner");
153 Image logo = ChannelProperties.getImage("logo.48");
154 MediaTracker mt = new MediaTracker(this);
157 mt.addImage(image, 0);
161 mt.addImage(logo, 1);
168 } catch (InterruptedException x)
173 System.err.println("Error when loading images!");
175 } while (!mt.checkAll());
176 Desktop.instance.setIconImages(ChannelProperties.getIconList());
178 } catch (Exception ex)
182 this.setBackground(bg);
183 this.setForeground(fg);
186 iframe = new JInternalFrame();
187 iframe.setFrameIcon(null);
188 iframe.setClosable(true);
189 this.setLayout(new BorderLayout());
190 iframe.setContentPane(this);
191 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
192 iframe.setBackground(bg);
193 iframe.setForeground(fg);
194 iframe.setFont(font);
198 // ignore in JavaScript
207 ((JTextPane) splashText).setEditable(false);
208 splashText.setBackground(bg);
209 splashText.setForeground(fg);
210 splashText.setFont(font);
212 SplashImage splashimg = new SplashImage(image);
213 iconimg.add(splashimg, BorderLayout.LINE_START);
214 iconimg.setBackground(bg);
215 add(iconimg, BorderLayout.NORTH);
217 add(splashText, BorderLayout.CENTER);
218 splashText.addMouseListener(closer);
219 Desktop.desktop.add(iframe);
224 * update text in author text panel reflecting current version information
226 protected boolean refreshText()
228 String newtext = Desktop.instance.getAboutMessage();
229 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
230 if (oldTextLength != newtext.length())
232 iframe.setVisible(false);
233 oldTextLength = newtext.length();
234 if (Platform.isJS()) // BH 2019
237 * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
238 * to display formatted html, so we use a simple alternative
240 String text = "<html><br><br><img src=\"swingjs/j2s/images/jalview_logo-48.png\"/><br>"
241 + newtext + "</html>";
242 JLabel ta = new JLabel(text);
244 ta.setBackground(Color.white);
254 JTextPane jtp = new JTextPane();
255 jtp.setEditable(false);
256 jtp.setBackground(bg);
257 jtp.setForeground(fg);
259 jtp.setContentType("text/html");
260 jtp.setText("<html>" + newtext + "</html>");
261 jtp.addHyperlinkListener(this);
264 splashText.addMouseListener(closer);
266 splashText.setVisible(true);
267 splashText.setSize(new Dimension(750, 375 + logoSize));
268 splashText.setBackground(bg);
269 splashText.setForeground(fg);
270 splashText.setFont(font);
271 add(splashText, BorderLayout.CENTER);
273 iframe.setBounds((Desktop.instance.getWidth() - 750) / 2,
274 (Desktop.instance.getHeight() - 375) / 2, 750,
275 splashText.getHeight() + iconimg.getHeight());
277 iframe.setVisible(true);
284 * Create splash screen, display it and clear it off again.
289 initSplashScreenWindow();
291 long startTime = System.currentTimeMillis() / 1000;
299 } catch (Exception ex)
303 if (transientDialog && ((System.currentTimeMillis() / 1000)
304 - startTime) > SHOW_FOR_SECS)
309 if (visible && refreshText())
313 if (!transientDialog)
320 Desktop.instance.startDialogQueue();
326 public void closeSplash()
331 iframe.setClosed(true);
332 } catch (Exception ex)
337 public class SplashImage extends JPanel
341 public SplashImage(Image todisplay)
346 setPreferredSize(new Dimension(image.getWidth(this) + 8,
347 image.getHeight(this)));
352 public Dimension getPreferredSize()
354 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
358 public void paintComponent(Graphics g)
361 g.fillRect(0, 0, getWidth(), getHeight());
363 g.setFont(new Font(font.getFontName(), Font.BOLD, FONT_SIZE + 6));
367 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
368 (getHeight() - image.getHeight(this)) / 2, this);
374 public void hyperlinkUpdate(HyperlinkEvent e)
376 Desktop.hyperlinkUpdate(e);