From f56a081f0c0174cf6a5b8799a5531ddbdb71f20f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 28 Feb 2017 14:22:38 +0000 Subject: [PATCH] JAL-1632 disable parameters not applicable for score model --- src/jalview/gui/TreeChooser.java | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/jalview/gui/TreeChooser.java b/src/jalview/gui/TreeChooser.java index aafc1c0..9cbb47a 100644 --- a/src/jalview/gui/TreeChooser.java +++ b/src/jalview/gui/TreeChooser.java @@ -21,8 +21,10 @@ 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 matrixNames; + JComboBox modelNames; private JInternalFrame frame; @@ -147,19 +149,31 @@ public class TreeChooser extends JPanel /* * score model drop-down */ - matrixNames = new JComboBox(); + modelNames = new JComboBox(); 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()) -- 1.7.10.2