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.scoremodels.ScoreModels;
24 import jalview.api.analysis.ScoreModelI;
25 import jalview.util.MessageManager;
27 import java.awt.Color;
28 import java.awt.FlowLayout;
30 import java.awt.event.ActionEvent;
32 import javax.swing.ButtonGroup;
33 import javax.swing.JButton;
34 import javax.swing.JComboBox;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JLayeredPane;
37 import javax.swing.JPanel;
38 import javax.swing.JRadioButton;
41 * A dialog to allow a user to select and action Tree calculation options
43 public class TreeChooser extends JPanel
45 private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
49 JRadioButton neighbourJoining;
51 JRadioButton averageDistance;
53 JComboBox<String> matrixNames;
55 private JInternalFrame frame;
57 private ButtonGroup treeTypes;
64 public TreeChooser(AlignFrame alignFrame)
72 frame = new JInternalFrame();
73 frame.setContentPane(this);
74 this.setBackground(Color.white);
76 neighbourJoining = new JRadioButton(
77 MessageManager.getString("label.tree_calc_nj"));
78 neighbourJoining.setOpaque(false);
79 averageDistance = new JRadioButton(
80 MessageManager.getString("label.tree_calc_av"));
81 treeTypes = new ButtonGroup();
82 treeTypes.add(neighbourJoining);
83 treeTypes.add(averageDistance);
84 neighbourJoining.setSelected(true);
86 matrixNames = new JComboBox<String>();
87 ScoreModels scoreModels = ScoreModels.getInstance();
88 for (ScoreModelI sm : scoreModels.getModels())
90 boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
91 if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
93 matrixNames.addItem(sm.getName());
97 JButton ok = new JButton(MessageManager.getString("action.ok"));
98 ok.setFont(VERDANA_11PT);
99 ok.addActionListener(new java.awt.event.ActionListener()
102 public void actionPerformed(ActionEvent e)
104 ok_actionPerformed(e);
108 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
109 cancel.setFont(VERDANA_11PT);
110 cancel.addActionListener(new java.awt.event.ActionListener()
113 public void actionPerformed(ActionEvent e)
115 cancel_actionPerformed(e);
119 JPanel p1 = new JPanel();
121 p1.add(neighbourJoining);
122 p1.add(averageDistance);
124 JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
126 p2.add(matrixNames, FlowLayout.LEFT);
128 JPanel p3 = new JPanel();
134 Desktop.addInternalFrame(frame,
135 MessageManager.getString("label.choose_tree"),
138 frame.setLayer(JLayeredPane.PALETTE_LAYER);
142 * Open and calculate the selected tree on 'OK'
146 protected void ok_actionPerformed(ActionEvent e)
150 frame.setClosed(true);
151 String treeType = neighbourJoining.isSelected() ? "NJ" : "AV";
152 ScoreModelI sm = ScoreModels.getInstance().forName(
153 matrixNames.getSelectedItem().toString());
154 af.newTreePanel(treeType, sm);
155 } catch (Exception ex)
161 * Closes dialog on cancel
165 protected void cancel_actionPerformed(ActionEvent e)
169 frame.setClosed(true);
170 } catch (Exception ex)