/*
* Copyright (c) 2010 The Jackson Laboratory
*
* This 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.
*
* This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jax.bham.infer;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import org.jax.bham.project.BhamProject;
import org.jax.haplotype.analysis.GenotypeInferencePhylogenyDataSource;
import org.jax.haplotype.data.GenomeDataSource;
import org.jax.util.gui.MessageDialogUtilities;
public class InferPhylogenyDialog extends JDialog
{
private static final Logger LOG = Logger.getLogger(
InferPhylogenyDialog.class.getName());
private final BhamProject project;
public InferPhylogenyDialog(Frame parent, BhamProject project)
{
super(parent, "Infer Perfect Phylogeny Trees", false);
this.project = project;
this.initComponents();
this.postGuiInit();
}
private void postGuiInit()
{
this.helpButton.addActionListener(new ActionListener()
{
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent e)
{
InferPhylogenyDialog.this.showHelp();
}
});
this.okButton.addActionListener(new ActionListener()
{
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent e)
{
InferPhylogenyDialog.this.ok();
}
});
this.cancelButton.addActionListener(new ActionListener()
{
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent e)
{
InferPhylogenyDialog.this.cancel();
}
});
for(GenomeDataSource genomeDataSource: this.project.getGenomeDataSources())
{
this.genotypeDataSourceComboBox.addItem(genomeDataSource);
}
}
private void ok()
{
try
{
if(this.validateData())
{
GenotypeInferencePhylogenyDataSource phylogenyDataSource =
new GenotypeInferencePhylogenyDataSource(
this.nameTextField.getText().trim(),
this.getSelectedGenomeDataSource());
this.project.addPhylogenyDataSource(phylogenyDataSource);
this.dispose();
}
}
catch(Exception ex)
{
String title = "Failed to Infer Phylogenies";
LOG.log(Level.SEVERE,
title,
ex);
MessageDialogUtilities.error(
this,
ex.getMessage(),
title);
}
}
private boolean validateData()
{
String errorMessage = null;
if(this.getSelectedGenomeDataSource() == null)
{
errorMessage = "No Genotype Data Source is Selected";
}
else if(this.nameTextField.getText().trim().length() == 0)
{
errorMessage =
"Please enter a name for the phylogeny data before continuing";
}
if(errorMessage == null)
{
return true;
}
else
{
MessageDialogUtilities.error(
this,
errorMessage,
"Validation Failed");
return false;
}
}
private void cancel()
{
this.dispose();
}
private void showHelp()
{
MessageDialogUtilities.inform(
this,
"Sorry, no help yet..",
"Help Not Implemented");
}
private GenomeDataSource getSelectedGenomeDataSource()
{
return (GenomeDataSource)this.genotypeDataSourceComboBox.getSelectedItem();
}
/**
* This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("all")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
nameLabel = new javax.swing.JLabel();
nameTextField = new javax.swing.JTextField();
genotypeDataSourceLabel = new javax.swing.JLabel();
genotypeDataSourceComboBox = new javax.swing.JComboBox();
actionPanel = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
helpButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
nameLabel.setText("Name Phylogeny Data:");
genotypeDataSourceLabel.setText("Genotype Data Source:");
okButton.setText("OK");
actionPanel.add(okButton);
cancelButton.setText("Cancel");
actionPanel.add(cancelButton);
helpButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help-16x16.png"))); // NOI18N
helpButton.setText("Help...");
actionPanel.add(helpButton);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, actionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(nameLabel)
.add(genotypeDataSourceLabel))
.add(19, 19, 19)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.add(27, 27, 27))
.add(layout.createSequentialGroup()
.add(genotypeDataSourceComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 130, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(nameLabel)
.add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(genotypeDataSourceLabel)
.add(genotypeDataSourceComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 8, Short.MAX_VALUE)
.add(actionPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel actionPanel;
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox genotypeDataSourceComboBox;
private javax.swing.JLabel genotypeDataSourceLabel;
private javax.swing.JButton helpButton;
private javax.swing.JLabel nameLabel;
private javax.swing.JTextField nameTextField;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}