2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.NJTree;
24 import jalview.analysis.scoremodels.ScoreModels;
25 import jalview.analysis.scoremodels.SimilarityParams;
26 import jalview.api.analysis.ScoreModelI;
27 import jalview.api.analysis.SimilarityParamsI;
28 import jalview.util.MessageManager;
30 import java.awt.Color;
31 import java.awt.FlowLayout;
33 import java.awt.GridLayout;
34 import java.awt.event.ActionEvent;
35 import java.beans.PropertyVetoException;
37 import javax.swing.ButtonGroup;
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JComboBox;
41 import javax.swing.JInternalFrame;
42 import javax.swing.JLabel;
43 import javax.swing.JLayeredPane;
44 import javax.swing.JPanel;
45 import javax.swing.JRadioButton;
48 * A dialog to allow a user to select and action Tree calculation options
50 public class TreeChooser extends JPanel
52 private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
56 JRadioButton neighbourJoining;
58 JRadioButton averageDistance;
60 JComboBox<String> matrixNames;
62 private JInternalFrame frame;
64 private ButtonGroup treeTypes;
66 private JCheckBox includeGaps;
68 private JCheckBox matchGaps;
70 private JCheckBox includeGappedColumns;
72 private JCheckBox shorterSequence;
79 public TreeChooser(AlignFrame alignFrame)
86 * Lays out the panel and adds it to the desktop
90 frame = new JInternalFrame();
91 frame.setContentPane(this);
92 this.setBackground(Color.white);
95 * Layout consists of 4 panels:
96 * - first with choice of tree method NJ or AV
97 * - second with choice of score model
98 * - third with score model parameter options
99 * - fourth with OK and Cancel
101 neighbourJoining = new JRadioButton(
102 MessageManager.getString("label.tree_calc_nj"));
103 neighbourJoining.setOpaque(false);
104 averageDistance = new JRadioButton(
105 MessageManager.getString("label.tree_calc_av"));
106 treeTypes = new ButtonGroup();
107 treeTypes.add(neighbourJoining);
108 treeTypes.add(averageDistance);
109 neighbourJoining.setSelected(true);
110 JPanel treeChoicePanel = new JPanel();
111 treeChoicePanel.setOpaque(false);
112 treeChoicePanel.add(neighbourJoining);
113 treeChoicePanel.add(averageDistance);
116 * score model drop-down
118 matrixNames = new JComboBox<String>();
119 ScoreModels scoreModels = ScoreModels.getInstance();
120 for (ScoreModelI sm : scoreModels.getModels())
122 boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
123 if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
125 matrixNames.addItem(sm.getName());
128 JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
129 scoreModelPanel.setOpaque(false);
130 scoreModelPanel.add(matrixNames, FlowLayout.LEFT);
133 * score model parameters
135 JPanel paramsPanel = new JPanel(new GridLayout(5, 1));
136 paramsPanel.setOpaque(false);
137 includeGaps = new JCheckBox("Include gaps");
138 matchGaps = new JCheckBox("Match gaps");
139 includeGappedColumns = new JCheckBox("Include gapped columns");
140 shorterSequence = new JCheckBox("Match on shorter sequence");
141 paramsPanel.add(new JLabel("Pairwise sequence scoring options"));
142 paramsPanel.add(includeGaps);
143 paramsPanel.add(matchGaps);
144 paramsPanel.add(includeGappedColumns);
145 paramsPanel.add(shorterSequence);
148 * OK / Cancel buttons
150 JButton ok = new JButton(MessageManager.getString("action.ok"));
151 ok.setFont(VERDANA_11PT);
152 ok.addActionListener(new java.awt.event.ActionListener()
155 public void actionPerformed(ActionEvent e)
157 ok_actionPerformed(e);
160 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
161 cancel.setFont(VERDANA_11PT);
162 cancel.addActionListener(new java.awt.event.ActionListener()
165 public void actionPerformed(ActionEvent e)
167 cancel_actionPerformed(e);
170 JPanel actionPanel = new JPanel();
171 actionPanel.setOpaque(false);
173 actionPanel.add(cancel);
175 this.add(treeChoicePanel);
176 this.add(scoreModelPanel);
177 this.add(paramsPanel);
178 this.add(actionPanel);
180 Desktop.addInternalFrame(frame,
181 MessageManager.getString("label.choose_tree"), 400, 400, false);
183 frame.setLayer(JLayeredPane.PALETTE_LAYER);
187 * Open and calculate the selected tree on 'OK'
191 protected void ok_actionPerformed(ActionEvent e)
193 String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
194 : NJTree.AVERAGE_DISTANCE;
195 ScoreModelI sm = ScoreModels.getInstance().forName(
196 matrixNames.getSelectedItem().toString());
197 SimilarityParamsI params = getSimilarityParameters();
198 af.newTreePanel(treeType, sm, params);
202 frame.setClosed(true);
203 } catch (PropertyVetoException ex)
208 private SimilarityParamsI getSimilarityParameters()
210 SimilarityParamsI params = new SimilarityParams(
211 includeGappedColumns.isSelected(), matchGaps.isSelected(),
212 includeGaps.isSelected(), shorterSequence.isSelected());
217 * Closes dialog on cancel
221 protected void cancel_actionPerformed(ActionEvent e)
225 frame.setClosed(true);
226 } catch (Exception ex)