JAL-1632 disable parameters not applicable for score model
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 28 Feb 2017 14:22:38 +0000 (14:22 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 28 Feb 2017 14:22:38 +0000 (14:22 +0000)
src/jalview/gui/TreeChooser.java

index aafc1c0..9cbb47a 100644 (file)
 package jalview.gui;
 
 import jalview.analysis.NJTree;
+import jalview.analysis.scoremodels.ScoreMatrix;
 import jalview.analysis.scoremodels.ScoreModels;
 import jalview.analysis.scoremodels.SimilarityParams;
+import jalview.api.analysis.DistanceScoreModelI;
 import jalview.api.analysis.ScoreModelI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.util.MessageManager;
@@ -63,7 +65,7 @@ public class TreeChooser extends JPanel
 
   JRadioButton averageDistance;
 
-  JComboBox<String> matrixNames;
+  JComboBox<String> modelNames;
 
   private JInternalFrame frame;
 
@@ -147,19 +149,31 @@ public class TreeChooser extends JPanel
     /*
      * score model drop-down
      */
-    matrixNames = new JComboBox<String>();
+    modelNames = new JComboBox<String>();
     ScoreModels scoreModels = ScoreModels.getInstance();
     for (ScoreModelI sm : scoreModels.getModels())
     {
       boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
       if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
       {
-        matrixNames.addItem(sm.getName());
+        modelNames.addItem(sm.getName());
       }
     }
+    modelNames.addItemListener(new ItemListener()
+    {
+
+      @Override
+      public void itemStateChanged(ItemEvent e)
+      {
+        if (e.getStateChange() == ItemEvent.SELECTED)
+        {
+          scoreModelChanged((String) e.getItem());
+        }
+      }
+    });
     JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     scoreModelPanel.setOpaque(false);
-    scoreModelPanel.add(matrixNames, FlowLayout.LEFT);
+    scoreModelPanel.add(modelNames, FlowLayout.LEFT);
 
     /*
      * score model parameters
@@ -175,6 +189,8 @@ public class TreeChooser extends JPanel
     paramsPanel.add(matchGaps);
     paramsPanel.add(includeGappedColumns);
     paramsPanel.add(shorterSequence);
+    // configure initial state of options
+    scoreModelChanged(modelNames.getItemAt(0));
 
     /*
      * OK / Cancel buttons
@@ -217,6 +233,36 @@ public class TreeChooser extends JPanel
   }
 
   /**
+   * Action on selection of score model
+   * 
+   * @param item
+   */
+  protected void scoreModelChanged(String modelName)
+  {
+    /*
+     * enable/disable options appropriate to score model
+     * NB this is temporary - will get score models to provide
+     * their own parameters
+     */
+    includeGaps.setEnabled(true);
+    matchGaps.setEnabled(true);
+    includeGappedColumns.setEnabled(true);
+    shorterSequence.setEnabled(true);
+
+    ScoreModelI sm = ScoreModels.getInstance().forName(modelName);
+    if (sm instanceof DistanceScoreModelI)
+    {
+      matchGaps.setEnabled(false);
+      includeGappedColumns.setEnabled(false);
+      shorterSequence.setEnabled(false);
+    }
+    if (sm instanceof ScoreMatrix)
+    {
+      matchGaps.setEnabled(false);
+    }
+  }
+
+  /**
    * Open and calculate the selected tree on 'OK'
    * 
    * @param e
@@ -224,7 +270,7 @@ public class TreeChooser extends JPanel
   protected void ok_actionPerformed(ActionEvent e)
   {
     ScoreModelI sm = ScoreModels.getInstance().forName(
-            matrixNames.getSelectedItem().toString());
+            modelNames.getSelectedItem().toString());
     SimilarityParamsI params = getSimilarityParameters();
 
     if (pca.isSelected())