JAL-2937 Cygwin path preference, method refactoring
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 358298d..6ff335e 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.fts.service.pdb.PDBFTSRestClient;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -284,6 +285,8 @@ public class GPreferences extends JPanel
 
   protected JTextField hmmerPath = new JTextField();
 
+  protected JTextField cygwinPath = new JTextField();
+
   /*
    * DAS Settings tab
    */
@@ -424,12 +427,19 @@ public class GPreferences extends JPanel
   private JPanel initHMMERTab()
   {
     hmmerTab.setLayout(null);
+    final int lineSpacing = 20;
 
-    JLabel installationLocation = new JLabel(
+    /*
+     * path to hmmer binaries folder
+     */
+    JLabel hmmerLocation = new JLabel(
             MessageManager.getString("label.hmmer_location"));
-    installationLocation.setFont(LABEL_FONT);
-    installationLocation.setBounds(new Rectangle(22, 10, 250, 23));
-    hmmerPath.setBounds(new Rectangle(22, 30, 300, 23));
+    hmmerLocation.setFont(LABEL_FONT);
+    int xPos = 22;
+    int yPos = 10;
+    hmmerLocation.setBounds(new Rectangle(xPos, yPos, 250, 23));
+    yPos += lineSpacing;
+    hmmerPath.setBounds(new Rectangle(xPos, yPos, 300, 23));
     hmmerPath.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -441,54 +451,96 @@ public class GPreferences extends JPanel
           if (chosen != null)
           {
             hmmerPath.setText(chosen);
+            validateHmmerPath();
           }
         }
       }
     });
+    hmmerTab.add(hmmerLocation);
+    hmmerTab.add(hmmerPath);
 
-    JLabel hmmalign = new JLabel(
-            MessageManager.getString("label.hmmalign_label"));
-    hmmalign.setFont(LABEL_FONT);
-    hmmalign.setBounds(new Rectangle(22, 50, 200, 23));
+    /*
+     * path to Cygwin binaries folder (for Windows)
+     */
+    if (Platform.isWindows())
+    {
+      JLabel cygwinLocation = new JLabel(
+              MessageManager.getString("label.cygwin_location"));
+      cygwinLocation.setFont(LABEL_FONT);
+      yPos += lineSpacing * 2;
+      cygwinLocation.setBounds(new Rectangle(xPos, yPos, 250, 23));
+      yPos += lineSpacing;
+      cygwinPath.setBounds(new Rectangle(xPos, yPos, 300, 23));
+      cygwinPath.addMouseListener(new MouseAdapter()
+      {
+        @Override
+        public void mouseClicked(MouseEvent e)
+        {
+          if (e.getClickCount() == 2)
+          {
+            String chosen = openFileChooser(true);
+            if (chosen != null)
+            {
+              cygwinPath.setText(chosen);
+              validateCygwinPath();
+            }
+          }
+        }
+      });
+      hmmerTab.add(cygwinLocation);
+      hmmerTab.add(cygwinPath);
+    }
 
+    /*
+     * preferences for hmmalign
+     */
+    yPos += lineSpacing * 2;
+    JPanel alignOptions = new JPanel(new FlowLayout(FlowLayout.LEFT));
+    JvSwingUtils.createTitledBorder(alignOptions,
+            MessageManager.getString("label.hmmalign_label"), true);
+    yPos += lineSpacing;
     hmmrTrimTermini.setFont(LABEL_FONT);
     hmmrTrimTermini.setText(MessageManager.getString("label.trim_termini"));
-    hmmrTrimTermini.setBounds(new Rectangle(22, 70, 200, 23));
-
-    JLabel hmmsearch = new JLabel(
-            MessageManager.getString("label.hmmsearch_label"));
-    hmmsearch.setFont(LABEL_FONT);
-    hmmsearch.setBounds(new Rectangle(22, 90, 200, 23));
+    alignOptions.add(hmmrTrimTermini);
+    hmmerTab.add(alignOptions);
+    alignOptions.setBounds(new Rectangle(xPos, yPos, 300, 43));
 
+    /*
+     * preferences for hmmsearch
+     */
+    yPos += lineSpacing * 3;
+    JPanel searchOptions = new JPanel(new FlowLayout(FlowLayout.LEFT));
+    JvSwingUtils.createTitledBorder(searchOptions,
+            MessageManager.getString("label.hmmsearch_label"), true);
+    searchOptions.setBounds(new Rectangle(xPos, yPos, 300, 43));
     JLabel sequencesToKeep = new JLabel(
             MessageManager.getString("label.no_of_sequences"));
     sequencesToKeep.setFont(LABEL_FONT);
-    sequencesToKeep.setBounds(new Rectangle(22, 110, 125, 23));
-    hmmerSequenceCount.setBounds(new Rectangle(150, 110, 40, 23));
+    // hmmerSequenceCount.setBounds(new Rectangle(xPos + 250, yPos, 60, 23));
+    searchOptions.add(sequencesToKeep);
+    searchOptions.add(hmmerSequenceCount);
+    hmmerTab.add(searchOptions);
 
     ButtonGroup backgroundFreqSource = new ButtonGroup();
     backgroundFreqSource.add(hmmerBackgroundUniprot);
     backgroundFreqSource.add(hmmerBackgroundAlignment);
     backgroundFreqSource.setSelected(hmmerBackgroundUniprot.getModel(), true);
 
+    /*
+     * preferences for Information Content annotation
+     */
+    yPos += lineSpacing * 3;
     hmmerBackgroundUniprot.setText(MessageManager.getString("label.freq_uniprot"));
     hmmerBackgroundUniprot.setFont(LABEL_FONT);
-    hmmerBackgroundUniprot.setBounds(new Rectangle(22, 130, 255, 23));
+    hmmerBackgroundUniprot.setBounds(new Rectangle(xPos, yPos, 255, 23));
 
+    yPos += lineSpacing;
     hmmerBackgroundAlignment.setText(MessageManager.getString("label.freq_alignment"));
     hmmerBackgroundAlignment.setFont(LABEL_FONT);
-    hmmerBackgroundAlignment.setBounds(new Rectangle(22, 150, 300, 23));
+    hmmerBackgroundAlignment.setBounds(new Rectangle(xPos, yPos, 300, 23));
 
     hmmerTab.add(hmmerBackgroundUniprot);
     hmmerTab.add(hmmerBackgroundAlignment);
-    hmmerTab.add(hmmalign);
-    hmmerTab.add(hmmsearch);
-    hmmerTab.add(installationLocation);
-    hmmerTab.add(hmmerPath);
-    hmmerTab.add(hmmrTrimTermini);
-    hmmerTab.add(sequencesToKeep);
-    hmmerTab.add(sequencesToKeep);
-    hmmerTab.add(hmmerSequenceCount);
 
     return hmmerTab;
   }
@@ -1406,11 +1458,6 @@ public class GPreferences extends JPanel
     return false;
   }
 
-  protected boolean validateHMMERPath(boolean showWarning)
-  {
-    return false;
-  }
-
   /**
    * Initialises the Visual tabbed panel.
    * 
@@ -1915,8 +1962,11 @@ public class GPreferences extends JPanel
 
   }
 
-  public void hmmerPath_actionPerformed(ActionEvent e)
+  protected void validateHmmerPath()
   {
+  }
 
+  protected void validateCygwinPath()
+  {
   }
 }