/*
* Copyright (c) 2009 The Jackson Laboratory
*
* This software was developed by Gary Churchill's Lab at The Jackson
* Laboratory (see http://research.jax.org/faculty/churchill).
*
* 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.qtl.fit.gui;
import javax.swing.JOptionPane;
import org.jax.qtl.cross.Cross;
import org.jax.qtl.cross.QtlBasket;
import org.jax.qtl.project.QtlProjectManager;
import org.jax.util.TextWrapper;
/**
* A dialog for creating a new QTL basket
* @author <A HREF="mailto:keith.sheppard@jax.org">Keith Sheppard</A>
*/
public class CreateNewQtlBasketDialog extends javax.swing.JDialog
{
/**
* every {@link java.io.Serializable} is supposed to have one of these
*/
private static final long serialVersionUID = -5239580847828999892L;
/**
* Constructor
* @param parent
* the parent frame for this dialog
* @param selectedCross
* the initially selected cross
* @param selectableCrosses
* the crosses that the user is allowed to select from
*/
public CreateNewQtlBasketDialog(
java.awt.Frame parent,
Cross selectedCross,
Cross[] selectableCrosses)
{
super(parent, true);
this.initComponents();
for(Cross currCross: selectableCrosses)
{
this.crossComboBox.addItem(currCross);
}
if(selectedCross != null)
{
this.crossComboBox.setSelectedItem(selectedCross);
}
}
/**
* For validating the user inputs before accepting them
* @return
* true iff the validation is successful
*/
private boolean createNewQtlBasket()
{
String validationErrorMessage = null;
Cross selectedCross = this.getSelectedCross();
String qtlBasketName = this.getQtlBasketName();
if(selectedCross == null)
{
validationErrorMessage =
"Cannot create a QTL basket because no cross is selected";
}
else if(qtlBasketName.length() == 0)
{
validationErrorMessage =
"The QTL basket name cannot be empty";
}
else if(selectedCross.getQtlBasketMap().containsKey(qtlBasketName))
{
validationErrorMessage =
"Basket name \"" + qtlBasketName +
"\" conflicts with an existing name";
}
else
{
QtlBasket newBasket = new QtlBasket(
selectedCross,
qtlBasketName);
selectedCross.getQtlBasketMap().put(
qtlBasketName,
newBasket);
QtlProjectManager.getInstance().notifyActiveProjectModified();
}
if(validationErrorMessage != null)
{
JOptionPane.showMessageDialog(
this,
TextWrapper.wrapText(
validationErrorMessage,
TextWrapper.DEFAULT_DIALOG_COLUMN_COUNT),
"Validation Failed",
JOptionPane.WARNING_MESSAGE);
return false;
}
else
{
return true;
}
}
/**
* Getter for the qtl basket name
* @return
* the qtl basket name
*/
private String getQtlBasketName()
{
return this.qtlBasketNameTextField.getText().trim();
}
/**
* Getter for the selected cross
* @return
* the selected cross or null if there is no selection
*/
private Cross getSelectedCross()
{
return (Cross)this.crossComboBox.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() {
javax.swing.JLabel crossLabel = new javax.swing.JLabel();
crossComboBox = new javax.swing.JComboBox();
javax.swing.JLabel qtlBasketNameLabel = new javax.swing.JLabel();
qtlBasketNameTextField = new javax.swing.JTextField();
javax.swing.JPanel actionPanel = new javax.swing.JPanel();
javax.swing.JButton okButton = new javax.swing.JButton();
javax.swing.JButton cancelButton = new javax.swing.JButton();
helpButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
crossLabel.setText("QTL Basket Cross:");
qtlBasketNameLabel.setText("QTL Basket Name:");
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
actionPanel.add(okButton);
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
actionPanel.add(cancelButton);
helpButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/action/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(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(crossLabel)
.add(qtlBasketNameLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(crossComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(qtlBasketNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
.addContainerGap())
.add(actionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(crossLabel)
.add(crossComboBox, 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(qtlBasketNameLabel)
.add(qtlBasketNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 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
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
if(this.createNewQtlBasket())
{
this.dispose();
}
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox crossComboBox;
private javax.swing.JButton helpButton;
private javax.swing.JTextField qtlBasketNameTextField;
// End of variables declaration//GEN-END:variables
}