JAL-1645 source formatting and organise imports
[jalview.git] / src / jalview / ws / jws2 / SequenceAnnotationWSClient.java
index 77ba300..187540c 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -21,7 +21,6 @@
 package jalview.ws.jws2;
 
 import jalview.api.AlignCalcWorkerI;
-import jalview.bin.Cache;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvSwingUtils;
@@ -35,12 +34,8 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.List;
 
-import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
 
 /**
  * @author jprocter
@@ -88,7 +83,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
 
       List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
               .getCalcManager().getRegisteredWorkersOfClass(clientClass);
-      JabawsAlignCalcWorker worker;
+      AbstractJabaCalcWorker worker;
       if (clnts == null || clnts.size() == 0)
       {
         if (!processParams(sh, editParams))
@@ -97,16 +92,16 @@ public class SequenceAnnotationWSClient extends Jws2Client
         }
         try
         {
-          worker = (JabawsAlignCalcWorker) (clientClass
-                  .getConstructor(new Class[]
-                  { Jws2Instance.class, AlignFrame.class,
-                      WsParamSetI.class, List.class })
-                  .newInstance(new Object[]
-                  { sh, alignFrame, this.preset, paramset }));
+          worker = (AbstractJabaCalcWorker) (clientClass
+                  .getConstructor(new Class[] { Jws2Instance.class,
+                      AlignFrame.class, WsParamSetI.class, List.class })
+                  .newInstance(new Object[] { sh, alignFrame, this.preset,
+                      paramset }));
         } catch (Exception x)
         {
           x.printStackTrace();
-          throw new Error("Implementation error", x);
+          throw new Error(
+                  MessageManager.getString("error.implementation_error"), x);
         }
         alignFrame.getViewport().getCalcManager().registerWorker(worker);
         alignFrame.getViewport().getCalcManager().startWorker(worker);
@@ -114,7 +109,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
       }
       else
       {
-        worker = (JabawsAlignCalcWorker) clnts.get(0);
+        worker = (AbstractJabaCalcWorker) clnts.get(0);
         if (editParams)
         {
           paramset = worker.getArguments();
@@ -176,8 +171,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
             service.serviceType.length() - 2);
 
     JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage(
-            "label.calcname_with_default_settings", new String[]
-            { calcName }));
+            "label.calcname_with_default_settings",
+            new String[] { calcName }));
     annotservice.addActionListener(new ActionListener()
     {
 
@@ -209,16 +204,20 @@ public class SequenceAnnotationWSClient extends Jws2Client
       List<WsParamSetI> presets = service.getParamStore().getPresets();
       if (presets != null && presets.size() > 0)
       {
-        JMenu presetlist = new JMenu("Run " + calcName + "with preset");
+        JMenu presetlist = new JMenu(MessageManager.formatMessage(
+                "label.run_with_preset", new String[] { calcName }));
 
         for (final WsParamSetI preset : presets)
         {
           final JMenuItem methodR = new JMenuItem(preset.getName());
-          methodR.setToolTipText("<html><p>"
-                  + JvSwingUtils.wrapTooltip("<strong>"
-                          + (preset.isModifiable() ? "User Preset"
-                                  : "Service Preset") + "</strong><br/>"
-                          + preset.getDescription() + "</p>") + "</html>");
+          methodR.setToolTipText(JvSwingUtils.wrapTooltip(
+                  true,
+                  "<strong>"
+                          + (preset.isModifiable() ? MessageManager
+                                  .getString("label.user_preset")
+                                  : MessageManager
+                                          .getString("label.service_preset"))
+                          + "</strong><br/>" + preset.getDescription()));
           methodR.addActionListener(new ActionListener()
           {
             public void actionPerformed(ActionEvent e)
@@ -249,258 +248,11 @@ public class SequenceAnnotationWSClient extends Jws2Client
             Desktop.instance.showUrl(service.docUrl);
           }
         });
-        annotservice.setToolTipText("<html>"
-                + JvSwingUtils.wrapTooltip("View <a href=\""
-                        + service.docUrl + "\">" + service.docUrl + "</a>")
-                + "</html>");
+        annotservice.setToolTipText(JvSwingUtils.wrapTooltip(true,
+                MessageManager.formatMessage("label.view_service_doc_url",
+                        new String[] { service.docUrl, service.docUrl })));
         wsmenu.add(annotservice);
       }
     }
   }
-
-  private boolean registerAAConWSInstance(final JMenu wsmenu,
-          final Jws2Instance service, final AlignFrame alignFrame)
-  {
-    final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
-                                                                   // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
-    if (aaui == null)
-    {
-      // not an instantaneous calculation GUI type service
-      return false;
-    }
-    // create the instaneous calculation GUI bits and update state if existing
-    // GUI elements already present
-
-    JCheckBoxMenuItem _aaConEnabled = null;
-    for (int i = 0; i < wsmenu.getItemCount(); i++)
-    {
-      JMenuItem item = wsmenu.getItem(i);
-      if (item instanceof JCheckBoxMenuItem
-              && item.getText().equals(aaui.getAAconToggle()))
-      {
-        _aaConEnabled = (JCheckBoxMenuItem) item;
-      }
-    }
-    // is there an aaCon worker already present - if so, set it to use the
-    // given service handle
-    {
-      List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
-              .getCalcManager()
-              .getRegisteredWorkersOfClass(aaui.getClient());
-      if (aaconClient != null && aaconClient.size() > 0)
-      {
-        JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient
-                .get(0);
-        if (!worker.service.hosturl.equals(service.hosturl))
-        {
-          // javax.swing.SwingUtilities.invokeLater(new Runnable()
-          {
-            // @Override
-            // public void run()
-            {
-              removeCurrentAAConWorkerFor(aaui, alignFrame);
-              buildCurrentAAConWorkerFor(aaui, alignFrame, service);
-            }
-          }// );
-        }
-      }
-    }
-
-    // is there a service already registered ? there shouldn't be if we are
-    // being called correctly
-    if (_aaConEnabled == null)
-    {
-      final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
-              aaui.getAAconToggle());
-
-      aaConEnabled.setToolTipText("<html><p>"
-              + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip()
-                      + "</p>") + "</html>");
-      aaConEnabled.addActionListener(new ActionListener()
-      {
-        @Override
-        public void actionPerformed(ActionEvent arg0)
-        {
-          List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
-                  .getCalcManager()
-                  .getRegisteredWorkersOfClass(aaui.getClient());
-          if (aaconClient != null && aaconClient.size() > 0)
-          {
-            removeCurrentAAConWorkerFor(aaui, alignFrame);
-          }
-          else
-          {
-            buildCurrentAAConWorkerFor(aaui, alignFrame);
-
-          }
-        }
-
-      });
-      wsmenu.add(aaConEnabled);
-      final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
-      modifyParams.setToolTipText("<html><p>"
-              + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip()
-                      + "</p>") + "</html>");
-      modifyParams.addActionListener(new ActionListener()
-      {
-
-        @Override
-        public void actionPerformed(ActionEvent arg0)
-        {
-          showAAConAnnotationSettingsFor(aaui, alignFrame);
-        }
-      });
-      wsmenu.add(modifyParams);
-      wsmenu.addMenuListener(new MenuListener()
-      {
-
-        @Override
-        public void menuSelected(MenuEvent arg0)
-        {
-          // TODO: refactor to the implementing class.
-          if (alignFrame.getViewport().getAlignment().isNucleotide() ? aaui
-                  .isNa() : aaui.isPr())
-          {
-            aaConEnabled.setEnabled(true);
-            modifyParams.setEnabled(true);
-          }
-          else
-          {
-            aaConEnabled.setEnabled(false);
-            modifyParams.setEnabled(false);
-          }
-          List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
-                  .getCalcManager()
-                  .getRegisteredWorkersOfClass(aaui.getClient());
-          if (aaconClient != null && aaconClient.size() > 0)
-          {
-            aaConEnabled.setSelected(true);
-          }
-          else
-          {
-            aaConEnabled.setSelected(false);
-          }
-        }
-
-        @Override
-        public void menuDeselected(MenuEvent arg0)
-        {
-          // TODO Auto-generated method stub
-
-        }
-
-        @Override
-        public void menuCanceled(MenuEvent arg0)
-        {
-          // TODO Auto-generated method stub
-
-        }
-      });
-
-    }
-    return true;
-  }
-
-  private static void showAAConAnnotationSettingsFor(
-          final AlignAnalysisUIText aaui, AlignFrame alignFrame)
-  {
-    /*
-     * preferred settings Whether AACon is automatically recalculated Which
-     * AACon server to use What parameters to use
-     */
-    // could actually do a class search for this too
-    AAConSettings fave = (AAConSettings) alignFrame.getViewport()
-            .getCalcIdSettingsFor(aaui.getCalcId());
-    if (fave == null)
-    {
-      fave = createDefaultAAConSettings(aaui);
-    }
-    new SequenceAnnotationWSClient(fave, alignFrame, true);
-
-  }
-
-  private static void buildCurrentAAConWorkerFor(
-          final AlignAnalysisUIText aaui, AlignFrame alignFrame)
-  {
-    buildCurrentAAConWorkerFor(aaui, alignFrame, null);
-  }
-
-  private static void buildCurrentAAConWorkerFor(
-          final AlignAnalysisUIText aaui, AlignFrame alignFrame,
-          Jws2Instance service)
-  {
-    /*
-     * preferred settings Whether AACon is automatically recalculated Which
-     * AACon server to use What parameters to use
-     */
-    AAConSettings fave = (AAConSettings) alignFrame.getViewport()
-            .getCalcIdSettingsFor(aaui.getCalcId());
-    if (fave == null)
-    {
-      fave = createDefaultAAConSettings(aaui, service);
-    }
-    else
-    {
-      if (service != null
-              && !fave.getService().hosturl.equals(service.hosturl))
-      {
-        Cache.log.debug("Changing AACon service to " + service.hosturl
-                + " from " + fave.getService().hosturl);
-        fave.setService(service);
-      }
-    }
-    new SequenceAnnotationWSClient(fave, alignFrame, false);
-  }
-
-  private static AAConSettings createDefaultAAConSettings(
-          AlignAnalysisUIText aaui)
-  {
-    return createDefaultAAConSettings(aaui, null);
-  }
-
-  private static AAConSettings createDefaultAAConSettings(
-          AlignAnalysisUIText aaui, Jws2Instance service)
-  {
-    if (service != null)
-    {
-      if (!service.serviceType.toString().equals(
-              compbio.ws.client.Services.AAConWS.toString()))
-      {
-        Cache.log
-                .warn("Ignoring invalid preferred service for AACon calculations (service type was "
-                        + service.serviceType + ")");
-        service = null;
-      }
-      else
-      {
-        // check service is actually in the list of currently avaialable
-        // services
-        if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
-        {
-          // it isn't ..
-          service = null;
-        }
-      }
-    }
-    if (service == null)
-    {
-      // get the default service for AACon
-      service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
-              aaui.getServiceType());
-    }
-    if (service == null)
-    {
-      // TODO raise dialog box explaining error, and/or open the JABA
-      // preferences menu.
-      throw new Error("No AACon service found.");
-    }
-    return new AAConSettings(true, service, null, null);
-  }
-
-  private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
-          AlignFrame alignFrame)
-  {
-    alignFrame.getViewport().getCalcManager()
-            .removeRegisteredWorkersOfClass(aaui.getClient());
-  }
 }