/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
import jalview.analysis.NJTree;
import jalview.analysis.scoremodels.ScoreModels;
import jalview.api.analysis.ScoreModelI;
import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
/**
* A dialog to allow a user to select and action Tree calculation options
*/
public class TreeChooser extends JPanel
{
private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
AlignFrame af;
JRadioButton neighbourJoining;
JRadioButton averageDistance;
JComboBox matrixNames;
private JInternalFrame frame;
private ButtonGroup treeTypes;
/**
* Constructor
*
* @param af
*/
public TreeChooser(AlignFrame alignFrame)
{
this.af = alignFrame;
init();
}
void init()
{
frame = new JInternalFrame();
frame.setContentPane(this);
this.setBackground(Color.white);
neighbourJoining = new JRadioButton(
MessageManager.getString("label.tree_calc_nj"));
neighbourJoining.setOpaque(false);
averageDistance = new JRadioButton(
MessageManager.getString("label.tree_calc_av"));
treeTypes = new ButtonGroup();
treeTypes.add(neighbourJoining);
treeTypes.add(averageDistance);
neighbourJoining.setSelected(true);
matrixNames = new JComboBox();
ScoreModels scoreModels = ScoreModels.getInstance();
for (ScoreModelI sm : scoreModels.getModels())
{
boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
{
matrixNames.addItem(sm.getName());
}
}
JButton ok = new JButton(MessageManager.getString("action.ok"));
ok.setFont(VERDANA_11PT);
ok.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
ok_actionPerformed(e);
}
});
JButton cancel = new JButton(MessageManager.getString("action.cancel"));
cancel.setFont(VERDANA_11PT);
cancel.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
cancel_actionPerformed(e);
}
});
JPanel p1 = new JPanel();
p1.setOpaque(false);
p1.add(neighbourJoining);
p1.add(averageDistance);
this.add(p1);
JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
p2.setOpaque(false);
p2.add(matrixNames, FlowLayout.LEFT);
this.add(p2);
JPanel p3 = new JPanel();
p3.setOpaque(false);
p3.add(ok);
p3.add(cancel);
this.add(p3);
Desktop.addInternalFrame(frame,
MessageManager.getString("label.choose_tree"),
400, 200, false);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
}
/**
* Open and calculate the selected tree on 'OK'
*
* @param e
*/
protected void ok_actionPerformed(ActionEvent e)
{
try
{
frame.setClosed(true);
String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
: NJTree.AVERAGE_DISTANCE;
ScoreModelI sm = ScoreModels.getInstance().forName(
matrixNames.getSelectedItem().toString());
af.newTreePanel(treeType, sm);
} catch (Exception ex)
{
}
}
/**
* Closes dialog on cancel
*
* @param e
*/
protected void cancel_actionPerformed(ActionEvent e)
{
try
{
frame.setClosed(true);
} catch (Exception ex)
{
}
}
}