From: BobHanson Date: Tue, 5 Nov 2019 18:33:23 +0000 (-0600) Subject: enabling Splash screen in JavaScript. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=72f96c9a8773366b67f3766acf1ede5c86c43d01;p=jalview.git enabling Splash screen in JavaScript. --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 9e0c89b..ae3b652 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -473,17 +473,6 @@ public class Desktop extends GDesktop checkURLLinks(); - // Spawn a thread that shows the splashscreen - - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - new SplashScreen(); - } - }); - // Thread off a new instance of the file chooser - this reduces the time // it // takes to open it later on. @@ -516,6 +505,17 @@ public class Desktop extends GDesktop } + // Spawn a thread that shows the splashscreen + + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + new SplashScreen(); + } + }); + this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); this.addWindowListener(new WindowAdapter() diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index f5648d2..97707be 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -29,7 +29,10 @@ import java.awt.Dimension; 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; @@ -38,6 +41,8 @@ import javax.swing.JLabel; 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; @@ -50,6 +55,12 @@ 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()); @@ -57,7 +68,7 @@ public class SplashScreen extends JPanel /** * either text area in javascript or in java text pane */ - Component authlist; + Component htmlPane; JInternalFrame iframe; @@ -75,7 +86,7 @@ public class SplashScreen extends JPanel this(false); } - private boolean interactiveDialog = false; + protected boolean interactiveDialog = false; /** * @@ -89,7 +100,7 @@ public class SplashScreen extends JPanel // show a splashscreen that will disapper if (Platform.isJS()) // BH 2019 { - authlist = new JLabel(""); + htmlPane = new JLabel(""); run(); } else @@ -100,7 +111,7 @@ public class SplashScreen extends JPanel * @j2sIgnore */ { - authlist = new JTextPane(); + htmlPane = new JTextPane(); Thread t = new Thread(this, "SplashScreen"); t.start(); } @@ -130,77 +141,68 @@ public class SplashScreen extends JPanel * 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(); @@ -210,13 +212,16 @@ public class SplashScreen extends JPanel { iframe.setVisible(false); oldtext = newtext.length(); + System.out.println(newtext); if (Platform.isJS()) // BH 2019 { - authlist = new JLabel( - "


" - + 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 /** @@ -225,21 +230,21 @@ public class SplashScreen extends JPanel * @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; @@ -253,46 +258,65 @@ public class SplashScreen extends JPanel @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() { diff --git a/swingjs/SwingJS-site.zip b/swingjs/SwingJS-site.zip index b5efc84..88b0b71 100644 Binary files a/swingjs/SwingJS-site.zip and b/swingjs/SwingJS-site.zip differ diff --git a/swingjs/net.sf.j2s.core.jar b/swingjs/net.sf.j2s.core.jar index e2efdd4..e0cee1d 100644 Binary files a/swingjs/net.sf.j2s.core.jar and b/swingjs/net.sf.j2s.core.jar differ diff --git a/swingjs/timestamp b/swingjs/timestamp index d4e34e1..7e54dca 100644 --- a/swingjs/timestamp +++ b/swingjs/timestamp @@ -1 +1 @@ -20191030143851 +20191105122130 diff --git a/swingjs/ver/3.2.4/SwingJS-site.zip b/swingjs/ver/3.2.4/SwingJS-site.zip index b5efc84..88b0b71 100644 Binary files a/swingjs/ver/3.2.4/SwingJS-site.zip and b/swingjs/ver/3.2.4/SwingJS-site.zip differ diff --git a/swingjs/ver/3.2.4/net.sf.j2s.core.jar b/swingjs/ver/3.2.4/net.sf.j2s.core.jar index e2efdd4..e0cee1d 100644 Binary files a/swingjs/ver/3.2.4/net.sf.j2s.core.jar and b/swingjs/ver/3.2.4/net.sf.j2s.core.jar differ diff --git a/swingjs/ver/3.2.4/timestamp b/swingjs/ver/3.2.4/timestamp index d4e34e1..7e54dca 100644 --- a/swingjs/ver/3.2.4/timestamp +++ b/swingjs/ver/3.2.4/timestamp @@ -1 +1 @@ -20191030143851 +20191105122130