/*
* 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.scan.gui;
import java.awt.event.ItemEvent;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jax.qtl.scan.ScanCommandBuilder;
import org.jax.qtl.scan.ScanType;
/**
* Panel that edits the permutations portion of a scan command
* @author <A HREF="mailto:keith.sheppard@jax.org">Keith Sheppard</A>
*/
public class ScanPermutationsPanel extends ScanCommandEditorPanel
{
/**
* every {@link java.io.Serializable} is supposed to have one of these
*/
private static final long serialVersionUID = -5503455594080368863L;
/**
* the scan command that this panel edits
*/
private final ScanCommandBuilder scanCommand;
/**
* the spinner model for permutation counts
*/
private final SpinnerNumberModel permutationsCountModel;
/**
* Constructor
* @param scanCommand
* the command to edit
*/
public ScanPermutationsPanel(ScanCommandBuilder scanCommand)
{
this.scanCommand = scanCommand;
this.permutationsCountModel = new SpinnerNumberModel(
0,
0,
Integer.MAX_VALUE,
500);
this.initComponents();
this.postGuiInit();
}
/**
* Initialization code to run after the GUI builder code has completed
*/
private void postGuiInit()
{
// update the spinner model to behave how we want it to
this.permutationsCountSpinner.setModel(this.permutationsCountModel);
this.permutationsCountModel.addChangeListener(
new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
ScanPermutationsPanel.this.permutationsCountChanged();
}
});
this.permutationsCountChanged();
}
/**
* react to a change in the permutations count
*/
private void permutationsCountChanged()
{
int permutationsCount =
this.permutationsCountModel.getNumber().intValue();
this.scanCommand.setNumberOfPermutations(
permutationsCount);
this.refreshGui();
this.fireCommandModified();
}
/**
* This function tells this panel that a component other than itself
* has edited the {@link ScanCommandBuilder} and that we need to refresh
* our graphics to reflect those changes.
*/
public void refreshGui()
{
// this seperate x chromo option is only available for scan one
this.seperateXChromosomePermutationsCheckBox.setVisible(
this.scanCommand.getScanType() == ScanType.SCANONE);
// update the enabled property of the other check boxes based on
// whether or not we're performing permutations
int permutationsCount =
this.scanCommand.getNumberOfPermutations();
this.seperateXChromosomePermutationsCheckBox.setEnabled(
permutationsCount > 0);
this.verboseOutputCheckBox.setEnabled(
permutationsCount > 0);
}
/**
* 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() {
permutationsCountLabel = new javax.swing.JLabel();
permutationsCountSpinner = new javax.swing.JSpinner();
verboseOutputCheckBox = new javax.swing.JCheckBox();
seperateXChromosomePermutationsCheckBox = new javax.swing.JCheckBox();
permutationsCountLabel.setText("Number of Permutations to Perform:");
permutationsCountSpinner.setMinimumSize(new java.awt.Dimension(100, 24));
permutationsCountSpinner.setPreferredSize(new java.awt.Dimension(100, 24));
verboseOutputCheckBox.setText("Print Permutations Progress to Console");
verboseOutputCheckBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
verboseOutputCheckBoxItemStateChanged(evt);
}
});
seperateXChromosomePermutationsCheckBox.setText("Seperate Permutations for X Chromosome");
seperateXChromosomePermutationsCheckBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
seperateXChromosomePermutationsCheckBoxItemStateChanged(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(permutationsCountLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(permutationsCountSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(seperateXChromosomePermutationsCheckBox)
.add(verboseOutputCheckBox))
.addContainerGap(227, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(permutationsCountLabel)
.add(permutationsCountSpinner, 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(seperateXChromosomePermutationsCheckBox)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(verboseOutputCheckBox))
);
}// </editor-fold>//GEN-END:initComponents
private void seperateXChromosomePermutationsCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_seperateXChromosomePermutationsCheckBoxItemStateChanged
this.scanCommand.setSeperatePermutationsForAutosome(
evt.getStateChange() == ItemEvent.SELECTED);
this.fireCommandModified();
}//GEN-LAST:event_seperateXChromosomePermutationsCheckBoxItemStateChanged
private void verboseOutputCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_verboseOutputCheckBoxItemStateChanged
this.scanCommand.setVerbosePermutationsOutput(
evt.getStateChange() == ItemEvent.SELECTED);
this.fireCommandModified();
}//GEN-LAST:event_verboseOutputCheckBoxItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel permutationsCountLabel;
private javax.swing.JSpinner permutationsCountSpinner;
private javax.swing.JCheckBox seperateXChromosomePermutationsCheckBox;
private javax.swing.JCheckBox verboseOutputCheckBox;
// End of variables declaration//GEN-END:variables
/**
* {@inheritDoc}
*/
@Override
protected ScanCommandBuilder getScanCommand()
{
return this.scanCommand;
}
}