new SequenceFetcher gui and visual delay indication for initialisation and fetching
[jalview.git] / src / jalview / gui / Desktop.java
index ff01ed6..262a9be 100755 (executable)
@@ -19,6 +19,7 @@
 package jalview.gui;
 
 import jalview.io.*;
+
 import java.awt.*;
 import java.awt.datatransfer.*;
 import java.awt.dnd.*;
@@ -38,7 +39,7 @@ import javax.swing.event.MenuListener;
  */
 public class Desktop
     extends jalview.jbgui.GDesktop implements DropTargetListener,
-    ClipboardOwner
+    ClipboardOwner, IProgressIndicator
 {
   /** DOCUMENT ME!! */
   public static Desktop instance;
@@ -64,6 +65,11 @@ public class Desktop
    */
   public Desktop()
   {
+    /**
+     * A note to implementors. It is ESSENTIAL that any 
+     * activities that might block are spawned off as threads rather 
+     * than waited for during this constructor.
+     */
     instance = this;
     doVamsasClientCheck();
     doGroovyCheck();
@@ -121,10 +127,9 @@ public class Desktop
 
 
     this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
+    // Spawn a thread that shows the splashscreen
+    new SplashScreen();     
 
-    /////////Add a splashscreen on startup
-    /////////Add a splashscreen on startup
-    new SplashScreen();
 
 
     discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
@@ -825,7 +830,7 @@ public class Desktop
 
   public void inputSequence_actionPerformed(ActionEvent e)
   {
-    new SequenceFetcher(null);
+    new SequenceFetcher(this);
   }
 
   JPanel progressPanel;
@@ -1217,7 +1222,8 @@ public class Desktop
   public void checkForQuestionnaire(String url)
   {
     UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
-    javax.swing.SwingUtilities.invokeLater(jvq);
+    //javax.swing.SwingUtilities.invokeLater(jvq);
+    new Thread(jvq).start();
   }
   /**
    * Proxy class for JDesktopPane which optionally 
@@ -1385,4 +1391,27 @@ public class Desktop
               JOptionPane.ERROR_MESSAGE);
     }
   }
+
+  /**
+   *  Progress bars managed by the IProgressIndicator method.
+   */
+  private Hashtable progressBars;
+  /* (non-Javadoc)
+   * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
+   */
+  public void setProgressBar(String message, long id)
+  {
+    if(progressBars == null)
+    {
+      progressBars = new Hashtable();
+    }
+
+    if(progressBars.get( new Long(id) )!=null)
+    {
+      JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) );
+       removeProgressPanel(progressPanel);
+    } else {
+      progressBars.put(new Long(id), addProgressPanel(message));
+    }
+  }
 }