Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / src / jalview / gui / SplashScreen.java
index 83346fc..fb12330 100755 (executable)
  */
 package jalview.gui;
 
+
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.MediaTracker;
-import java.awt.Toolkit;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 
 import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 import javax.swing.JTextPane;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
 
+import jalview.util.ChannelProperties;
 import jalview.util.Platform;
-import javajs.async.SwingJSUtils.StateHelper;
-import javajs.async.SwingJSUtils.StateMachine;
-
 /**
  * DOCUMENT ME!
  * 
@@ -61,19 +61,31 @@ public class SplashScreen extends JPanel
 
   private static final int SHOW_FOR_SECS = 5;
 
-  private int FONT_SIZE = (Platform.isJS() ? 14 : 11);
+  private static final int FONT_SIZE = (Platform.isJS() ? 14 : 11);
+
+  private boolean visible = true;
+
+  private JPanel iconimg = new JPanel(new BorderLayout());
+
+  // could change fg, bg, font later to use ChannelProperties (these are not
+  // actually being used!)
+  private static Color bg = Color.WHITE;
+
+  private static Color fg = Color.BLACK;
 
-  private JPanel imgPanel = new JPanel(new BorderLayout());
+  /*
+   * as JTextPane in Java, JLabel in javascript
+   */
+  private Component splashText;
 
   private JInternalFrame iframe;
 
-  private Image image, logo;
+  private Image image;
 
-  protected boolean isStartup = false;
+  private boolean transientDialog = false;
 
   private long oldTextLength = -1;
 
-  private StateHelper helper;
   /*
    * allow click in the initial splash screen to dismiss it
    * immediately (not if opened from About menu)
@@ -83,7 +95,7 @@ public class SplashScreen extends JPanel
     @Override
     public void mousePressed(MouseEvent evt)
     {
-      if (isStartup)
+      if (transientDialog)
       {
         try
         {
@@ -104,11 +116,12 @@ public class SplashScreen extends JPanel
    */
   public SplashScreen(boolean isStartup)
   {
-    this.isStartup = isStartup;
+    this.transientDialog = isStartup;
     // we must get the image in JavaScript BEFORE starting the helper,
     // as it will take a 1 ms clock tick to obtain width and height information.
-    image = Toolkit.getDefaultToolkit().createImage(
-            getClass().getResource("/images/Jalview_Logo.png"));
+    image = ChannelProperties.getImage("banner");
+    logo = ChannelProperties.getImage("logo.48");
+    font = new Font("SansSerif", Font.PLAIN, FONT_SIZE);
     helper = new StateHelper(this);
     helper.next(STATE_INIT);
   }
@@ -141,18 +154,8 @@ public class SplashScreen extends JPanel
     if (Platform.isJS())
       return;
     MediaTracker mt = new MediaTracker(this);
-    try
-    {
-      mt.addImage(image, 0);
-      logo = Toolkit.getDefaultToolkit().createImage(
-              getClass().getResource("/images/Jalview_Logo_small.png"));
-    } catch (Exception ex)
-    {
-    }
-    if (logo != null)
-    {
-      mt.addImage(logo, 1);
-    }
+    mt.addImage(image, 0);
+    mt.addImage(logo, 1);
     do
     {
       try
@@ -171,6 +174,9 @@ public class SplashScreen extends JPanel
     {
       Desktop.getInstance().setIconImage(logo);
     }
+    this.setBackground(bg);
+    this.setForeground(fg);
+    this.setFont(font);
   }
 
   /**
@@ -179,26 +185,60 @@ public class SplashScreen extends JPanel
   protected boolean refreshText()
   {
     String newtext = Desktop.getInstance().getAboutMessage();
+    // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
     if (oldTextLength == newtext.length())
     {
       return false;
     }
-    oldTextLength = newtext.length();
+  
     iframe.setVisible(false);
-    JTextPane jtp = new JTextPane();
-    jtp.setEditable(false);
-    jtp.setContentType("text/html");
-    jtp.setText("<html>" + newtext + "</html>");
-    jtp.addHyperlinkListener(this);
-    jtp.setFont(new Font("Verdana", Font.PLAIN, FONT_SIZE));
-    jtp.addMouseListener(closer);
-    jtp.setVisible(true);
-    jtp.setSize(new Dimension(750, 425));
-    add(jtp, BorderLayout.CENTER);
+    oldTextLength = newtext.length();
+    if (Platform.isJS()) // BH 2019
+    {
+      /*
+       * SwingJS doesn't have HTMLEditorKit, required for a JTextPane
+       * to display formatted html, so we use a simple alternative
+       */
+      String text = "<html><br><img src=\""
+              + ChannelProperties.getImageURL("banner") + "\"/>" + newtext
+              + "<br></html>";
+      JLabel ta = new JLabel(text);
+      ta.setOpaque(true);
+      ta.setBackground(Color.white);
+      splashText = ta;
+    }
+    else
+    /**
+     * Java only
+     *
+     * @j2sIgnore
+     */
+    {
+      JTextPane jtp = new JTextPane();
+      jtp.setEditable(false);
+      jtp.setBackground(bg);
+      jtp.setForeground(fg);
+      jtp.setFont(font);
+      jtp.setContentType("text/html");
+      jtp.setText("<html>" + newtext + "</html>");
+      jtp.addHyperlinkListener(this);
+      splashText = jtp;
+    }
+    splashText.addMouseListener(closer);
+
+    splashText.setVisible(true);
+    splashText.setSize(new Dimension(750,
+            375 + logoSize + (Platform.isJS() ? 40 : 0)));
+    splashText.setBackground(bg);
+    splashText.setForeground(fg);
+    splashText.setFont(font);
+    add(splashText, BorderLayout.CENTER);
     revalidate();
-    int h = jtp.getHeight() + imgPanel.getHeight();
-    iframe.setBounds(Math.max(0, (iframe.getParent().getWidth() - 750) / 2),
-           Math.max(0,  (iframe.getParent().getHeight() - h)/2), 750, h);
+    int width = Math.max(splashText.getWidth(), iconimg.getWidth());
+    int height = splashText.getHeight() + iconimg.getHeight();
+    iframe.setBounds((iframe.getParent().getWidth() - width) / 2,
+            (iframe.getParent().getHeight() - height) / 2, 750,
+            width,height);
     iframe.validate();
     iframe.setVisible(true);
     return true;
@@ -278,9 +318,10 @@ public class SplashScreen extends JPanel
     @Override
     public void paintComponent(Graphics g)
     {
-      g.setColor(Color.white);
+      g.setColor(bg);
       g.fillRect(0, 0, getWidth(), getHeight());
-      g.setColor(Color.black);
+      g.setColor(fg);
+      g.setFont(new Font(font.getFontName(), Font.BOLD, FONT_SIZE + 6));
 
       if (image != null)
       {