Merge branch 'features/mchmmer' into merge/wsinterfaces_mchmmer_JAL-3070_JAL-1950
[jalview.git] / src / jalview / jbgui / GPreferences.java
index 6ff335e..4e909f1 100755 (executable)
@@ -48,11 +48,13 @@ import java.awt.event.MouseEvent;
 import javax.swing.AbstractButton;
 import javax.swing.AbstractCellEditor;
 import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
 import javax.swing.ButtonGroup;
 import javax.swing.DefaultListCellRenderer;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
+import javax.swing.JComponent;
 import javax.swing.JFileChooser;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
@@ -72,6 +74,8 @@ import javax.swing.event.ChangeListener;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
 
+import net.miginfocom.swing.MigLayout;
+
 /**
  * Base class for the Preferences panel.
  * 
@@ -273,24 +277,19 @@ public class GPreferences extends JPanel
   /*
    * hmmer tab and components
    */
-  protected JPanel hmmerTab = new JPanel();
-
-  protected JCheckBox hmmrTrimTermini = new JCheckBox();
+  protected JPanel hmmerTab;
 
-  protected AbstractButton hmmerBackgroundUniprot = new JCheckBox();
+  protected JCheckBox hmmrTrimTermini;
 
-  protected AbstractButton hmmerBackgroundAlignment = new JCheckBox();
+  protected AbstractButton hmmerBackgroundUniprot;
 
-  protected JTextField hmmerSequenceCount = new JTextField();
+  protected AbstractButton hmmerBackgroundAlignment;
 
-  protected JTextField hmmerPath = new JTextField();
+  protected JTextField hmmerSequenceCount;
 
-  protected JTextField cygwinPath = new JTextField();
+  protected JTextField hmmerPath;
 
-  /*
-   * DAS Settings tab
-   */
-  protected JPanel dasTab = new JPanel();
+  protected JTextField cygwinPath;
 
   /*
    * Web Services tab
@@ -353,12 +352,6 @@ public class GPreferences extends JPanel
     tabbedPane.add(initHMMERTab(), MessageManager.getString("label.hmmer"));
 
     /*
-     * See DasSourceBrowser for the real work of configuring this tab.
-     */
-    dasTab.setLayout(new BorderLayout());
-    tabbedPane.add(dasTab, MessageManager.getString("label.das_settings"));
-
-    /*
      * See WsPreferences for the real work of configuring this tab.
      */
     wsTab.setLayout(new BorderLayout());
@@ -426,20 +419,23 @@ public class GPreferences extends JPanel
    */
   private JPanel initHMMERTab()
   {
-    hmmerTab.setLayout(null);
-    final int lineSpacing = 20;
+    hmmerTab = new JPanel();
+    hmmerTab.setLayout(new BoxLayout(hmmerTab, BoxLayout.Y_AXIS));
+    hmmerTab.setLayout(new MigLayout("flowy"));
 
     /*
      * path to hmmer binaries folder
      */
+    JPanel installationPanel = new JPanel(new MigLayout("flowy"));
+    // new FlowLayout(FlowLayout.LEFT));
+    JvSwingUtils.createTitledBorder(installationPanel,
+            MessageManager.getString("label.installation"), true);
+    hmmerTab.add(installationPanel);
     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));
+    final int pathFieldLength = 40;
+    hmmerPath = new JTextField(pathFieldLength);
     hmmerPath.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -456,8 +452,8 @@ public class GPreferences extends JPanel
         }
       }
     });
-    hmmerTab.add(hmmerLocation);
-    hmmerTab.add(hmmerPath);
+    installationPanel.add(hmmerLocation);
+    installationPanel.add(hmmerPath);
 
     /*
      * path to Cygwin binaries folder (for Windows)
@@ -467,10 +463,7 @@ public class GPreferences extends JPanel
       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 = new JTextField(pathFieldLength);
       cygwinPath.addMouseListener(new MouseAdapter()
       {
         @Override
@@ -487,60 +480,62 @@ public class GPreferences extends JPanel
           }
         }
       });
-      hmmerTab.add(cygwinLocation);
-      hmmerTab.add(cygwinPath);
+      installationPanel.add(cygwinLocation);
+      installationPanel.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;
+    JPanel alignOptionsPanel = new JPanel(new MigLayout());
+    // new FlowLayout(FlowLayout.LEFT));
+    JvSwingUtils.createTitledBorder(alignOptionsPanel,
+            MessageManager.getString("label.hmmalign_options"), true);
+    hmmerTab.add(alignOptionsPanel);
+    hmmrTrimTermini = new JCheckBox();
     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));
+    alignOptionsPanel.add(hmmrTrimTermini);
 
     /*
      * preferences for hmmsearch
      */
-    yPos += lineSpacing * 3;
-    JPanel searchOptions = new JPanel(new FlowLayout(FlowLayout.LEFT));
+    JPanel searchOptions = new JPanel(new MigLayout());
+    // FlowLayout(FlowLayout.LEFT));
     JvSwingUtils.createTitledBorder(searchOptions,
-            MessageManager.getString("label.hmmsearch_label"), true);
-    searchOptions.setBounds(new Rectangle(xPos, yPos, 300, 43));
+            MessageManager.getString("label.hmmsearch_options"), true);
+    hmmerTab.add(searchOptions);
     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);
+    hmmerSequenceCount = new JTextField(5);
     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"));
