JAL-2629 method refactor and menu tidying
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 May 2018 13:02:34 +0000 (14:02 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 May 2018 13:02:34 +0000 (14:02 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/hmmer/HMMSearch.java
src/jalview/jbgui/GAlignFrame.java

index 3f74327..be765ec 100644 (file)
@@ -5796,22 +5796,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
-  public void hmmerMenu_actionPerformed(ActionEvent e)
-  {
-    SequenceGroup grp = getViewport().getSelectionGroup();
-    if (grp != null)
-    {
-      hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from "
-              + grp.getName());
-    }
-    else
-    {
-      hmmBuild.setText(MessageManager.getString("label.hmmbuild")
-              + " from Alignment");
-    }
-  }
-
-  @Override
   protected void loadVcf_actionPerformed()
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
index 4c5bfb3..a58b949 100644 (file)
@@ -160,6 +160,25 @@ public class HMMSearch extends HmmerCommand
 
     List<String> args = new ArrayList<>();
     args.add(command);
+    buildArguments(args, searchOutputFile, hitsAlignmentFile, hmmFile);
+
+    return runCommand(args);
+  }
+
+  /**
+   * Appends command line arguments to the given list, to specify input and
+   * output files for the search, and any additional options that may have been
+   * passed from the parameters dialog
+   * 
+   * @param args
+   * @param searchOutputFile
+   * @param hitsAlignmentFile
+   * @param hmmFile
+   * @throws IOException
+   */
+  protected void buildArguments(List<String> args, File searchOutputFile,
+          File hitsAlignmentFile, File hmmFile) throws IOException
+  {
     args.add("-o");
     args.add(getFilePath(searchOutputFile));
     args.add("-A");
@@ -282,8 +301,6 @@ public class HMMSearch extends HmmerCommand
 
     args.add(getFilePath(hmmFile));
     args.add(getFilePath(databaseFile));
-
-    return runCommand(args);
   }
 
   /**
index 8226cee..bc71566 100755 (executable)
@@ -72,26 +72,6 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu hmmerMenu = new JMenu();
 
-  protected JMenu hmmAlign = new JMenu();
-
-  protected JMenuItem hmmAlignRun = new JMenuItem();
-
-  protected JMenuItem hmmAlignSettings = new JMenuItem();
-
-  protected JMenu hmmSearch = new JMenu();
-
-  protected JMenuItem hmmSearchRun = new JMenuItem();
-
-  protected JMenuItem hmmSearchSettings = new JMenuItem();
-
-  protected JMenuItem addDatabase = new JMenuItem();
-
-  protected JMenu hmmBuild = new JMenu();
-
-  protected JMenuItem hmmBuildRun = new JMenuItem();
-
-  protected JMenuItem hmmBuildSettings = new JMenuItem();
-
   protected JMenuItem webServiceNoServices;
 
   protected JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
@@ -280,7 +260,6 @@ public class GAlignFrame extends JInternalFrame
   private void jbInit() throws Exception
   {
     initColourMenu();
-    initHMMERMenu();
   
     JMenuItem saveAs = new JMenuItem(
             MessageManager.getString("action.save_as"));
@@ -322,19 +301,8 @@ public class GAlignFrame extends JInternalFrame
     JMenu calculateMenu = new JMenu(
             MessageManager.getString("action.calculate"));
     webService.setText(MessageManager.getString("action.web_service"));
-    hmmerMenu.setText(MessageManager.getString("action.hmmer"));
-    hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
-    hmmerMenu.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmerMenu_actionPerformed(e);
-      }
-    });
-    hmmerMenu.add(hmmBuild);
-    hmmerMenu.add(hmmAlign);
-    hmmerMenu.add(hmmSearch);
+
+    initHMMERMenu();
 
     JMenuItem selectAllSequenceMenuItem = new JMenuItem(
             MessageManager.getString("action.select_all"));
@@ -1757,81 +1725,6 @@ public class GAlignFrame extends JInternalFrame
         selectHighlightedColumns_actionPerformed(actionEvent);
       }
     };
-    hmmBuildRun.setText(MessageManager.formatMessage(
-            "label.action_with_default_settings", "hmmbuild"));
-    hmmBuildRun.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmBuild_actionPerformed(true);
-      }
-    });
-    hmmBuildSettings.setText(
-            MessageManager.getString("label.edit_settings_and_run"));
-    hmmBuildSettings.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmBuild_actionPerformed(false);
-      }
-    });
-    hmmAlignRun.setText(MessageManager.formatMessage(
-            "label.action_with_default_settings", "hmmalign"));
-    hmmAlignRun.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmAlign_actionPerformed(true);
-      }
-    });
-    hmmAlignSettings.setText(
-            MessageManager.getString("label.edit_settings_and_run"));
-    hmmAlignSettings.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmAlign_actionPerformed(false);
-      }
-    });
-    hmmSearchRun.setText(MessageManager.formatMessage(
-            "label.action_with_default_settings", "hmmsearch"));
-    hmmSearchRun.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmSearch_actionPerformed(true);
-      }
-    });
-    hmmSearchSettings.setText(
-            MessageManager.getString("label.edit_settings_and_run"));
-    hmmSearchSettings.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmSearch_actionPerformed(false);
-      }
-    });
-    addDatabase.setText(MessageManager.getString("label.add_database"));
-    addDatabase.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        try
-        {
-          addDatabase_actionPerformed();
-        } catch (IOException e1)
-        {
-          e1.printStackTrace();
-        }
-      }
-    });
     selectHighlighted.addActionListener(al);
     JMenu tooltipSettingsMenu = new JMenu(
             MessageManager.getString("label.sequence_id_tooltip"));
@@ -2014,40 +1907,119 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
-  public void hmmerMenu_actionPerformed(ActionEvent e)
-  {
-
-  }
-
   /**
-   * Constructs the entries on the HMMER menu (does not add them to the menu).
+   * Constructs the entries on the HMMER menu
    */
   protected void initHMMERMenu()
   {
-    hmmAlign = new JMenu(MessageManager.getString("label.hmmalign"));
-    hmmAlignSettings = new JMenuItem(
-            MessageManager.getString("label.edit_settings_and_run"));
-    hmmAlignRun = new JMenuItem(MessageManager.formatMessage(
-            "label.action_with_default_settings", "hmmalign"));
-    hmmAlign.add(hmmAlignSettings);
-    hmmAlign.add(hmmAlignRun);
-    hmmBuild = new JMenu(MessageManager.getString("label.hmmbuild"));
-    hmmBuildSettings = new JMenuItem(
+    /*
+     * hmmbuild
+     */
+    JMenu hmmBuild = new JMenu(MessageManager.getString("label.hmmbuild"));
+    JMenuItem hmmBuildSettings = new JMenuItem(
             MessageManager.getString("label.edit_settings_and_run"));
-    hmmBuildRun = new JMenuItem(MessageManager.formatMessage(
+    hmmBuildSettings.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmBuild_actionPerformed(false);
+      }
+    });
+    JMenuItem hmmBuildRun = new JMenuItem(MessageManager.formatMessage(
             "label.action_with_default_settings", "hmmbuild"));
-    hmmBuild.add(hmmBuildSettings);
+    hmmBuildRun.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmBuild_actionPerformed(true);
+      }
+    });
     hmmBuild.add(hmmBuildRun);
