threaded off ws menu building to avoid initial pause when services are discovered
authorjprocter <Jim Procter>
Fri, 10 Sep 2010 16:22:52 +0000 (16:22 +0000)
committerjprocter <Jim Procter>
Fri, 10 Sep 2010 16:22:52 +0000 (16:22 +0000)
src/jalview/gui/AlignFrame.java

index b0d30a2..ca4b880 100755 (executable)
@@ -550,9 +550,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       };
     });
     // Finally, build the menu once to get current service state
-    javax.swing.SwingUtilities.invokeLater(new Runnable() {
-    public void run() { BuildWebServiceMenu();}
-    });
+    new Thread(new Runnable()
+    {
+      public void run()
+      {
+        BuildWebServiceMenu();
+      }
+    }).start();
   }
 
   public void setGUINucleotide(boolean nucleotide)
@@ -695,8 +699,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         public void actionPerformed(ActionEvent e)
         {
           handler.cancelActivity(id);
-          us.setProgressBar("Cancelled "
-                  + ((JLabel) progressPanel.getComponent(0)).getText(), id);
+          us.setProgressBar(
+                  "Cancelled "
+                          + ((JLabel) progressPanel.getComponent(0))
+                                  .getText(), id);
         }
       });
       progressPanel.add(cancel, BorderLayout.EAST);
@@ -834,8 +840,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void saveAs_actionPerformed(ActionEvent e)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-            .getProperty("LAST_DIRECTORY"),
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
             jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
             jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
             currentFileFormat, false);
@@ -1006,14 +1012,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     cap.setForInput(null);
 
-    try {
+    try
+    {
       cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
-            viewport.alignment, omitHidden, viewport.colSel));
-    Desktop.addInternalFrame(cap, "Alignment output - "
-            + e.getActionCommand(), 600, 500);
+              viewport.alignment, omitHidden, viewport.colSel));
+      Desktop.addInternalFrame(cap,
+              "Alignment output - " + e.getActionCommand(), 600, 500);
     } catch (OutOfMemoryError oom)
     {
-      new OOMWarning("Outputting alignment as "+e.getActionCommand(),oom);
+      new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
       cap.dispose();
     }
 
@@ -1027,9 +1034,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   protected void htmlMenuItem_actionPerformed(ActionEvent e)
   {
-    new HTMLOutput(alignPanel, alignPanel.seqPanel.seqCanvas
-            .getSequenceRenderer(), alignPanel.seqPanel.seqCanvas
-            .getFeatureRenderer());
+    new HTMLOutput(alignPanel,
+            alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
+            alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
   }
 
   public void createImageMap(File file, String image)
@@ -1085,7 +1092,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   public void exportAnnotations_actionPerformed(ActionEvent e)
   {
-    new AnnotationExporter().exportAnnotations(alignPanel,
+    new AnnotationExporter().exportAnnotations(
+            alignPanel,
             viewport.showAnnotation ? viewport.alignment
                     .getAlignmentAnnotation() : null, viewport.alignment
                     .getGroups(),
@@ -1095,8 +1103,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void associatedData_actionPerformed(ActionEvent e)
   {
     // Pick the tree file
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-            .getProperty("LAST_DIRECTORY"));
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle("Load Jalview Annotations or Features File");
     chooser.setToolTipText("Load Jalview Annotations / Features file");
@@ -1536,11 +1544,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       jalview.gui.Desktop.internalCopy = true;
       // Its really worth setting the clipboard contents
       // to empty before setting the large StringSelection!!
-      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
-              new StringSelection(""), null);
+      Toolkit.getDefaultToolkit().getSystemClipboard()
+              .setContents(new StringSelection(""), null);
 
-      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
-              Desktop.instance);
+      Toolkit.getDefaultToolkit().getSystemClipboard()
+              .setContents(ss, Desktop.instance);
     } catch (OutOfMemoryError er)
     {
       new OOMWarning("copying region", er);
@@ -1803,8 +1811,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           buildSortByAnnotationScoresMenu();
         }
-        viewport.firePropertyChange("alignment", null, alignment
-                .getSequences());
+        viewport.firePropertyChange("alignment", null,
+                alignment.getSequences());
 
       }
       else
