package com.compomics.util.gui.parameters.identification_parameters;
import com.compomics.util.preferences.IdentificationParameters;
import java.awt.Dialog;
import javax.swing.JOptionPane;
/**
*
* @author Marc Vaudel
*/
public class IdentificationParametersNameDialog extends javax.swing.JDialog {
/**
* The parent frame.
*/
private java.awt.Frame parentFrame;
/**
* 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;
/**
* The original description.
*/
private String originalDescription;
/**
* Creates a new IdentificationParametersNameDialog with a frame as owner.
*
* @param parentFrame a parent frame
* @param identificationParameters the identification parameters to display
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public IdentificationParametersNameDialog(java.awt.Frame parentFrame, IdentificationParameters identificationParameters, boolean editable) {
super(parentFrame, true);
this.parentFrame = parentFrame;
this.editable = editable;
initComponents();
setUpGui();
populateGUI(identificationParameters);
setLocationRelativeTo(parentFrame);
setVisible(true);
}
/**
* Creates a new IdentificationParametersNameDialog with a dialog as owner.
*
* @param owner the dialog owner
* @param parentFrame a parent frame
* @param identificationParameters the identification parameters to display
* @param editable boolean indicating whether the settings can be edited by
* the user
*/
public IdentificationParametersNameDialog(Dialog owner, java.awt.Frame parentFrame, IdentificationParameters identificationParameters, boolean editable) {
super(owner, true);
this.parentFrame = parentFrame;
this.editable = editable;
initComponents();
setUpGui();
populateGUI(identificationParameters);
setLocationRelativeTo(owner);
setVisible(true);
}
/**
* Set up the GUI.
*/
private void setUpGui() {
nameTxt.setEditable(editable);
nameTxt.setEnabled(editable);
descriptionTxt.setEditable(editable);
descriptionTxt.setEnabled(editable);
}
/**
* Fills the GUI with the given settings.
*
* @param identificationParameters the identification parameters to display
*/
private void populateGUI(IdentificationParameters identificationParameters) {
nameTxt.setText(identificationParameters.getName());
originalDescription = identificationParameters.getDescription();
descriptionTxt.setText(originalDescription);
}
/**
* Indicates whether the user canceled the editing.
*
* @return a boolean indicating whether the user canceled the editing
*/
public boolean isCanceled() {
return canceled;
}
/**
* Updates the given identification parameters attributes.
*
* @param identificationParameters the identification parameters to update
*/
public void updateParameters(IdentificationParameters identificationParameters) {
identificationParameters.setName(nameTxt.getText());
String newDescription = descriptionTxt.getText();
if (!originalDescription.equals(newDescription)) {
identificationParameters.setDescription(newDescription, false);
}
}
/**
* Validates the user input.
*
* @return a boolean indicating whether the user input is valid
*/
public boolean validateInput() {
String name = nameTxt.getText();
for (char character : name.toCharArray()) {
String charAsString = character + "";
if (charAsString.matches("[^\\dA-Za-z ]")) {
JOptionPane.showMessageDialog(this, "Unsupported character in parameters name (" + character + "). Please avoid special characters in parameters name.",
"Special Character", JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
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();
attributesPanel = new javax.swing.JPanel();
decriptionLbl = new javax.swing.JLabel();
nameTxt = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
descriptionTxt = new javax.swing.JTextArea();
nameLbl = new javax.swing.JLabel();
cancelButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
backgroundPanel.setBackground(new java.awt.Color(230, 230, 230));
attributesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters Attributes"));
attributesPanel.setOpaque(false);
decriptionLbl.setText("Description");
descriptionTxt.setColumns(20);
descriptionTxt.setRows(5);
jScrollPane1.setViewportView(descriptionTxt);
nameLbl.setText("Name");
javax.swing.GroupLayout attributesPanelLayout = new javax.swing.GroupLayout(attributesPanel);
attributesPanel.setLayout(attributesPanelLayout);
attributesPanelLayout.setHorizontalGroup(
attributesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(attributesPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(attributesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(attributesPanelLayout.createSequentialGroup()
.addGroup(attributesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(attributesPanelLayout.createSequentialGroup()
.addComponent(nameLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(nameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(decriptionLbl))
.addGap(0, 87, Short.MAX_VALUE)))
.addContainerGap())
);
attributesPanelLayout.setVerticalGroup(
attributesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(attributesPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(attributesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nameLbl)
.addComponent(nameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(decriptionLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
.addContainerGap())
);
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);
}
});
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(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addGap(0, 0, 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())
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addComponent(attributesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 10, Short.MAX_VALUE))))
);
backgroundPanelLayout.setVerticalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(attributesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.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
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
canceled = true;
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
dispose();
}//GEN-LAST:event_okButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel attributesPanel;
private javax.swing.JPanel backgroundPanel;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel decriptionLbl;
private javax.swing.JTextArea descriptionTxt;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel nameLbl;
private javax.swing.JTextField nameTxt;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}