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());
63 * as JTextPane in Java, JLabel in javascript
65 private Component splashText;
67 private JInternalFrame iframe;
71 private boolean transientDialog = false;
73 private long oldTextLength = -1;
76 * allow click in the initial splash screen to dismiss it
77 * immediately (not if opened from About menu)
79 private MouseAdapter closer = new MouseAdapter()
82 public void mousePressed(MouseEvent evt)
90 } catch (Exception ex)
98 * Constructor that displays the splash screen
101 * if true the panel removes itself on click or after a few seconds;
102 * if false it stays up until closed by the user
104 public SplashScreen(boolean isTransient)
106 this.transientDialog = isTransient;
108 if (Platform.isJS()) // BH 2019
110 splashText = new JLabel("");
121 splashText = new JTextPane();
122 Thread t = new Thread(this);
129 * ping the jalview version page then create and display the jalview
130 * splashscreen window.
132 void initSplashScreenWindow()
134 addMouseListener(closer);
138 if (!Platform.isJS())
140 image = ChannelProperties.getImage("banner");
141 Image logo = ChannelProperties.getImage("logo.48");
142 MediaTracker mt = new MediaTracker(this);
145 mt.addImage(image, 0);
149 mt.addImage(logo, 1);
156 } catch (InterruptedException x)
161 System.err.println("Error when loading images!");
163 } while (!mt.checkAll());
164 Desktop.instance.setIconImage(logo);
166 } catch (Exception ex)
170 iframe = new JInternalFrame();
171 iframe.setFrameIcon(null);
172 iframe.setClosable(true);
173 this.setLayout(new BorderLayout());
174 iframe.setContentPane(this);
175 iframe.setLayer(JLayeredPane.PALETTE_LAYER);
178 // ignore in JavaScript
187 ((JTextPane) splashText).setEditable(false);
189 SplashImage splashimg = new SplashImage(image);
190 iconimg.add(splashimg, BorderLayout.CENTER);
191 add(iconimg, BorderLayout.NORTH);
193 add(splashText, BorderLayout.CENTER);
194 splashText.addMouseListener(closer);
195 Desktop.desktop.add(iframe);
200 * update text in author text panel reflecting current version information
202 protected boolean refreshText()
204 String newtext = Desktop.instance.getAboutMessage();
205 // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
206 if (oldTextLength != newtext.length())
208 iframe.setVisible(false);
209 oldTextLength = newtext.length();
210 if (Platform.isJS()) // BH 2019
213 * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
214 * to display formatted html, so we use a simple alternative
216 String text = "<html><br><br><img src=\"swingjs/j2s/images/jalview_logo-48.png\"/><br>"
217 + newtext + "</html>";
218 JLabel ta = new JLabel(text);
220 ta.setBackground(Color.white);
230 JTextPane jtp = new JTextPane();
231 jtp.setEditable(false);
232 jtp.setContentType("text/html");
233 jtp.setText("<html>" + newtext + "</html>");
234 jtp.addHyperlinkListener(this);
237 splashText.addMouseListener(closer);
239 splashText.setVisible(true);
240 splashText.setSize(new Dimension(750, 375));
241 add(splashText, BorderLayout.CENTER);
243 iframe.setBounds((Desktop.instance.getWidth() - 750) / 2,
244 (Desktop.instance.getHeight() - 375) / 2, 750,
245 splashText.getHeight() + iconimg.getHeight());
247 iframe.setVisible(true);
254 * Create splash screen, display it and clear it off again.
259 initSplashScreenWindow();
261 long startTime = System.currentTimeMillis() / 1000;
269 } catch (Exception ex)
273 if (transientDialog && ((System.currentTimeMillis() / 1000)
274 - startTime) > SHOW_FOR_SECS)
279 if (visible && refreshText())
283 if (!transientDialog)
290 Desktop.instance.startDialogQueue();
296 public void closeSplash()
301 iframe.setClosed(true);
302 } catch (Exception ex)
307 public class SplashImage extends JPanel
311 public SplashImage(Image todisplay)
316 setPreferredSize(new Dimension(image.getWidth(this) + 8,
317 image.getHeight(this)));
322 public Dimension getPreferredSize()
324 return new Dimension(image.getWidth(this) + 8, image.getHeight(this));
328 public void paintComponent(Graphics g)
330 g.setColor(Color.white);
331 g.fillRect(0, 0, getWidth(), getHeight());
332 g.setColor(Color.black);
333 g.setFont(new Font("Verdana", Font.BOLD, FONT_SIZE + 6));
337 g.drawImage(image, (getWidth() - image.getWidth(this)) / 2,
338 (getHeight() - image.getHeight(this)) / 2, this);
344 public void hyperlinkUpdate(HyperlinkEvent e)
346 Desktop.hyperlinkUpdate(e);