+    // JPanel dummy = new JPanel(new FlowLayout(FlowLayout.LEFT));
+    JPanel annotationOptions = new JPanel(new MigLayout("left"));
+    JvSwingUtils.createTitledBorder(annotationOptions,
+            MessageManager.getString("label.information_annotation"), true);
+    // dummy.add(annotationOptions);
+    hmmerTab.add(annotationOptions);
+    ButtonGroup backgroundOptions = new ButtonGroup();
+    hmmerBackgroundUniprot = new JRadioButton(
+            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 = new JRadioButton(
+            MessageManager.getString("label.freq_alignment"));
     hmmerBackgroundAlignment.setFont(LABEL_FONT);
-    hmmerBackgroundAlignment.setBounds(new Rectangle(xPos, yPos, 300, 23));
-
-    hmmerTab.add(hmmerBackgroundUniprot);
-    hmmerTab.add(hmmerBackgroundAlignment);
+    backgroundOptions.add(hmmerBackgroundUniprot);
+    backgroundOptions.add(hmmerBackgroundAlignment);
+    backgroundOptions.setSelected(hmmerBackgroundUniprot.getModel(), true);
+    // disable buttons for now as annotation only uses Uniprot background
+    hmmerBackgroundAlignment.setEnabled(false);
+    hmmerBackgroundUniprot.setEnabled(false);
+    annotationOptions.add(hmmerBackgroundUniprot, "wrap");
+    annotationOptions.add(hmmerBackgroundAlignment);
 
     return hmmerTab;
   }
@@ -677,7 +672,9 @@ public class GPreferences extends JPanel
             MessageManager.getString("label.default_browser_unix"));
     defaultBrowser.setFont(LABEL_FONT);
     defaultBrowser.setText("");
-
+    final String tooltip = JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.double_click_to_browse"));
+    defaultBrowser.setToolTipText(tooltip);
     defaultBrowser.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -1098,7 +1095,7 @@ public class GPreferences extends JPanel
     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
     protColourLabel.setText(
             MessageManager.getString("label.prot_alignment_colour") + " ");
-    JvSwingUtils.addtoLayout(coloursTab,
+    GPreferences.addtoLayout(coloursTab,
             MessageManager
                     .getString("label.default_colour_scheme_for_alignment"),
             protColourLabel, protColour);
@@ -1110,7 +1107,7 @@ public class GPreferences extends JPanel
     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
     nucColourLabel.setText(
             MessageManager.getString("label.nuc_alignment_colour") + " ");
-    JvSwingUtils.addtoLayout(coloursTab,
+    GPreferences.addtoLayout(coloursTab,
             MessageManager
                     .getString("label.default_colour_scheme_for_alignment"),
             nucColourLabel, nucColour);
@@ -1119,11 +1116,11 @@ public class GPreferences extends JPanel
     annotationShding.setBorder(new TitledBorder(
             MessageManager.getString("label.annotation_shading_default")));
     annotationShding.setLayout(new GridLayout(1, 2));
-    JvSwingUtils.addtoLayout(annotationShding,
+    GPreferences.addtoLayout(annotationShding,
             MessageManager.getString(
                     "label.default_minimum_colour_annotation_shading"),
             mincolourLabel, minColour);
-    JvSwingUtils.addtoLayout(annotationShding,
+    GPreferences.addtoLayout(annotationShding,
             MessageManager.getString(
                     "label.default_maximum_colour_annotation_shading"),
             maxcolourLabel, maxColour);
@@ -1359,14 +1356,14 @@ public class GPreferences extends JPanel
     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
     pathLabel.setText(MessageManager.getString("label.chimera_path"));
-    final String tooltip = JvSwingUtils.wrapTooltip(true,
-            MessageManager.getString("label.chimera_path_tip"));
-    pathLabel.setToolTipText(tooltip);
     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
     structureTab.add(pathLabel);
 
     chimeraPath.setFont(LABEL_FONT);
     chimeraPath.setText("");
+    final String tooltip = JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.chimera_path_tip"));
+    chimeraPath.setToolTipText(tooltip);
     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
     chimeraPath.addMouseListener(new MouseAdapter()
     {
@@ -1654,6 +1651,9 @@ public class GPreferences extends JPanel
     startupCheckbox.setSelected(true);
     startupFileTextfield.setFont(LABEL_FONT);
     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
+    final String tooltip = JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.double_click_to_browse"));
+    startupFileTextfield.setToolTipText(tooltip);
     startupFileTextfield.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -1969,4 +1969,32 @@ public class GPreferences extends JPanel
   protected void validateCygwinPath()
   {
   }
+
+  /**
+   * A helper method to add a panel containing a label and a component to a
+   * panel
+   * 
+   * @param panel
+   * @param tooltip
+   * @param label
+   * @param valBox
+   */
+  protected static void addtoLayout(JPanel panel, String tooltip,
+          JComponent label, JComponent valBox)
+  {
+    JPanel laypanel = new JPanel(new GridLayout(1, 2));
+    JPanel labPanel = new JPanel(new BorderLayout());
+    JPanel valPanel = new JPanel();
+    labPanel.setBounds(new Rectangle(7, 7, 158, 23));
+    valPanel.setBounds(new Rectangle(172, 7, 270, 23));
+    labPanel.add(label, BorderLayout.WEST);
+    valPanel.add(valBox);
+    laypanel.add(labPanel);
+    laypanel.add(valPanel);
+    valPanel.setToolTipText(tooltip);
+    labPanel.setToolTipText(tooltip);
+    valBox.setToolTipText(tooltip);
+    panel.add(laypanel);
+    panel.validate();
+  }
 }