added SeqSearch service interface. Documented and refactored web service client ...
[jalview.git] / src / jalview / gui / AlignFrame.java
index 6e7b15d..39a7fac 100755 (executable)
@@ -68,6 +68,8 @@ public class AlignFrame
    */
   String fileName = null;
 
+  
+
 
   /**
    * Creates a new AlignFrame object.
@@ -531,6 +533,7 @@ public class AlignFrame
     conservationMenuItem.setSelected(av.getConservationSelected());
     seqLimits.setSelected(av.getShowJVSuffix());
     idRightAlign.setSelected(av.rightAlignIds);
+    centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
     renderGapsMenuItem.setSelected(av.renderGaps);
     wrapMenuItem.setSelected(av.wrapAlignment);
     scaleAbove.setVisible(av.wrapAlignment);
@@ -2187,6 +2190,12 @@ public class AlignFrame
     alignPanel.paintAlignment(true);
   }
 
+  public void centreColumnLabels_actionPerformed(ActionEvent e)
+  {
+    viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
+    alignPanel.paintAlignment(true);
+  }
+
 
 
   /**
@@ -3261,7 +3270,7 @@ public class AlignFrame
    * or just the selected set will be submitted for multiple alignment.
    *
    */
-  private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
+  public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
   {
     // Now, check we have enough sequences
     AlignmentView msa = null;
@@ -3299,12 +3308,14 @@ public class AlignFrame
   }
 
   /**
-   * Decides what is submitted to a secondary structure prediction service,
-   * the currently selected sequence, or the currently selected alignment
+   * Decides what is submitted to a secondary structure prediction service:
+   * the first sequence in the alignment, or in the current selection,
+   * or, if the alignment is 'aligned' (ie padded with gaps), then the
+   * currently selected region or the whole alignment.
    * (where the first sequence in the set is the one that the prediction
    * will be for).
    */
-  AlignmentView gatherSeqOrMsaForSecStrPrediction()
+  public AlignmentView gatherSeqOrMsaForSecStrPrediction()
   {
    AlignmentView seqs = null;
 
@@ -3454,6 +3465,7 @@ public class AlignFrame
       // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere
       Vector msaws = (Vector) Discoverer.services.get("MsaWS");
       Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
+      Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
       // TODO: move GUI generation code onto service implementation - so a client instance attaches itself to the GUI with method call like jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, alignframe)
       Vector wsmenu = new Vector();
       final AlignFrame af = this;
@@ -3465,43 +3477,9 @@ public class AlignFrame
         {
           final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
               get(i);
-          final JMenuItem method = new JMenuItem(sh.getName());
-          method.addActionListener(new ActionListener()
-          {
-            public void actionPerformed(ActionEvent e)
-            {
-              AlignmentView msa = gatherSequencesForAlignment();
-              new jalview.ws.MsaWSClient(sh, title, msa,
-                                         false, true,
-                                         viewport.getAlignment().getDataset(),
-                                         af);
-
-            }
-
-          });
-          msawsmenu.add(method);
-          // Deal with services that we know accept partial alignments.
-          // TODO: this should be a service property - ie sh.getProperty("submitGaps")==Boolean.true
-          if (sh.getName().indexOf("lustal") > -1)
-          {
-            // We know that ClustalWS can accept partial alignments for refinement.
-            final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
-            methodR.addActionListener(new ActionListener()
-            {
-              public void actionPerformed(ActionEvent e)
-              {
-                AlignmentView msa = gatherSequencesForAlignment();
-                new jalview.ws.MsaWSClient(sh, title, msa,
-                                           true, true,
-                                           viewport.getAlignment().getDataset(),
-                                           af);
-
-              }
-
-            });
-            msawsmenu.add(methodR);
-
-          }
+          jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
+          impl.attachWSMenuEntry(msawsmenu, this);
+        
         }
         wsmenu.add(msawsmenu);
       }
@@ -3513,32 +3491,25 @@ public class AlignFrame
         {
           final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
               secstrpr.get(i);
-          final JMenuItem method = new JMenuItem(sh.getName());
-          method.addActionListener(new ActionListener()
-          {
-            public void actionPerformed(ActionEvent e)
-            {
-              AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
-              if (msa.getSequences().length == 1)
-              {
-                // Single Sequence prediction
-                new jalview.ws.JPredClient(sh, title, false, msa, af, true);
-              }
-              else
-              {
-                if (msa.getSequences().length > 1)
-                {
-                  // Sequence profile based prediction
-                  new jalview.ws.JPredClient(sh,
-                      title, true, msa, af, true);
-                }
-              }
-            }
-          });
-          secstrmenu.add(method);
+          jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
+          impl.attachWSMenuEntry(secstrmenu, this);
         }
         wsmenu.add(secstrmenu);
       }
+      if (seqsrch!=null)
+      {
+        // Add any sequence search services
+        final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
+        for (int i = 0, j = seqsrch.size(); i < j; i++)
+        {
+          final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
+              seqsrch.elementAt(i);
+          jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh);
+          impl.attachWSMenuEntry(seqsrchmenu, this);
+        }
+        // finally, add the whole shebang onto the webservices menu
+        wsmenu.add(seqsrchmenu); 
+      }
       resetWebServiceMenu();
       for (int i = 0, j = wsmenu.size(); i < j; i++)
       {