JAL-1183 dialog thread is only started after the splashscreen goes away
authorjprocter <jprocter@compbio.dundee.ac.uk>
Mon, 1 Oct 2012 11:15:10 +0000 (12:15 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Mon, 1 Oct 2012 11:15:10 +0000 (12:15 +0100)
src/jalview/gui/Desktop.java
src/jalview/gui/SplashScreen.java

index 50f0095..d357e4f 100644 (file)
@@ -67,6 +67,7 @@ import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Semaphore;
 
 import javax.swing.DefaultDesktopManager;
 import javax.swing.DesktopManager;
@@ -2618,6 +2619,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements
    * single thread that handles display of dialogs to user.
    */
   ExecutorService dialogExecutor=Executors.newSingleThreadExecutor();
+  /**
+   * flag indicating if dialogExecutor should try to acquire a permit
+   */
+  private volatile boolean dialogPause=true;
+  /**
+   * pause the queue 
+   */
+  private java.util.concurrent.Semaphore block=new Semaphore(0);
   
   /**
    * add another dialog thread to the queue
@@ -2629,6 +2638,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     {
       public void run()
       {
+        if (dialogPause) {
+          try { block.acquire(); } catch (InterruptedException x){};
+        }
+        if (instance==null)
+        {
+          return;
+        }
         try
         {
           SwingUtilities.invokeAndWait(prompter);
@@ -2640,4 +2656,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     });
   }
 
+  public void startDialogQueue()
+  {
+    // set the flag so we don't pause waiting for another permit and semaphore the current task to begin
+    dialogPause=false;
+    block.release();
+  }
 }
index 15914df..6fcb6a0 100755 (executable)
@@ -197,6 +197,7 @@ public class SplashScreen extends JPanel implements Runnable, HyperlinkListener
     }
 
     closeSplash();
+    Desktop.instance.startDialogQueue();
   }
 
   /**