-    hmmSearch = new JMenu(MessageManager.getString("label.hmmsearch"));
-    hmmSearchSettings = new JMenuItem(
+    hmmBuild.add(hmmBuildSettings);
+
+    /*
+     * hmmalign
+     */
+    JMenu hmmAlign = new JMenu(MessageManager.getString("label.hmmalign"));
+    JMenuItem hmmAlignRun = new JMenuItem(MessageManager.formatMessage(
+            "label.action_with_default_settings", "hmmalign"));
+    hmmAlignRun.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmAlign_actionPerformed(true);
+      }
+    });
+    JMenuItem hmmAlignSettings = new JMenuItem(
+            MessageManager.getString("label.edit_settings_and_run"));
+    hmmAlignSettings.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmAlign_actionPerformed(false);
+      }
+    });
+    hmmAlign.add(hmmAlignRun);
+    hmmAlign.add(hmmAlignSettings);
+
+    /*
+     * hmmsearch
+     */
+    JMenu hmmSearch = new JMenu(
+            MessageManager.getString("label.hmmsearch"));
+    JMenuItem hmmSearchSettings = new JMenuItem(
             MessageManager.getString("label.edit_settings_and_run"));
-    hmmSearchRun = new JMenuItem(MessageManager.formatMessage(
+    hmmSearchSettings.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmSearch_actionPerformed(false);
+      }
+    });
+    JMenuItem hmmSearchRun = new JMenuItem(MessageManager.formatMessage(
             "label.action_with_default_settings", "hmmsearch"));
-    addDatabase = new JMenuItem(
+    hmmSearchRun.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmSearch_actionPerformed(true);
+      }
+    });
+    JMenuItem addDatabase = new JMenuItem(
             MessageManager.getString("label.add_database"));
+    addDatabase.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        try
+        {
+          addDatabase_actionPerformed();
+        } catch (IOException e1)
+        {
+          e1.printStackTrace();
+        }
+      }
+    });
     hmmSearch.add(hmmSearchSettings);
     hmmSearch.add(hmmSearchRun);
     hmmSearch.add(addDatabase);
+
+    /*
+     * top level menu
+     */
+    hmmerMenu.setText(MessageManager.getString("action.hmmer"));
+    hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
+    hmmerMenu.add(hmmBuild);
+    hmmerMenu.add(hmmAlign);
+    hmmerMenu.add(hmmSearch);
+
   }
 
   protected void loadVcf_actionPerformed()