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.awt.event.ItemEvent;
36 import java.awt.event.ItemListener;
37 import java.beans.PropertyVetoException;
39 import javax.swing.ButtonGroup;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
50 * A dialog to allow a user to select and action Tree calculation options
52 public class TreeChooser extends JPanel
54 private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
62 JRadioButton neighbourJoining;
64 JRadioButton averageDistance;
66 JComboBox<String> matrixNames;
68 private JInternalFrame frame;
70 private ButtonGroup treeTypes;
72 private JCheckBox includeGaps;
74 private JCheckBox matchGaps;
76 private JCheckBox includeGappedColumns;
78 private JCheckBox shorterSequence;
85 public TreeChooser(AlignFrame alignFrame)
92 * Lays out the panel and adds it to the desktop
96 frame = new JInternalFrame();
97 frame.setContentPane(this);
98 this.setBackground(Color.white);
101 * Layout consists of 5 panels:
102 * - first with choice of Tree or PCA
103 * - second with choice of tree method NJ or AV
104 * - third with choice of score model
105 * - fourth with score model parameter options
106 * - fifth with OK and Cancel
108 tree = new JRadioButton(MessageManager.getString("label.tree"));
109 tree.setOpaque(false);
110 pca = new JRadioButton(
111 MessageManager.getString("label.principal_component_analysis"));
112 pca.setOpaque(false);
113 neighbourJoining = new JRadioButton(
114 MessageManager.getString("label.tree_calc_nj"));
115 averageDistance = new JRadioButton(
116 MessageManager.getString("label.tree_calc_av"));
117 ItemListener listener = new ItemListener()
120 public void itemStateChanged(ItemEvent e)
122 neighbourJoining.setEnabled(tree.isSelected());
123 averageDistance.setEnabled(tree.isSelected());
126 pca.addItemListener(listener);
127 tree.addItemListener(listener);
128 ButtonGroup calcTypes = new ButtonGroup();
131 JPanel calcChoicePanel = new JPanel();
132 calcChoicePanel.setOpaque(false);
133 tree.setSelected(true);
134 calcChoicePanel.add(tree);
135 calcChoicePanel.add(pca);
137 neighbourJoining.setOpaque(false);
138 treeTypes = new ButtonGroup();
139 treeTypes.add(neighbourJoining);
140 treeTypes.add(averageDistance);
141 neighbourJoining.setSelected(true);
142 JPanel treeChoicePanel = new JPanel();
143 treeChoicePanel.setOpaque(false);
144 treeChoicePanel.add(neighbourJoining);
145 treeChoicePanel.add(averageDistance);
148 * score model drop-down
150 matrixNames = new JComboBox<String>();
151 ScoreModels scoreModels = ScoreModels.getInstance();
152 for (ScoreModelI sm : scoreModels.getModels())
154 boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
155 if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
157 matrixNames.addItem(sm.getName());
160 JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
161 scoreModelPanel.setOpaque(false);
162 scoreModelPanel.add(matrixNames, FlowLayout.LEFT);
165 * score model parameters
167 JPanel paramsPanel = new JPanel(new GridLayout(5, 1));
168 paramsPanel.setOpaque(false);
169 includeGaps = new JCheckBox("Include gaps");
170 matchGaps = new JCheckBox("Match gaps");
171 includeGappedColumns = new JCheckBox("Include gapped columns");
172 shorterSequence = new JCheckBox("Match on shorter sequence");
173 paramsPanel.add(new JLabel("Pairwise sequence scoring options"));
174 paramsPanel.add(includeGaps);
175 paramsPanel.add(matchGaps);
176 paramsPanel.add(includeGappedColumns);
177 paramsPanel.add(shorterSequence);
180 * OK / Cancel buttons
182 JButton ok = new JButton(MessageManager.getString("action.ok"));
183 ok.setFont(VERDANA_11PT);
184 ok.addActionListener(new java.awt.event.ActionListener()
187 public void actionPerformed(ActionEvent e)
189 ok_actionPerformed(e);
192 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
193 cancel.setFont(VERDANA_11PT);
194 cancel.addActionListener(new java.awt.event.ActionListener()
197 public void actionPerformed(ActionEvent e)
199 cancel_actionPerformed(e);
202 JPanel actionPanel = new JPanel();
203 actionPanel.setOpaque(false);
205 actionPanel.add(cancel);
207 this.add(calcChoicePanel);
208 this.add(treeChoicePanel);
209 this.add(scoreModelPanel);
210 this.add(paramsPanel);
211 this.add(actionPanel);
213 Desktop.addInternalFrame(frame,
214 MessageManager.getString("label.choose_tree"), 400, 400, false);
216 frame.setLayer(JLayeredPane.PALETTE_LAYER);
220 * Open and calculate the selected tree on 'OK'
224 protected void ok_actionPerformed(ActionEvent e)
226 ScoreModelI sm = ScoreModels.getInstance().forName(
227 matrixNames.getSelectedItem().toString());
228 SimilarityParamsI params = getSimilarityParameters();
230 if (pca.isSelected())
232 AlignViewport viewport = af.getViewport();
233 if (((viewport.getSelectionGroup() != null)
234 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
235 .getSelectionGroup().getSize() > 0))
236 || (viewport.getAlignment().getHeight() < 4))
239 .showInternalMessageDialog(
242 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
244 .getString("label.sequence_selection_insufficient"),
245 JvOptionPane.WARNING_MESSAGE);
248 new PCAPanel(af.alignPanel, sm, params);
252 String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
253 : NJTree.AVERAGE_DISTANCE;
254 af.newTreePanel(treeType, sm, params);
263 protected void closeFrame()
267 frame.setClosed(true);
268 } catch (PropertyVetoException ex)
273 private SimilarityParamsI getSimilarityParameters()
275 SimilarityParamsI params = new SimilarityParams(
276 includeGappedColumns.isSelected(), matchGaps.isSelected(),
277 includeGaps.isSelected(), shorterSequence.isSelected());
282 * Closes dialog on cancel
286 protected void cancel_actionPerformed(ActionEvent e)
290 frame.setClosed(true);
291 } catch (Exception ex)