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.api.analysis.ScoreModelI;
26 import jalview.util.MessageManager;
28 import java.awt.Color;
29 import java.awt.FlowLayout;
31 import java.awt.event.ActionEvent;
33 import javax.swing.ButtonGroup;
34 import javax.swing.JButton;
35 import javax.swing.JComboBox;
36 import javax.swing.JInternalFrame;
37 import javax.swing.JLayeredPane;
38 import javax.swing.JPanel;
39 import javax.swing.JRadioButton;
42 * A dialog to allow a user to select and action Tree calculation options
44 public class TreeChooser extends JPanel
46 private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
50 JRadioButton neighbourJoining;
52 JRadioButton averageDistance;
54 JComboBox<String> matrixNames;
56 private JInternalFrame frame;
58 private ButtonGroup treeTypes;
65 public TreeChooser(AlignFrame alignFrame)
73 frame = new JInternalFrame();
74 frame.setContentPane(this);
75 this.setBackground(Color.white);
77 neighbourJoining = new JRadioButton(
78 MessageManager.getString("label.tree_calc_nj"));
79 neighbourJoining.setOpaque(false);
80 averageDistance = new JRadioButton(
81 MessageManager.getString("label.tree_calc_av"));
82 treeTypes = new ButtonGroup();
83 treeTypes.add(neighbourJoining);
84 treeTypes.add(averageDistance);
85 neighbourJoining.setSelected(true);
87 matrixNames = new JComboBox<String>();
88 ScoreModels scoreModels = ScoreModels.getInstance();
89 for (ScoreModelI sm : scoreModels.getModels())
91 boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
92 if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
94 matrixNames.addItem(sm.getName());
98 JButton ok = new JButton(MessageManager.getString("action.ok"));
99 ok.setFont(VERDANA_11PT);
100 ok.addActionListener(new java.awt.event.ActionListener()
103 public void actionPerformed(ActionEvent e)
105 ok_actionPerformed(e);
109 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
110 cancel.setFont(VERDANA_11PT);
111 cancel.addActionListener(new java.awt.event.ActionListener()
114 public void actionPerformed(ActionEvent e)
116 cancel_actionPerformed(e);
120 JPanel p1 = new JPanel();
122 p1.add(neighbourJoining);
123 p1.add(averageDistance);
125 JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
127 p2.add(matrixNames, FlowLayout.LEFT);
129 JPanel p3 = new JPanel();
135 Desktop.addInternalFrame(frame,
136 MessageManager.getString("label.choose_tree"),
139 frame.setLayer(JLayeredPane.PALETTE_LAYER);
143 * Open and calculate the selected tree on 'OK'
147 protected void ok_actionPerformed(ActionEvent e)
151 frame.setClosed(true);
152 String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
153 : NJTree.AVERAGE_DISTANCE;
154 ScoreModelI sm = ScoreModels.getInstance().forName(
155 matrixNames.getSelectedItem().toString());
156 af.newTreePanel(treeType, sm);
157 } catch (Exception ex)
163 * Closes dialog on cancel
167 protected void cancel_actionPerformed(ActionEvent e)
171 frame.setClosed(true);
172 } catch (Exception ex)