Merge branch 'develop' into features/hmmer
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 633d2b8..bb6f223 100755 (executable)
@@ -45,6 +45,7 @@ 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;
@@ -95,11 +96,11 @@ public class GPreferences extends JPanel
 
   protected JCheckBox rightAlign = new JCheckBox();
 
-  protected JComboBox<String> fontSizeCB = new JComboBox<String>();
+  protected JComboBox<String> fontSizeCB = new JComboBox<>();
 
-  protected JComboBox<String> fontStyleCB = new JComboBox<String>();
+  protected JComboBox<String> fontStyleCB = new JComboBox<>();
 
-  protected JComboBox<String> fontNameCB = new JComboBox<String>();
+  protected JComboBox<String> fontNameCB = new JComboBox<>();
 
   protected JCheckBox showOccupancy = new JCheckBox();
 
@@ -111,15 +112,15 @@ public class GPreferences extends JPanel
 
   protected JCheckBox scaleProteinToCdna = new JCheckBox();
 
-  protected JComboBox<String> gapSymbolCB = new JComboBox<String>();
+  protected JComboBox<String> gapSymbolCB = new JComboBox<>();
 
   protected JCheckBox wrap = new JCheckBox();
 
-  protected JComboBox<String> sortby = new JComboBox<String>();
+  protected JComboBox<String> sortby = new JComboBox<>();
 
-  protected JComboBox<String> sortAnnBy = new JComboBox<String>();
+  protected JComboBox<String> sortAnnBy = new JComboBox<>();
 
-  protected JComboBox<String> sortAutocalc = new JComboBox<String>();
+  protected JComboBox<String> sortAutocalc = new JComboBox<>();
 
   protected JCheckBox startupCheckbox = new JCheckBox();
 
@@ -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
    */
@@ -159,7 +165,7 @@ public class GPreferences extends JPanel
 
   protected JCheckBox addTempFactor = new JCheckBox();
 
-  protected JComboBox<String> structViewer = new JComboBox<String>();
+  protected JComboBox<String> structViewer = new JComboBox<>();
 
   protected JTextField chimeraPath = new JTextField();
 
@@ -176,9 +182,9 @@ public class GPreferences extends JPanel
 
   protected JPanel maxColour = new JPanel();
 
-  protected JComboBox<String> protColour = new JComboBox<String>();
+  protected JComboBox<String> protColour = new JComboBox<>();
 
-  protected JComboBox<String> nucColour = new JComboBox<String>();
+  protected JComboBox<String> nucColour = new JComboBox<>();
 
   /*
    * Connections tab components
@@ -216,7 +222,7 @@ public class GPreferences extends JPanel
   /*
    * Output tab components
    */
-  protected JComboBox<Object> epsRendering = new JComboBox<Object>();
+  protected JComboBox<Object> epsRendering = new JComboBox<>();
 
   protected JLabel userIdWidthlabel = new JLabel();
 
@@ -252,6 +258,33 @@ public class GPreferences extends JPanel
   protected JCheckBox sortByTree = new JCheckBox();
 
   /*
+   * hmmer tab and components
+   */
+  protected JPanel hmmerTab = new JPanel();
+
+  protected JCheckBox trimTermini = new JCheckBox();
+
+  protected ButtonGroup backgroundFreqSource = new ButtonGroup();
+
+  protected AbstractButton uniprot = new JCheckBox();
+
+  protected AbstractButton alignment = new JCheckBox();
+
+  protected JLabel sequencesToKeep = new JLabel();
+
+  protected JTextField numberOfSequencesToKeepField = new JTextField();
+
+  protected JLabel installationLocation = new JLabel();
+
+  protected JCheckBox isHMMERInstalled = new JCheckBox();
+
+  protected JTextField hmmerPath = new JTextField();
+
+  protected JLabel hmmsearch = new JLabel();
+
+  protected JLabel hmmalign = new JLabel();
+
+  /*
    * DAS Settings tab
    */
   protected JPanel dasTab = new JPanel();
@@ -261,6 +294,8 @@ public class GPreferences extends JPanel
    */
   protected JPanel wsTab = new JPanel();
 
+
+
   /**
    * Creates a new GPreferences object.
    */
@@ -309,6 +344,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.
      */
@@ -341,6 +378,16 @@ public class GPreferences extends JPanel
             return;
           }
         }
+        else if (lastTab == hmmerTab
+                && tabbedPane.getSelectedComponent() != hmmerTab
+                && isHMMERInstalled.isSelected())
+        {
+          if (!validateHMMER())
+          {
+            tabbedPane.setSelectedComponent(hmmerTab);
+          }
+          return;
+        }
         lastTab = tabbedPane.getSelectedComponent();
       }
 
