package com.compomics.util.gui.parameters.identification_parameters.algorithm_settings; import com.compomics.util.examples.BareBonesBrowserLaunch; import com.compomics.util.experiment.identification.identification_parameters.IdentificationAlgorithmParameter; import com.compomics.util.experiment.identification.identification_parameters.tool_specific.PepnovoParameters; import com.compomics.util.gui.parameters.identification_parameters.AlgorithmSettingsDialog; import java.awt.Dialog; import javax.swing.SwingConstants; /** * Dialog for editing the PepNovo advanced settings. * * @author Harald Barsnes */ public class PepNovoSettingsDialog extends javax.swing.JDialog implements AlgorithmSettingsDialog { /** * True if the dialog was canceled by the user. */ private boolean canceled = false; /** * Boolean indicating whether the settings can be edited by the user. */ private boolean editable; /** * Creates a new PepNovoSettingsDialog with a frame as owner. * * @param parent the parent frame * @param pepNovoParameters the PepNovo parameters * @param editable boolean indicating whether the settings can be edited by * the user */ public PepNovoSettingsDialog(java.awt.Frame parent, PepnovoParameters pepNovoParameters, boolean editable) { super(parent, true); this.editable = editable; initComponents(); setUpGUI(); populateGUI(pepNovoParameters); setLocationRelativeTo(parent); setVisible(true); } /** * Creates a new PepNovoSettingsDialog with a dialog as owner. * * @param owner the dialog owner * @param parent the parent frame * @param pepnovoParameters the PepNovo parameters * @param editable boolean indicating whether the settings can be edited by * the user */ public PepNovoSettingsDialog(Dialog owner, java.awt.Frame parent, PepnovoParameters pepnovoParameters, boolean editable) { super(owner, true); this.editable = editable; initComponents(); setUpGUI(); populateGUI(pepnovoParameters); setLocationRelativeTo(owner); setVisible(true); } /** * Sets up the GUI. */ private void setUpGUI() { correctPrecursorMassCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER)); estimateChargeCmb.setRenderer(new com.compomics.util.gui.renderers.AlignedListCellRenderer(SwingConstants.CENTER)); } /** * Populates the GUI using the given settings. * * @param pepnovoParameters the PepNovo parameters */ private void populateGUI(PepnovoParameters pepnovoParameters) { hitListLengthSpinner.setValue(pepnovoParameters.getHitListLength()); if (pepnovoParameters.isCorrectPrecursorMass()) { correctPrecursorMassCmb.setSelectedIndex(1); } else { correctPrecursorMassCmb.setSelectedIndex(0); } if (pepnovoParameters.isEstimateCharge()) { estimateChargeCmb.setSelectedIndex(1); } else { estimateChargeCmb.setSelectedIndex(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("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { backgroundPanel = new javax.swing.JPanel(); pepNovoPanel = new javax.swing.JPanel(); hitListLengthLabel = new javax.swing.JLabel(); hitListLengthSpinner = new javax.swing.JSpinner(); correctPrecursorMassLabel = new javax.swing.JLabel(); correctPrecursorMassCmb = new javax.swing.JComboBox(); estimateChargeLabel = new javax.swing.JLabel(); estimateChargeCmb = new javax.swing.JComboBox(); openDialogHelpJButton = new javax.swing.JButton(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("PepNovo+ Advanced Settings"); 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)); pepNovoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("PepNovo+ Settings")); pepNovoPanel.setOpaque(false); hitListLengthLabel.setText("Hit List Length"); hitListLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(10, 1, 2000, 1)); correctPrecursorMassLabel.setText("Correct Precursor Mass"); correctPrecursorMassCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes", "No" })); estimateChargeLabel.setText("Estimate Charge"); estimateChargeCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes", "No" })); javax.swing.GroupLayout pepNovoPanelLayout = new javax.swing.GroupLayout(pepNovoPanel); pepNovoPanel.setLayout(pepNovoPanelLayout); pepNovoPanelLayout.setHorizontalGroup( pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pepNovoPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pepNovoPanelLayout.createSequentialGroup() .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(correctPrecursorMassLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(estimateChargeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(estimateChargeCmb, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(correctPrecursorMassCmb, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pepNovoPanelLayout.createSequentialGroup() .addComponent(hitListLengthLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(hitListLengthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pepNovoPanelLayout.setVerticalGroup( pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pepNovoPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(hitListLengthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(hitListLengthLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(correctPrecursorMassCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(correctPrecursorMassLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pepNovoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(estimateChargeCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(estimateChargeLabel)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); openDialogHelpJButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/help.GIF"))); // NOI18N openDialogHelpJButton.setToolTipText("Open the PepNovo+ web page"); openDialogHelpJButton.setBorder(null); openDialogHelpJButton.setBorderPainted(false); openDialogHelpJButton.setContentAreaFilled(false); openDialogHelpJButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { openDialogHelpJButtonMouseEntered(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { openDialogHelpJButtonMouseExited(evt); } }); openDialogHelpJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { openDialogHelpJButtonActionPerformed(evt); } }); okButton.setText("OK"); 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(backgroundPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(backgroundPanelLayout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(openDialogHelpJButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) .addComponent(pepNovoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .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(pepNovoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(openDialogHelpJButton) .addComponent(okButton) .addComponent(cancelButton)) .addContainerGap()) ); 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.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); 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 boolean valid = validateParametersInput(true); if (valid) { dispose(); } }//GEN-LAST:event_okButtonActionPerformed /** * Close the dialog without saving the settings. * * @param evt */ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed canceled = true; dispose(); }//GEN-LAST:event_cancelButtonActionPerformed /** * Change the cursor into a hand cursor. * * @param evt */ private void openDialogHelpJButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openDialogHelpJButtonMouseEntered setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); }//GEN-LAST:event_openDialogHelpJButtonMouseEntered /** * Change the cursor back to the default cursor. * * @param evt */ private void openDialogHelpJButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openDialogHelpJButtonMouseExited setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); }//GEN-LAST:event_openDialogHelpJButtonMouseExited /** * Open the PepNovo+ web page. * * @param evt */ private void openDialogHelpJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDialogHelpJButtonActionPerformed setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); BareBonesBrowserLaunch.openURL("http://proteomics.ucsd.edu/Software/PepNovo/"); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); }//GEN-LAST:event_openDialogHelpJButtonActionPerformed /** * Close the dialog without saving the settings. * * @param evt */ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing cancelButtonActionPerformed(null); }//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 correctPrecursorMassCmb; private javax.swing.JLabel correctPrecursorMassLabel; private javax.swing.JComboBox estimateChargeCmb; private javax.swing.JLabel estimateChargeLabel; private javax.swing.JLabel hitListLengthLabel; private javax.swing.JSpinner hitListLengthSpinner; private javax.swing.JButton okButton; private javax.swing.JButton openDialogHelpJButton; private javax.swing.JPanel pepNovoPanel; // End of variables declaration//GEN-END:variables /** * Inspects the parameters validity. * * @param showMessage if true an error messages are shown to the users * @return a boolean indicating if the parameters are valid */ public boolean validateParametersInput(boolean showMessage) { boolean valid = true; okButton.setEnabled(valid); return valid; } /** * Returns the PepNovo+ parameters as set by the user. * * @return the PepNovo+ parameters */ public PepnovoParameters getInput() { PepnovoParameters pepNovoParameters = new PepnovoParameters(); pepNovoParameters.setHitListLength((Integer) hitListLengthSpinner.getValue()); pepNovoParameters.setCorrectPrecursorMass(correctPrecursorMassCmb.getSelectedIndex() == 1); pepNovoParameters.setEstimateCharge(estimateChargeCmb.getSelectedIndex() == 0); return pepNovoParameters; } @Override public boolean isCancelled() { return canceled; } @Override public IdentificationAlgorithmParameter getParameters() { return getInput(); } }