JAL-1632 suppress PID parameter options in Tree/PCA chooser for now
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 23 Mar 2017 16:11:37 +0000 (16:11 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 23 Mar 2017 16:11:37 +0000 (16:11 +0000)
src/jalview/gui/TreeChooser.java

index 41b7d48..4f972ae 100644 (file)
 package jalview.gui;
 
 import jalview.analysis.NJTree;
-import jalview.analysis.scoremodels.ScoreMatrix;
+import jalview.analysis.scoremodels.PIDModel;
 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;
@@ -100,11 +99,11 @@ public class TreeChooser extends JPanel
     this.setBackground(Color.white);
 
     /*
-     * Layout consists of 5 panels:
+     * Layout consists of 4 or 5 panels:
      * - first with choice of Tree or PCA
      * - second with choice of tree method NJ or AV
      * - third with choice of score model
-     * - fourth with score model parameter options
+     * - fourth with score model parameter options [suppressed]
      * - fifth with OK and Cancel
      */
     tree = new JRadioButton(MessageManager.getString("label.tree"));
@@ -159,18 +158,7 @@ public class TreeChooser extends JPanel
         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(modelNames, FlowLayout.LEFT);
@@ -189,8 +177,6 @@ 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
@@ -202,7 +188,7 @@ public class TreeChooser extends JPanel
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        ok_actionPerformed(e);
+        ok_actionPerformed();
       }
     });
     JButton cancel = new JButton(MessageManager.getString("action.cancel"));
@@ -220,71 +206,36 @@ public class TreeChooser extends JPanel
     actionPanel.add(ok);
     actionPanel.add(cancel);
 
+    boolean includeParams = false;
     this.add(calcChoicePanel);
     this.add(treeChoicePanel);
     this.add(scoreModelPanel);
-    this.add(paramsPanel);
+    if (includeParams)
+    {
+      this.add(paramsPanel);
+    }
     this.add(actionPanel);
 
+    int width = 380;
+    int height = includeParams ? 400 : 220;
     Desktop.addInternalFrame(frame,
-            MessageManager.getString("label.choose_tree"), 400, 400, false);
+            MessageManager.getString("label.choose_tree"), width, height,
+            false);
 
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
   }
 
   /**
-   * 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);
-    }
-    if (tree.isSelected())
-    {
-      // ?? tree requires specific parameter settings??
-      includeGaps.setSelected(true);
-      includeGaps.setEnabled(false);
-      matchGaps.setSelected(true);
-      includeGappedColumns.setSelected(true);
-      includeGappedColumns.setEnabled(false);
-      shorterSequence.setSelected(false);
-      shorterSequence.setEnabled(false);
-    }
-  }
-
-  /**
    * Open and calculate the selected tree on 'OK'
-   * 
-   * @param e
    */
-  protected void ok_actionPerformed(ActionEvent e)
+  protected void ok_actionPerformed()
   {
+    boolean doPCA = pca.isSelected();
     ScoreModelI sm = ScoreModels.getInstance().forName(
             modelNames.getSelectedItem().toString());
-    SimilarityParamsI params = getSimilarityParameters();
+    SimilarityParamsI params = getSimilarityParameters(doPCA, sm);
 
-    if (pca.isSelected())
+    if (doPCA)
     {
       AlignViewport viewport = af.getViewport();
       if (((viewport.getSelectionGroup() != null)
@@ -327,12 +278,35 @@ public class TreeChooser extends JPanel
     }
   }
 
-  private SimilarityParamsI getSimilarityParameters()
+  /**
+   * Returns a data bean holding parameters for similarity (or distance) model
+   * calculation
+   * 
+   * @param doPCA
+   * @param sm
+   * @return
+   */
+  protected SimilarityParamsI getSimilarityParameters(boolean doPCA,
+          ScoreModelI sm)
   {
-    SimilarityParamsI params = new SimilarityParams(
-            includeGappedColumns.isSelected(), matchGaps.isSelected(),
-            includeGaps.isSelected(), shorterSequence.isSelected());
-    return params;
+    // commented out: parameter choices read from gui widgets
+    // SimilarityParamsI params = new SimilarityParams(
+    // includeGappedColumns.isSelected(), matchGaps.isSelected(),
+    // includeGaps.isSelected(), shorterSequence.isSelected());
+
+    /*
+     * for now we want
+     * includeGappedColumns = true
+     * includeGaps = true
+     * matchOnShortestSequence = false
+     * matchGaps = true except false for PCA by PID (to match SeqSpace)
+     */
+    boolean matchGap = true;
+    if (doPCA && (sm instanceof PIDModel))
+    {
+      matchGap = false;
+    }
+    return new SimilarityParams(true, matchGap, true, false);
   }
 
   /**