@@ -377,6 +424,95 @@ public class GPreferences extends JPanel
   }
 
   /**
+   * Initialises the hmmer tabbed panel.
+   * 
+   * @return
+   */
+  private JPanel initHMMERTab()
+  {
+    hmmerTab.setLayout(null);
+
+    hmmalign.setFont(LABEL_FONT);
+    hmmalign.setText(MessageManager.getString("label.hmmalign_label"));
+    hmmalign.setBounds(new Rectangle(22, 10, 200, 23));
+
+    trimTermini.setFont(LABEL_FONT);
+    trimTermini.setText(MessageManager.getString("label.trim_termini"));
+    trimTermini.setBounds(new Rectangle(22, 30, 200, 23));
+
+    hmmsearch.setFont(LABEL_FONT);
+    hmmsearch.setText(MessageManager.getString("label.hmmsearch_label"));
+    hmmsearch.setBounds(new Rectangle(250, 10, 200, 23));
+
+    sequencesToKeep.setFont(LABEL_FONT);
+    sequencesToKeep
+            .setText(MessageManager.getString("label.no_of_sequences"));
+    sequencesToKeep.setBounds(new Rectangle(250, 30, 125, 23));
+    numberOfSequencesToKeepField.setBounds(new Rectangle(375, 30, 40, 23));
+
+    isHMMERInstalled.setFont(LABEL_FONT);
+    isHMMERInstalled.setText(
+            MessageManager.getString("label.hmmer_installed"));
+    isHMMERInstalled.setBounds(new Rectangle(22, 180, 200, 23));
+    isHMMERInstalled.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        boolean status = isHMMERInstalled.isSelected();
+        installationLocation.setEnabled(status);
+        hmmerPath.setEnabled(status);
+      }
+    });
+    installationLocation.setFont(LABEL_FONT);
+    installationLocation.setText(
+            MessageManager.getString("label.change_hmmer_location"));
+    installationLocation.setBounds(new Rectangle(22, 200, 200, 23));
+    hmmerPath.setBounds(new Rectangle(22, 220, 200, 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);
+          }
+        }
+      }
+    });
+
+    backgroundFreqSource.add(uniprot);
+    backgroundFreqSource.add(alignment);
+    backgroundFreqSource.setSelected(uniprot.getModel(), true);
+
+    uniprot.setText(MessageManager.getString("label.freq_uniprot"));
+    uniprot.setFont(LABEL_FONT);
+    uniprot.setBounds(new Rectangle(22, 260, 255, 23));
+
+    alignment.setText(MessageManager.getString("label.freq_alignment"));
+    alignment.setFont(LABEL_FONT);
+    alignment.setBounds(new Rectangle(22, 280, 255, 23));
+
+    hmmerTab.add(uniprot);
+    hmmerTab.add(alignment);
+    hmmerTab.add(hmmalign);
+    hmmerTab.add(hmmsearch);
+    hmmerTab.add(installationLocation);
+    hmmerTab.add(hmmerPath);
+    hmmerTab.add(trimTermini);
+    hmmerTab.add(sequencesToKeep);
+    hmmerTab.add(sequencesToKeep);
+    hmmerTab.add(numberOfSequencesToKeepField);
+    hmmerTab.add(isHMMERInstalled);
+
+    return hmmerTab;
+  }
+
+  /**
    * Initialises the Output tabbed panel.
    * 
    * @return
@@ -1061,7 +1197,7 @@ public class GPreferences extends JPanel
       {
         if (e.getClickCount() == 2)
         {
-          String chosen = openFileChooser();
+          String chosen = openFileChooser(false);
           if (chosen != null)
           {
             chimeraPath.setText(chosen);
@@ -1116,10 +1252,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(
@@ -1150,11 +1290,31 @@ public class GPreferences extends JPanel
     return true;
   }
 
+  /**
+   * Validate the hmmer tab preferences; if invalid, set focus on this tab.
+   * 
+   * @param e
+   */
+  protected boolean validateHMMER(FocusEvent e)
+  {
+    if (!validateHMMER())
+    {
+      e.getComponent().requestFocusInWindow();
+      return false;
+    }
+    return true;
+  }
+
   protected boolean validateStructure()
   {
     return false;
   }
 
+  protected boolean validateHMMER()
+  {
+    return false;
+  }
+
   /**
    * Initialises the Visual tabbed panel.
    * 
@@ -1642,4 +1802,9 @@ public class GPreferences extends JPanel
     }
 
   }
+
+  public void hmmerPath_actionPerformed(ActionEvent e)
+  {
+
+  }
 }