JAL-4217 close internal frame on the swing thread to avoid deadlock
[jalview.git] / src / jalview / gui / SplashScreen.java
index 2d5e63b..465bc0d 100755 (executable)
@@ -36,6 +36,7 @@ import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 import javax.swing.JTextPane;
+import javax.swing.SwingUtilities;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
 
@@ -114,6 +115,10 @@ public class SplashScreen extends JPanel
   public SplashScreen(boolean isTransient)
   {
     this.transientDialog = isTransient;
+    if (this.transientDialog)
+    {
+      Desktop.instance.acquireDialogQueue();
+    }
 
     if (Platform.isJS()) // BH 2019
     {
@@ -171,7 +176,7 @@ public class SplashScreen extends JPanel
           }
           if (mt.isErrorAny())
           {
-            System.err.println("Error when loading images!");
+            jalview.bin.Console.errPrintln("Error when loading images!");
           }
         } while (!mt.checkAll());
         Desktop.instance.setIconImages(ChannelProperties.getIconList());
@@ -227,7 +232,8 @@ public class SplashScreen extends JPanel
   protected boolean refreshText()
   {
     String newtext = Desktop.instance.getAboutMessage();
-    // System.err.println("Text found: \n"+newtext+"\nEnd of newtext.");
+    // jalview.bin.Console.errPrintln("Text found: \n"+newtext+"\nEnd of
+    // newtext.");
     if (oldTextLength != newtext.length())
     {
       iframe.setVisible(false);
@@ -267,7 +273,7 @@ public class SplashScreen extends JPanel
 
       splashText.setVisible(true);
       splashText.setSize(new Dimension(750,
-              375 + logoSize + (Platform.isJS() ? 40 : 0)));
+              425 + logoSize + (Platform.isJS() ? 40 : 0)));
       splashText.setBackground(bg);
       splashText.setForeground(fg);
       splashText.setFont(font);
@@ -275,8 +281,10 @@ public class SplashScreen extends JPanel
       revalidate();
       int width = Math.max(splashText.getWidth(), iconimg.getWidth());
       int height = splashText.getHeight() + iconimg.getHeight();
-      iframe.setBounds((Desktop.instance.getWidth() - width) / 2,
-              (Desktop.instance.getHeight() - height) / 2, width, height);
+      iframe.setBounds(
+              Math.max(0, (Desktop.instance.getWidth() - width) / 2),
+              Math.max(0, (Desktop.instance.getHeight() - height) / 2),
+              width, height);
       iframe.validate();
       iframe.setVisible(true);
       return true;
@@ -321,7 +329,6 @@ public class SplashScreen extends JPanel
     }
 
     closeSplash();
-    Desktop.instance.startDialogQueue();
   }
 
   /**
@@ -329,10 +336,26 @@ public class SplashScreen extends JPanel
    */
   public void closeSplash()
   {
+    if (this.transientDialog)
+    {
+      Desktop.instance.releaseDialogQueue();
+    }
     try
     {
-
-      iframe.setClosed(true);
+      final JInternalFrame frme = iframe;
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          try
+          {
+            frme.setClosed(true);
+          } catch (Exception ex)
+          {
+          }
+        }
+      });
     } catch (Exception ex)
     {
     }