package com.compomics.util.gui.parameters.identification_parameters;
import com.compomics.util.experiment.identification.protein_inference.PeptideMapperType;
import com.compomics.util.preferences.SequenceMatchingPreferences;
import java.awt.Dialog;
import javax.swing.DefaultComboBoxModel;
import javax.swing.SwingConstants;
/**
* Dialog for the edition of the sequence matching settings.
*
* @author Marc Vaudel
* @author Harald Barsnes
*/
public class SequenceMatchingSettingsDialog extends javax.swing.JDialog {
/**
* Boolean indicating whether the user canceled the editing.
*/
private boolean canceled = false;
/**
* Boolean indicating whether the settings can be edited by the user.
*/
private boolean editable;
/**
* Creates a new SequenceMatchingSettingsDialog with a frame as owner.
*
* @param parentFrame a parent frame
* @param sequenceMatchingPreferences the sequence matching preferences to
* display
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public SequenceMatchingSettingsDialog(java.awt.Frame parentFrame, SequenceMatchingPreferences sequenceMatchingPreferences, boolean editable) {
super(parentFrame, true);
this.editable = editable;
initComponents();
setUpGui();
populateGUI(sequenceMatchingPreferences);
setLocationRelativeTo(parentFrame);
setVisible(true);
}
/**
* Creates a new SequenceMatchingSettingsDialog with a dialog as owner.
*
* @param owner the dialog owner
* @param parentFrame a parent frame
* @param sequenceMatchingPreferences the sequence matching preferences to
* display
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public SequenceMatchingSettingsDialog(Dialog owner, java.awt.Frame parentFrame, SequenceMatchingPreferences sequenceMatchingPreferences, boolean editable) {
super(owner, true);
this.editable = editable;
initComponents();
setUpGui();
populateGUI(sequenceMatchingPreferences);
setLocationRelativeTo(owner);
setVisible(true);
}
/**
* Set up the GUI.
*/
private void setUpGui() {
matchingCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER));
matchingCmb.setEnabled(editable);
indexTypeCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER));
indexTypeCmb.setEnabled(editable);
xSpinner.setEnabled(editable);
}
/**
* Fills the GUI with the given settings.
*
* @param sequenceMatchingPreferences the sequence matching preferences to
* display
*/
private void populateGUI(SequenceMatchingPreferences sequenceMatchingPreferences) {
SequenceMatchingPreferences.MatchingType matchingType = sequenceMatchingPreferences.getSequenceMatchingType();
matchingCmb.setSelectedItem(matchingType);
PeptideMapperType peptideMapperType = sequenceMatchingPreferences.getPeptideMapperType();
indexTypeCmb.setSelectedItem(peptideMapperType);
xSpinner.setValue(sequenceMatchingPreferences.getLimitX());
}
/**
* Indicates whether the user canceled the editing.
*
* @return a boolean indicating whether the user canceled the editing
*/
public boolean isCanceled() {
return canceled;
}
/**
* Returns the sequence matching settings as set by the user.
*
* @return the sequence matching settings as set by the user
*/
public SequenceMatchingPreferences getSequenceMatchingPreferences() {
SequenceMatchingPreferences sequenceMatchingPreferences = new SequenceMatchingPreferences();
sequenceMatchingPreferences.setPeptideMapperType((PeptideMapperType) indexTypeCmb.getSelectedItem());
sequenceMatchingPreferences.setSequenceMatchingType((SequenceMatchingPreferences.MatchingType) matchingCmb.getSelectedItem());
sequenceMatchingPreferences.setLimitX((Double) xSpinner.getValue());
return sequenceMatchingPreferences;
}
/**
* Validates the user input.
*
* @return a boolean indicating whether the user input is valid
*/
public boolean validateInput() {
return true;
}
/**
* 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("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
backgroundPanel = new javax.swing.JPanel();
cancelButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
sequenceMatchingPanel = new javax.swing.JPanel();
matchingMethodLbl = new javax.swing.JLabel();
xLbl = new javax.swing.JLabel();
matchingCmb = new javax.swing.JComboBox();
xSpinner = new javax.swing.JSpinner();
indexTypeCmb = new javax.swing.JComboBox();
indexTypeLbl = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Sequence Matching");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
backgroundPanel.setBackground(new java.awt.Color(230, 230, 230));
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
sequenceMatchingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));
sequenceMatchingPanel.setOpaque(false);
matchingMethodLbl.setText("Matching Method");
xLbl.setText("Maximum Share of X's");
matchingCmb.setModel(new DefaultComboBoxModel(SequenceMatchingPreferences.MatchingType.values()));
xSpinner.setModel(new javax.swing.SpinnerNumberModel(0.25d, 0.0d, 1.0d, 0.1d));
indexTypeCmb.setModel(new DefaultComboBoxModel(PeptideMapperType.values()));
indexTypeLbl.setText("Index Type");
javax.swing.GroupLayout sequenceMatchingPanelLayout = new javax.swing.GroupLayout(sequenceMatchingPanel);
sequenceMatchingPanel.setLayout(sequenceMatchingPanelLayout);
sequenceMatchingPanelLayout.setHorizontalGroup(
sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(sequenceMatchingPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(matchingMethodLbl)
.addComponent(xLbl)
.addComponent(indexTypeLbl))
.addGap(18, 18, 18)
.addGroup(sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(indexTypeCmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(matchingCmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(xSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE))
.addContainerGap())
);
sequenceMatchingPanelLayout.setVerticalGroup(
sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sequenceMatchingPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(indexTypeLbl)
.addComponent(indexTypeCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(matchingMethodLbl)
.addComponent(matchingCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(sequenceMatchingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(xLbl)
.addComponent(xSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
backgroundPanel.setLayout(backgroundPanelLayout);
backgroundPanelLayout.setHorizontalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(sequenceMatchingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addGap(0, 313, Short.MAX_VALUE)
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))
.addContainerGap())
);
backgroundPanelLayout.setVerticalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(sequenceMatchingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Save the settings and close the dialog.
*
* @param evt
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
if (validateInput()) {
dispose();
}
}//GEN-LAST:event_okButtonActionPerformed
/**
* Close the dialog without saving.
*
* @param evt
*/
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
canceled = true;
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
/**
* Close the dialog without saving.
*
* @param evt
*/
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
canceled = true;
}//GEN-LAST:event_formWindowClosing
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel backgroundPanel;
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox indexTypeCmb;
private javax.swing.JLabel indexTypeLbl;
private javax.swing.JComboBox matchingCmb;
private javax.swing.JLabel matchingMethodLbl;
private javax.swing.JButton okButton;
private javax.swing.JPanel sequenceMatchingPanel;
private javax.swing.JLabel xLbl;
private javax.swing.JSpinner xSpinner;
// End of variables declaration//GEN-END:variables
}