JAL-2937 Cygwin path preference, method refactoring
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 1ca0802..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;
@@ -40,11 +41,11 @@ import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 
+import javax.swing.AbstractButton;
 import javax.swing.AbstractCellEditor;
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
@@ -142,10 +143,15 @@ public class GPreferences extends JPanel
 
   protected JCheckBox showConsensLogo = new JCheckBox();
 
+  protected JCheckBox showInformationHistogram = new JCheckBox();
+
+  protected JCheckBox showHMMLogo = new JCheckBox();
+
   protected JCheckBox showDbRefTooltip = new JCheckBox();
 
   protected JCheckBox showNpTooltip = new JCheckBox();
 
+
   /*
    * Structure tab and components
    */
@@ -265,6 +271,23 @@ public class GPreferences extends JPanel
   protected JCheckBox sortByTree = new JCheckBox();
 
   /*
+   * hmmer tab and components
+   */
+  protected JPanel hmmerTab = new JPanel();
+
+  protected JCheckBox hmmrTrimTermini = new JCheckBox();
+
+  protected AbstractButton hmmerBackgroundUniprot = new JCheckBox();
+
+  protected AbstractButton hmmerBackgroundAlignment = new JCheckBox();
+
+  protected JTextField hmmerSequenceCount = new JTextField();
+
+  protected JTextField hmmerPath = new JTextField();
+
+  protected JTextField cygwinPath = new JTextField();
+
+  /*
    * DAS Settings tab
    */
   protected JPanel dasTab = new JPanel();
@@ -274,6 +297,8 @@ public class GPreferences extends JPanel
    */
   protected JPanel wsTab = new JPanel();
 
+
+
   /**
    * Creates a new GPreferences object.
    */
@@ -325,6 +350,8 @@ public class GPreferences extends JPanel
     tabbedPane.add(initEditingTab(),
             MessageManager.getString("label.editing"));
 
+    tabbedPane.add(initHMMERTab(), MessageManager.getString("label.hmmer"));
+
     /*
      * See DasSourceBrowser for the real work of configuring this tab.
      */
@@ -339,7 +366,7 @@ public class GPreferences extends JPanel
 
     /*
      * Handler to validate a tab before leaving it - currently only for
-     * Structure.
+     * Structure
      */
     tabbedPane.addChangeListener(new ChangeListener()
     {
@@ -393,6 +420,132 @@ public class GPreferences extends JPanel
   }
 
   /**
+   * Initialises the hmmer tabbed panel
+   * 
+   * @return
+   */
+  private JPanel initHMMERTab()
+  {
+    hmmerTab.setLayout(null);
+    final int lineSpacing = 20;
+
+    /*
+     * path to hmmer binaries folder
+     */
+    JLabel hmmerLocation = new JLabel(
+            MessageManager.getString("label.hmmer_location"));
+    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
+      public void mouseClicked(MouseEvent e)
+      {
+        if (e.getClickCount() == 2)
+        {
+          String chosen = openFileChooser(true);
+          if (chosen != null)
+          {
+            hmmerPath.setText(chosen);
+            validateHmmerPath();
+          }
+        }
+      }
+    });
+    hmmerTab.add(hmmerLocation);
+    hmmerTab.add(hmmerPath);
+
+    /*
+     * 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"));
+    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);
+    // 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(xPos, yPos, 255, 23));
+
+    yPos += lineSpacing;
+    hmmerBackgroundAlignment.setText(MessageManager.getString("label.freq_alignment"));
+    hmmerBackgroundAlignment.setFont(LABEL_FONT);
+    hmmerBackgroundAlignment.setBounds(new Rectangle(xPos, yPos, 300, 23));
+
+    hmmerTab.add(hmmerBackgroundUniprot);
+    hmmerTab.add(hmmerBackgroundAlignment);
+
+    return hmmerTab;
+  }
+
+  /**
    * Initialises the Output tabbed panel.
    * 
    * @return
@@ -1222,7 +1375,7 @@ public class GPreferences extends JPanel
       {
         if (e.getClickCount() == 2)
         {
-          String chosen = openFileChooser();
+          String chosen = openFileChooser(false);
           if (chosen != null)
           {
             chimeraPath.setText(chosen);
@@ -1277,10 +1430,14 @@ public class GPreferences extends JPanel
    * 
    * @return
    */
-  protected String openFileChooser()
+  protected String openFileChooser(boolean forFolder)
   {
     String choice = null;
     JFileChooser chooser = new JFileChooser();
+    if (forFolder)
+    {
+      chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+    }
 
     // chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
@@ -1296,21 +1453,6 @@ public class GPreferences extends JPanel
     return choice;
   }
 
-  /**
-   * Validate the structure tab preferences; if invalid, set focus on this tab.
-   * 
-   * @param e
-   */
-  protected boolean validateStructure(FocusEvent e)
-  {
-    if (!validateStructure())
-    {
-      e.getComponent().requestFocusInWindow();
-      return false;
-    }
-    return true;
-  }
-
   protected boolean validateStructure()
   {
     return false;
@@ -1819,4 +1961,12 @@ public class GPreferences extends JPanel
     }
 
   }
+
+  protected void validateHmmerPath()
+  {
+  }
+
+  protected void validateCygwinPath()
+  {
+  }
 }