package com.compomics.util.gui.parameters.identification_parameters;
import com.compomics.util.experiment.biology.Enzyme;
import com.compomics.util.experiment.biology.EnzymeFactory;
import java.awt.Dialog;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;
import javax.swing.SwingConstants;
/**
* Simple dialog for mapping a PRIDE enzyme to a utilities enzyme.
*
* @author Harald Barsnes
*/
public class EnzymeSelectionDialog extends javax.swing.JDialog {
/**
* The enzyme factory.
*/
private EnzymeFactory enzymeFactory = EnzymeFactory.getInstance();
/**
* True of the enzyme selection was canceled by the user.
*/
private boolean selectionCanceled = false;
/**
* Boolean indicating whether the settings can be edited by the user.
*/
private boolean editable;
/**
* Creates a new EnzymeSelectionDialog with a frame as owner.
*
* @param parent the parent frame
* @param modal if the dialog is to be modal or not
* @param enzymeName the PRIDE enzyme name
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public EnzymeSelectionDialog(java.awt.Frame parent, boolean modal, String enzymeName, boolean editable) {
super(parent, modal);
initComponents();
prideEnzymeNameTextField.setText(enzymeName);
enzymesCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER));
this.editable = editable;
setLocationRelativeTo(parent);
setVisible(true);
}
/**
* Creates a new EnzymeSelectionDialog with a dialog as owner.
*
* @param owner the dialog owner
* @param parent the parent frame
* @param modal if the dialog is to be modal or not
* @param enzymeName the PRIDE enzyme name
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public EnzymeSelectionDialog(Dialog owner, java.awt.Frame parent, boolean modal, String enzymeName, boolean editable) {
super(owner, modal);
initComponents();
prideEnzymeNameTextField.setText(enzymeName);
enzymesCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER));
this.editable = editable;
setLocationRelativeTo(owner);
setVisible(true);
}
/**
* Creates a new EnzymeSelectionDialog.
*
* @param parent the parent dialog
* @param modal if the dialog is to be modal or not
* @param enzymeName the PRIDE enzyme name
*/
public EnzymeSelectionDialog(JDialog parent, boolean modal, String enzymeName) {
super(parent, modal);
initComponents();
setUpGui();
populateGui(enzymeName);
setLocationRelativeTo(parent);
setVisible(true);
}
/**
* Sets up the GUI.
*/
private void setUpGui() {
enzymesCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER));
enzymesCmb.setEnabled(editable);
}
/**
* Populates the gui using the given annotation settings.
*
* @param annotationSettings the annotation settings to display
* @param possibleNeutralLosses the possible neutral losses
*/
private void populateGui(String enzymeName) {
prideEnzymeNameTextField.setText(enzymeName);
}
/**
* Returns the selected enzyme.
*
* @return the selected enzyme
*/
public Enzyme getEnzyme() {
if (!selectionCanceled) {
return enzymeFactory.getEnzyme(enzymesCmb.getSelectedItem().toString());
} else {
return null;
}
}
/**
* 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();
mappingPanel = new javax.swing.JPanel();
enzymesCmb = new javax.swing.JComboBox();
enzymeLabel = new javax.swing.JLabel();
prideEnzymeNameLabel = new javax.swing.JLabel();
prideEnzymeNameTextField = new javax.swing.JTextField();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Enzyme");
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));
mappingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Enzyme Selection"));
mappingPanel.setOpaque(false);
enzymesCmb.setModel(new DefaultComboBoxModel(loadEnzymes()));
enzymesCmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enzymesCmbActionPerformed(evt);
}
});
enzymeLabel.setText("Enzyme");
prideEnzymeNameLabel.setText("PRIDE");
prideEnzymeNameTextField.setEditable(false);
prideEnzymeNameTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
javax.swing.GroupLayout mappingPanelLayout = new javax.swing.GroupLayout(mappingPanel);
mappingPanel.setLayout(mappingPanelLayout);
mappingPanelLayout.setHorizontalGroup(
mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mappingPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(enzymeLabel)
.addComponent(prideEnzymeNameLabel))
.addGap(18, 18, 18)
.addGroup(mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(enzymesCmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(prideEnzymeNameTextField))
.addContainerGap())
);
mappingPanelLayout.setVerticalGroup(
mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mappingPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(prideEnzymeNameLabel)
.addComponent(prideEnzymeNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mappingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(enzymeLabel)
.addComponent(enzymesCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
okButton.setText("OK");
okButton.setEnabled(false);
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
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()
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mappingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addGap(0, 380, Short.MAX_VALUE)
.addComponent(okButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))
.addContainerGap())
);
backgroundPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
backgroundPanelLayout.setVerticalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mappingPanel, 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(okButton)
.addComponent(cancelButton))
.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
/**
* Close the dialog.
*
* @param evt
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
dispose();
setVisible(false);
}//GEN-LAST:event_okButtonActionPerformed
/**
* Close the dialog.
*
* @param evt
*/
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
selectionCanceled = true;
okButtonActionPerformed(null);
}//GEN-LAST:event_cancelButtonActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
cancelButtonActionPerformed(null);
}//GEN-LAST:event_formWindowClosing
/**
* Enable/disable the OK button.
*
* @param evt
*/
private void enzymesCmbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enzymesCmbActionPerformed
okButton.setEnabled(enzymesCmb.getSelectedIndex() > 0);
}//GEN-LAST:event_enzymesCmbActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel backgroundPanel;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel enzymeLabel;
private javax.swing.JComboBox enzymesCmb;
private javax.swing.JPanel mappingPanel;
private javax.swing.JButton okButton;
private javax.swing.JLabel prideEnzymeNameLabel;
private javax.swing.JTextField prideEnzymeNameTextField;
// End of variables declaration//GEN-END:variables
/**
* Loads the implemented enzymes.
*
* @return the list of enzyme names
*/
private String[] loadEnzymes() {
ArrayList<String> tempEnzymes = new ArrayList<String>();
for (int i = 0; i < enzymeFactory.getEnzymes().size(); i++) {
tempEnzymes.add(enzymeFactory.getEnzymes().get(i).getName());
}
Collections.sort(tempEnzymes);
String[] enzymes = new String[tempEnzymes.size() + 1];
enzymes[0] = "--- Select ---";
for (int i = 0; i < tempEnzymes.size(); i++) {
enzymes[i + 1] = tempEnzymes.get(i);
}
return enzymes;
}
}