JAL-1183 dialog queue
[jalview.git] / src / jalview / gui / Desktop.java
index b8c224d..712c9ce 100644 (file)
@@ -64,6 +64,8 @@ import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.StringTokenizer;
 import java.util.Vector;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import javax.swing.DefaultDesktopManager;
 import javax.swing.DesktopManager;
@@ -80,8 +82,10 @@ import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JProgressBar;
 import javax.swing.SwingUtilities;
+import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
+import javax.swing.event.HyperlinkEvent.EventType;
 
 /**
  * Jalview Desktop
@@ -1036,6 +1040,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
       
     }
+    if (dialogExecutor!=null)
+    {
+      dialogExecutor.shutdownNow();
+    }
       
     System.exit(0);
   }
@@ -1060,28 +1068,36 @@ public class Desktop extends jalview.jbgui.GDesktop implements
    */
   public void aboutMenuItem_actionPerformed(ActionEvent e)
   {
-    StringBuffer message = getAboutMessage(false);
-    JOptionPane.showInternalMessageDialog(Desktop.desktop,
-
-    message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
+//    StringBuffer message = getAboutMessage(false);
+//    JOptionPane.showInternalMessageDialog(Desktop.desktop,
+//
+//    message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
+    new Thread(new Runnable() { public void run() {new SplashScreen(true);}}).start();
   }
+
   public StringBuffer getAboutMessage(boolean shortv)
   {
-    StringBuffer message=new StringBuffer();
+    StringBuffer message = new StringBuffer();
     message.append("<html>");
     if (shortv)
-    { 
-      message.append("<h1><strong>Jalview "
-              + jalview.bin.Cache.getProperty("VERSION") + "</strong></h1><br>");
-      message.append("<strong>Last Updated: <em>"+jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")+"</em></strong>");
-      
-    } else {
-      
-    message.append("<strong>Jalview version "
-            + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
-            + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
+    {
+      message.append("<h1><strong>Version: "
+              + jalview.bin.Cache.getProperty("VERSION")
+              + "</strong></h1><br>");
+      message.append("<strong>Last Updated: <em>"
+              + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")
+              + "</em></strong>");
+
     }
-    
+    else
+    {
+
+      message.append("<strong>Version "
+              + jalview.bin.Cache.getProperty("VERSION")
+              + "; last updated: "
+              + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
+    }
+
     if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
             "Checking"))
     {
@@ -1090,27 +1106,34 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
             .equals(jalview.bin.Cache.getProperty("VERSION")))
     {
-      boolean red=false;
+      boolean red = false;
       if (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
               .indexOf("automated build") == -1)
       {
-        red=true;
+        red = true;
         // Displayed when code version and jnlp version do not match and code
         // version is not a development build
         message.append("<div style=\"color: #FF0000;font-style: bold;\">");
       }
-      
-      message.append("<br>!! Jalview version "
-                      + jalview.bin.Cache.getDefault("LATEST_VERSION",
-                              "..Checking..")
-                      + " is available for download from "+jalview.bin.Cache.getDefault("www.jalview.org","http://www.jalview.org")+" !!");
-      if (red) {
+
+      message.append("<br>!! Version "
+              + jalview.bin.Cache.getDefault("LATEST_VERSION",
+                      "..Checking..")
+              + " is available for download from "
+              + jalview.bin.Cache.getDefault("www.jalview.org",
+                      "http://www.jalview.org") + " !!");
+      if (red)
+      {
         message.append("</div>");
       }
-    }    
-    message.append("<br>Authors:  "+jalview.bin.Cache.getDefault("AUTHORNAMES","Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton")
+    }
+    message.append("<br>Authors:  "
+            + jalview.bin.Cache
+                    .getDefault(
+                            "AUTHORNAMES",
+                            "Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton")
             + "<br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
-            + "<br>For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list"
+            + "<br>For help, see the FAQ at <a href=\"http://www.jalview.org\">www.jalview.org</a> and/or join the jalview-discuss@jalview.org mailing list"
             + "<br>If  you use Jalview, please cite:"
             + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
             + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
@@ -2314,6 +2337,20 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   }
 
   /**
+   * 
+   * @return true if any progress bars are still active
+   */
+  @Override
+  public boolean operationInProgress()
+  {
+    if (progressBars != null && progressBars.size() > 0)
+    {
+      return true;
+    }
+    return false;
+  }
+
+  /**
    * This will return the first AlignFrame viewing AlignViewport av. It will
    * break if there are more than one AlignFrames viewing a particular av. This
    * 
@@ -2546,5 +2583,49 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     return wsparamManager;
   }
 
+  /**
+   * static hyperlink handler proxy method for use by Jalview's internal windows 
+   * @param e
+   */
+  public static void hyperlinkUpdate(HyperlinkEvent e)
+  {
+    if (e.getEventType() == EventType.ACTIVATED)
+    {
+      String url=null;
+      try
+      {
+        url = e.getURL().toString();
+        Desktop.showUrl(url);
+      } catch (Exception x)
+      {
+        if (url!=null) { 
+          if (Cache.log!=null) { 
+            Cache.log.error("Couldn't handle string "+url+" as a URL.");
+          } else {
+            System.err.println("Couldn't handle string "+url+" as a URL.");
+          }
+        }
+        // ignore any exceptions due to dud links.
+      }
+
+    }    
+  }
+  /**
+   * single thread that handles display of dialogs to user.
+   */
+  ExecutorService dialogExecutor=null;
+  
+  /**
+   * add another dialog thread to the queue
+   * @param prompter
+   */
+  public synchronized void addDialogThread(Runnable prompter)
+  {
+    if (dialogExecutor==null)
+    {
+      dialogExecutor = Executors.newSingleThreadExecutor();
+    }
+    dialogExecutor.submit(prompter);
+  }
 
 }