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 (these are not
63 // actually being used!)
64 private static Color bg = Color.WHITE;
66 private static Color fg = Color.BLACK;
68 private static Font font = new Font("SansSerif", Font.PLAIN, FONT_SIZE);
71 * as JTextPane in Java, JLabel in javascript
73 private Component splashText;
75 private JInternalFrame iframe;
79 private boolean transientDialog = false;
81 private long oldTextLength = -1;
83 public static int logoSize = 32;
86 * allow click in the initial splash screen to dismiss it
87 * immediately (not if opened from About menu)
89 private MouseAdapter closer = new MouseAdapter()
92 public void mousePressed(MouseEvent evt)
100 } catch (Exception ex)
108 * Constructor that displays the splash screen
111 * if true the panel removes itself on click or after a few seconds;
112 * if false it stays up until closed by the user
114 public SplashScreen(boolean isTransient)
116 Desktop.instance.acquireDialogQueue();
117 this.transientDialog = isTransient;
119 if (Platform.isJS()) // BH 2019
121 splashText = new JLabel("");
132 splashText = new JTextPane();
133 splashText.setBackground(bg);
134 splashText.setForeground(fg);
135 splashText.setFont(font);
136 Thread t = new Thread(this);
143 * ping the jalview version page then create and display the jalview
144 * splashscreen window.
146 void initSplashScreenWindow()
148 addMouseListener(closer);
152 if (!Platform.isJS())
154 image = ChannelProperties.getImage("banner");
155 Image logo = ChannelProperties.getImage("logo.48");
156 MediaTracker mt = new MediaTracker(this);
159 mt.addImage(image, 0);
163 mt.addImage(logo, 1);
170 } catch (InterruptedException x)
175 System.err.println("Error when loading images!");
177 } while (!mt.checkAll());
178 Desktop.instance.setIconImages(ChannelProperties.getIconList());
180 } catch (Exception ex)
184 this.setBackground(bg);
185 this.setForeground(fg);
188 iframe = new JInternalFrame();
189 iframe.setFrameIcon(null);
190 iframe.setClosable(true);
191 this.setLayout(new BorderLayout());
192 iframe.setContentPane(this);
193 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
194 iframe.setBackground(bg);
195 iframe.setForeground(fg);
196 iframe.setFont(font);
200 // ignore in JavaScript
209 ((JTextPane) splashText).setEditable(false);
210 splashText.setBackground(bg);
211 splashText.setForeground(fg);
212 splashText.setFont(font);
214 SplashImage splashimg = new SplashImage(image);
215 iconimg.add(splashimg, BorderLayout.LINE_START);
216 iconimg.setBackground(bg);
217 add(iconimg, BorderLayout.NORTH);
219 add(splashText, BorderLayout.CENTER);
220 splashText.addMouseListener(closer);
221 Desktop.desktop.add(iframe);
226 * update text in author text panel reflecting current version information
228 protected boolean refreshText()
230 String newtext = Desktop.instance.getAboutMessage();
231 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
232 if (oldTextLength != newtext.length())
234 iframe.setVisible(false);
235 oldTextLength = newtext.length();
236 if (Platform.isJS()) // BH 2019
239 * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
240 * to display formatted html, so we use a simple alternative
242 String text = "<html><br><img src=\""
243 + ChannelProperties.getImageURL("banner") + "\"/>" + newtext
245 JLabel ta = new JLabel(text);
247 ta.setBackground(Color.white);
257 JTextPane jtp = new JTextPane();
258 jtp.setEditable(false);
259 jtp.setBackground(bg);
260 jtp.setForeground(fg);
262 jtp.setContentType("text/html");
263 jtp.setText("<html>" + newtext + "</html>");
264 jtp.addHyperlinkListener(this);
267 splashText.addMouseListener(closer);
269 splashText.setVisible(true);
270 splashText.setSize(new Dimension(750,
271 425 + logoSize + (Platform.isJS() ? 40 : 0)));
272 splashText.setBackground(bg);
273 splashText.setForeground(fg);
274 splashText.setFont(font);
275 add(splashText, BorderLayout.CENTER);
277 int width = Math.max(splashText.getWidth(), iconimg.getWidth());
278 int height = splashText.getHeight() + iconimg.getHeight();
280 Math.max(0, (Desktop.instance.getWidth() - width) / 2),
281 Math.max(0, (Desktop.instance.getHeight() - height) / 2),
284 iframe.setVisible(true);
291 * Create splash screen, display it and clear it off again.
296 initSplashScreenWindow();
298 long startTime = System.currentTimeMillis() / 1000;
306 } catch (Exception ex)
310 if (transientDialog && ((System.currentTimeMillis() / 1000)
311 - startTime) > SHOW_FOR_SECS)
316 if (visible && refreshText())
320 if (!transientDialog)
327 Desktop.instance.releaseDialogQueue();
333 public void closeSplash()
338 iframe.setClosed(true);
339 } catch (Exception ex)
344 public class SplashImage extends JPanel
348 public SplashImage(Image todisplay)
353 setPreferredSize(new Dimension(image.getWidth(this) + 8,
354 image.getHeight(this)));
359 public Dimension getPreferredSize()
361 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
365 public void paintComponent(Graphics g)
368 g.fillRect(0, 0, getWidth(), getHeight());
370 g.setFont(new Font(font.getFontName(), Font.BOLD, FONT_SIZE + 6));
374 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
375 (getHeight() - image.getHeight(this)) / 2, this);
381 public void hyperlinkUpdate(HyperlinkEvent e)
383 Desktop.hyperlinkUpdate(e);