import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
+import java.awt.Insets;
import java.awt.MediaTracker;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JTextPane;
+import javax.swing.Timer;
+import javax.swing.border.EmptyBorder;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class SplashScreen extends JPanel
implements Runnable, HyperlinkListener
{
+ private static final int STATE_INIT = 0;
+
+ private static final int STATE_LOOP = 1;
+
+ private static final int STATE_DONE = 2;
+
boolean visible = true;
JPanel iconimg = new JPanel(new BorderLayout());
/**
* either text area in javascript or in java text pane
*/
- Component authlist;
+ Component htmlPane;
JInternalFrame iframe;
this(false);
}
- private boolean interactiveDialog = false;
+ protected boolean interactiveDialog = false;
/**
*
// show a splashscreen that will disapper
if (Platform.isJS()) // BH 2019
{
- authlist = new JLabel("");
+ htmlPane = new JLabel("");
run();
}
else
* @j2sIgnore
*/
{
- authlist = new JTextPane();
+ htmlPane = new JTextPane();
Thread t = new Thread(this, "SplashScreen");
t.start();
}
* ping the jalview version page then create and display the jalview
* splashscreen window.
*/
- void initSplashScreenWindow()
+ protected void initSplashScreenWindow()
{
addMouseListener(closer);
try
{
java.net.URL url = getClass().getResource("/images/Jalview_Logo.png");
- java.net.URL urllogo = getClass()
- .getResource("/images/Jalview_Logo_small.png");
-
- if (!Platform.isJS() && url != null)
+ image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
+ MediaTracker mt = new MediaTracker(this);
+ mt.addImage(image, 0);
+ Image logo = (Platform.isJS() ? null
+ : java.awt.Toolkit.getDefaultToolkit().createImage(getClass()
+ .getResource("/images/Jalview_Logo_small.png")));
+ if (logo != null)
{
- image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
- Image logo = java.awt.Toolkit.getDefaultToolkit()
- .createImage(urllogo);
- MediaTracker mt = new MediaTracker(this);
- mt.addImage(image, 0);
mt.addImage(logo, 1);
- do
+ }
+ do
+ {
+ try
{
- try
- {
- mt.waitForAll();
- } catch (InterruptedException x)
- {
- }
- if (mt.isErrorAny())
- {
- System.err.println("Error when loading images!");
- }
- } while (!mt.checkAll());
+ mt.waitForAll();
+ } catch (InterruptedException x)
+ {
+ }
+ if (mt.isErrorAny())
+ {
+ System.err.println("Error when loading images!");
+ }
+ } while (!mt.checkAll());
+ if (url != null)
+ {
Desktop.getInstance().setIconImage(logo);
}
} catch (Exception ex)
{
}
-
iframe = new JInternalFrame();
iframe.setFrameIcon(null);
iframe.setClosable(interactiveDialog);
this.setLayout(new BorderLayout());
iframe.setContentPane(this);
iframe.setLayer(JLayeredPane.PALETTE_LAYER);
- if (Platform.isJS())
+ if (htmlPane instanceof JTextPane)
{
- // ignore in JavaScript
- }
- else
- /**
- * Java only
- *
- * @j2sIgnore
- */
- {
- ((JTextPane) authlist).setEditable(false);
-
- SplashImage splashimg = new SplashImage(image);
- iconimg.add(splashimg, BorderLayout.CENTER);
- add(iconimg, BorderLayout.NORTH);
+ ((JTextPane) htmlPane).setEditable(false);
}
- add(authlist, BorderLayout.CENTER);
- authlist.addMouseListener(closer);
+ SplashImage splashimg = new SplashImage(image);
+ iconimg.add(splashimg, BorderLayout.CENTER);
+ add(iconimg, BorderLayout.NORTH);
+ add(htmlPane, BorderLayout.CENTER);
+ htmlPane.addMouseListener(closer);
Desktop.getDesktopPane().add(iframe);
refreshText();
}
long oldtext = -1;
+ private int mainState;
+
/**
* update text in author text panel reflecting current version information
*/
- @SuppressWarnings("unused")
protected boolean refreshText()
{
Desktop desktop = Desktop.getInstance();
{
iframe.setVisible(false);
oldtext = newtext.length();
+ System.out.println(newtext);
if (Platform.isJS()) // BH 2019
{
- authlist = new JLabel(
- "<html><br/><br/><img src=\"swingjs/j2s/images/Jalview_Logo.png\"/><br/>"
- + newtext);
- ((JLabel) authlist).setOpaque(true);
- ((JLabel) authlist).setBackground(Color.white);
+ // BH TODO SwingJS does not implement HTML style. Could rethink this.
+
+ htmlPane = new JLabel(newtext);
+ ((JLabel) htmlPane)
+ .setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
+ ((JLabel) htmlPane).setOpaque(true);
+ ((JLabel) htmlPane).setBackground(Color.white);
}
else
/**
* @j2sIgnore
*/
{
- authlist = new JTextPane();
- ((JTextPane) authlist).setEditable(false);
- ((JTextPane) authlist).setContentType("text/html");
- ((JTextPane) authlist).setText(newtext);
- ((JTextPane) authlist).addHyperlinkListener(this);
+ htmlPane = new JTextPane();
+ ((JTextPane) htmlPane).setEditable(false);
+ ((JTextPane) htmlPane).setContentType("text/html");
+ ((JTextPane) htmlPane).setText(newtext);
+ ((JTextPane) htmlPane).addHyperlinkListener(this);
}
- authlist.addMouseListener(closer);
+ htmlPane.addMouseListener(closer);
- authlist.setVisible(true);
- authlist.setSize(new Dimension(750, 375));
- add(authlist, BorderLayout.CENTER);
+ htmlPane.setVisible(true);
+ htmlPane.setSize(new Dimension(750, 375));
+ add(htmlPane, BorderLayout.CENTER);
revalidate();
iframe.setBounds((desktop.getWidth() - 750) / 2,
(desktop.getHeight() - 375) / 2, 750,
- authlist.getHeight() + iconimg.getHeight());
+ htmlPane.getHeight() + iconimg.getHeight());
iframe.validate();
iframe.setVisible(true);
return true;
@Override
public void run()
{
- initSplashScreenWindow();
+ mainState = STATE_INIT;
+ mainLoop();
+ }
- long startTime = System.currentTimeMillis() / 1000;
+ protected long startTime;
- while (visible)
+ protected void mainLoop()
+ {
+ while (true)
{
- iframe.repaint();
- try
- {
- Thread.sleep(500);
- } catch (Exception ex)
+ if (!visible)
{
+ mainState = STATE_DONE;
}
-
- if (!interactiveDialog
- && ((System.currentTimeMillis() / 1000) - startTime) > 5)
+ switch (mainState)
{
- visible = false;
- }
+ case STATE_INIT:
+ initSplashScreenWindow();
+ startTime = System.currentTimeMillis() / 1000;
+ mainState = STATE_LOOP;
+ continue;
+ case STATE_LOOP:
+ if (!interactiveDialog
+ && ((System.currentTimeMillis() / 1000) - startTime) > 5)
+ {
+ visible = false;
+ continue;
+ }
+ if (visible && refreshText())
+ {
+ iframe.repaint();
+ }
+ if (interactiveDialog)
+ {
+ return;
+ }
+ Timer timer = new Timer(500, new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ mainLoop();
+ }
- if (visible && refreshText())
- {
- // if (interactiveDialog) {
- iframe.repaint();
- // } else {
- // iframe.repaint();
- // };
- }
- if (interactiveDialog)
- {
+ });
+ timer.start();
+ return;
+ case STATE_DONE:
+ closeSplash();
+ Desktop.getInstance().startDialogQueue();
return;
}
}
- closeSplash();
- Desktop.getInstance().startDialogQueue();
}
/**
- * DOCUMENT ME!
+ * Close the internal frame, either from the timer expiring or from the mouse
+ * action.
*/
public void closeSplash()
{