@@ -2701,8 +2709,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           pos = npos + 1;
         } while (npos != -1);
-        contents
-                .append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
+        contents.append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
       }
       contents.append("</table>");
     }
@@ -2730,19 +2737,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     JInternalFrame frame = new JInternalFrame();
     OverviewPanel overview = new OverviewPanel(alignPanel);
     frame.setContentPane(overview);
-    Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), frame
-            .getWidth(), frame.getHeight());
+    Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
+            frame.getWidth(), frame.getHeight());
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
-    frame
-            .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
-            {
-              public void internalFrameClosed(
-                      javax.swing.event.InternalFrameEvent evt)
-              {
-                alignPanel.setOverviewPanel(null);
-              };
-            });
+    frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+    {
+      public void internalFrameClosed(
+              javax.swing.event.InternalFrameEvent evt)
+      {
+        alignPanel.setOverviewPanel(null);
+      };
+    });
 
     alignPanel.setOverviewPanel(overview);
   }
@@ -2772,8 +2778,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void clustalColour_actionPerformed(ActionEvent e)
   {
     changeColour(new ClustalxColourScheme(
-            viewport.alignment.getSequences(), viewport.alignment
-                    .getWidth()));
+            viewport.alignment.getSequences(),
+            viewport.alignment.getWidth()));
   }
 
   /**
@@ -2911,8 +2917,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         Alignment al = (Alignment) viewport.alignment;
         Conservation c = new Conservation("All",
-                ResidueProperties.propHash, 3, al.getSequences(), 0, al
-                        .getWidth() - 1);
+                ResidueProperties.propHash, 3, al.getSequences(), 0,
+                al.getWidth() - 1);
 
         c.calculate();
         c.verdict(false, viewport.ConsPercGaps);
@@ -2948,8 +2954,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         if (cs instanceof ClustalxColourScheme)
         {
-          sg.cs = new ClustalxColourScheme(sg
-                  .getSequences(viewport.hiddenRepSequences), sg.getWidth());
+          sg.cs = new ClustalxColourScheme(
+                  sg.getSequences(viewport.hiddenRepSequences),
+                  sg.getWidth());
         }
         else if (cs instanceof UserColourScheme)
         {
@@ -2971,9 +2978,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
 
-          sg.cs.setConsensus(AAFrequency.calculate(sg
-                  .getSequences(viewport.hiddenRepSequences), sg
-                  .getStartRes(), sg.getEndRes() + 1));
+          sg.cs.setConsensus(AAFrequency.calculate(
+                  sg.getSequences(viewport.hiddenRepSequences),
+                  sg.getStartRes(), sg.getEndRes() + 1));
         }
         else
         {
@@ -2983,9 +2990,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         if (viewport.getConservationSelected())
         {
           Conservation c = new Conservation("Group",
-                  ResidueProperties.propHash, 3, sg
-                          .getSequences(viewport.hiddenRepSequences), sg
-                          .getStartRes(), sg.getEndRes() + 1);
+                  ResidueProperties.propHash, 3,
+                  sg.getSequences(viewport.hiddenRepSequences),
+                  sg.getStartRes(), sg.getEndRes() + 1);
           c.calculate();
           c.verdict(false, viewport.ConsPercGaps);
           sg.cs.setConservation(c);
@@ -3016,8 +3023,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (viewport.getAbovePIDThreshold()
             && viewport.globalColourScheme != null)
     {
-      SliderPanel.setPIDSliderSource(alignPanel, viewport
-              .getGlobalColourScheme(), "Background");
+      SliderPanel.setPIDSliderSource(alignPanel,
+              viewport.getGlobalColourScheme(), "Background");
       SliderPanel.showPIDSlider();
     }
   }
@@ -3127,8 +3134,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             if (evt.isControlDown()
                     || SwingUtilities.isRightMouseButton(evt))
             {
-              radioItem
-                      .removeActionListener(radioItem.getActionListeners()[0]);
+              radioItem.removeActionListener(radioItem.getActionListeners()[0]);
 
               int option = JOptionPane.showInternalConfirmDialog(
                       jalview.gui.Desktop.desktop,
@@ -3502,8 +3508,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       public void actionPerformed(ActionEvent e)
       {
         SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
-        AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport
-                .getAlignment());// ,viewport.getSelectionGroup());
+        AlignmentSorter.sortByAnnotationScore(scoreLabel,
+                viewport.getAlignment());// ,viewport.getSelectionGroup());
         addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
                 viewport.alignment));
         alignPanel.paintAlignment(true);
@@ -3551,8 +3557,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       Enumeration labels = scoreSorts.keys();
       while (labels.hasMoreElements())
       {
-        addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels
-                .nextElement());
+        addSortByAnnotScoreMenuItem(sortByAnnotScore,
+                (String) labels.nextElement());
       }
       sortByAnnotScore.setVisible(scoreSorts.size() > 0);
       scoreSorts.clear();
@@ -3707,8 +3713,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
   {
     // Pick the tree file
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-            .getProperty("LAST_DIRECTORY"));
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle("Select a newick-like tree file");
     chooser.setToolTipText("Load a tree file");
@@ -3732,8 +3738,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       if (fin != null && fin.hasWarningMessage())
       {
-        JOptionPane.showMessageDialog(Desktop.desktop, fin
-                .getWarningMessage(), "Possible problem with tree file",
+        JOptionPane.showMessageDialog(Desktop.desktop,
+                fin.getWarningMessage(), "Possible problem with tree file",
                 JOptionPane.WARNING_MESSAGE);
       }
     }
@@ -3825,7 +3831,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       ;
     }
+    final AlignFrame me = this;
     buildingMenu = true;
+    new Thread(new Runnable() {
+      public void run() {
     try
     {
       System.err
@@ -3838,8 +3847,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // TODO: add in rediscovery GUI function to restart discoverer
       // TODO: group services by location as well as function and/or introduce
       // object broker mechanism.
-      Vector wsmenu = new Vector();
-      final IProgressIndicator af = this;
+      final Vector wsmenu = new Vector();
+      final IProgressIndicator af = me;
       if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
               && Discoverer.services != null
               && (Discoverer.services.size() > 0))
@@ -3863,7 +3872,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     .get(i);
             jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
                     .getServiceClient(sh);
-            impl.attachWSMenuEntry(msawsmenu, this);
+            impl.attachWSMenuEntry(msawsmenu, me);
 
           }
           wsmenu.add(msawsmenu);
@@ -3879,7 +3888,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     .get(i);
             jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
                     .getServiceClient(sh);
-            impl.attachWSMenuEntry(secstrmenu, this);
+            impl.attachWSMenuEntry(secstrmenu, me);
           }
           wsmenu.add(secstrmenu);
         }
@@ -3893,7 +3902,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     .elementAt(i);
             jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
                     .getServiceClient(sh);
-            impl.attachWSMenuEntry(seqsrchmenu, this);
+            impl.attachWSMenuEntry(seqsrchmenu, me);
           }
           wsmenu.add(seqsrchmenu);
         }
@@ -3908,7 +3917,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           if (jws2servs.hasServices())
           {
             JMenu jws2men = new JMenu("Jalview 2 Services");
-            jws2servs.attachWSMenuEntry(jws2men, this);
+            jws2servs.attachWSMenuEntry(jws2men, me);
             for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
             {
               wsmenu.add(jws2men.getMenuComponent(i));
@@ -3916,6 +3925,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
         }
       }
+      
+        javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() {
+          try {
+            
       resetWebServiceMenu();
       // finally, add the whole shebang onto the webservices menu
       if (wsmenu.size() > 0)
@@ -3927,13 +3940,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       else
       {
-        this.webService.add(this.webServiceNoServices);
+        me.webService.add(me.webServiceNoServices);
       }
+          } catch (Exception e)
+          {
+          }
+          ;
+        }
+        });
     } catch (Exception e)
     {
     }
     ;
+        
     buildingMenu = false;
+      }}).start();
+    
   }
 
   /**
@@ -4044,8 +4066,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     } catch (Exception e)
     {
       jalview.bin.Cache.log
-              .warn(
-                      "canTranslate threw an exception - please report to help@jalview.org",
+              .warn("canTranslate threw an exception - please report to help@jalview.org",
                       e);
       return false;
     }
@@ -4135,13 +4156,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // old way
     try
     {
-      return (jalview.analysis.Dna.canTranslate(selection, viewport
-              .getViewAsVisibleContigs(true)));
+      return (jalview.analysis.Dna.canTranslate(selection,
+              viewport.getViewAsVisibleContigs(true)));
     } catch (Exception e)
     {
       jalview.bin.Cache.log
-              .warn(
-                      "canTranslate threw an exception - please report to help@jalview.org",
+              .warn("canTranslate threw an exception - please report to help@jalview.org",
                       e);
       return false;
     }
@@ -4230,9 +4250,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     boolean featuresFile = false;
     try
     {
-      featuresFile = new FeaturesFile(file, type).parse(viewport.alignment
-              .getDataset(), alignPanel.seqPanel.seqCanvas
-              .getFeatureRenderer().featureColours, false);
+      featuresFile = new FeaturesFile(file, type)
+              .parse(viewport.alignment.getDataset(),
+                      alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
+                      false);
     } catch (Exception ex)
     {
       ex.printStackTrace();
@@ -4372,8 +4393,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
           jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
                   protocol);
-          new JnetAnnotationMaker().add_annotation(predictions, viewport
-                  .getAlignment(), 0, false);
+          new JnetAnnotationMaker().add_annotation(predictions,
+                  viewport.getAlignment(), 0, false);
           isAnnotation = true;
         }
         else
@@ -4514,13 +4535,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     // preferences and have checkboxes.. rather than individual sources selected
     // here
     JMenu rfetch = new JMenu("Fetch DB References");
-    rfetch
-            .setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
+    rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
     webService.add(rfetch);
 
     JMenuItem fetchr = new JMenuItem("Standard Databases");
-    fetchr
-            .setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
+    fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
     fetchr.addActionListener(new ActionListener()
     {
 
@@ -4703,8 +4722,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (viewport.getSelectionGroup() != null)
     {
       SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
-              viewport.getSequenceSelection(), viewport.getAlignmentView(
-                      true).getSequenceStrings(viewport.getGapCharacter()),
+              viewport.getSequenceSelection(),
+              viewport.getAlignmentView(true).getSequenceStrings(
+                      viewport.getGapCharacter()),
               viewport.alignment.getGroups());
       viewport.alignment.deleteAllGroups();
       viewport.sequenceColours = null;
@@ -4715,8 +4735,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         gps[g].setShowNonconserved(viewport.getShowUnconserved());
         gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
         viewport.alignment.addGroup(gps[g]);
-        Color col = new Color((int) (Math.random() * 255), (int) (Math
-                .random() * 255), (int) (Math.random() * 255));
+        Color col = new Color((int) (Math.random() * 255),
+                (int) (Math.random() * 255), (int) (Math.random() * 255));
         col = col.brighter();
         for (Enumeration sq = gps[g].getSequences(null).elements(); sq
                 .hasMoreElements(); viewport.setSequenceColour(