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 (String scoreType : scoreModels.getModelNames())
90 ScoreModelI sm = scoreModels.forName(scoreType);
91 if (sm.isDNA() == af.getViewport().getAlignment().isNucleotide()
92 || sm.isProtein() == !af.getViewport().getAlignment()
95 matrixNames.addItem(sm.getName());
99 JButton ok = new JButton(MessageManager.getString("action.ok"));
100 ok.setFont(VERDANA_11PT);
101 ok.addActionListener(new java.awt.event.ActionListener()
104 public void actionPerformed(ActionEvent e)
106 ok_actionPerformed(e);
110 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
111 cancel.setFont(VERDANA_11PT);
112 cancel.addActionListener(new java.awt.event.ActionListener()
115 public void actionPerformed(ActionEvent e)
117 cancel_actionPerformed(e);
121 JPanel p1 = new JPanel();
123 p1.add(neighbourJoining);
124 p1.add(averageDistance);
126 JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
128 p2.add(matrixNames, FlowLayout.LEFT);
130 JPanel p3 = new JPanel();
136 Desktop.addInternalFrame(frame,
137 MessageManager.getString("label.choose_tree"),
140 frame.setLayer(JLayeredPane.PALETTE_LAYER);
144 * Open and calculate the selected tree on 'OK'
148 protected void ok_actionPerformed(ActionEvent e)
152 frame.setClosed(true);
153 String treeType = neighbourJoining.isSelected() ? "NJ" : "AV";
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)