public void actionPerformed(ActionEvent actionEvent) {
Object src = actionEvent.getSource();
Desktop desktop = MZmineCore.getDesktop();
if (src == buttonAddParameter) {
if (fieldName.getText().length() == 0) {
desktop.displayErrorMessage("Give a name for the parameter first.");
return;
}
String paramName = fieldName.getText();
UserParameter parameter = null;
if (radiobuttonNumerical.isSelected()) {
parameter = new DoubleParameter(paramName, null);
}
if (radiobuttonFreeText.isSelected()) {
parameter = new StringParameter(paramName, null);
}
if (radiobuttonCategorical.isSelected()) {
String[] possibleValues = new String[categories.size()];
if (possibleValues.length == 0) {
desktop.displayErrorMessage("Give at least a single parameter value.");
return;
}
for (int valueIndex = 0; valueIndex < categories.size(); valueIndex++)
possibleValues[valueIndex] = (String) categories
.get(valueIndex);
parameter = new ComboParameter<String>(paramName, null,
possibleValues);
}
mainDialog.addParameter(parameter);
dispose();
}
if (src == buttonCancel) {
dispose();
}
if ((src == radiobuttonNumerical) || (src == radiobuttonCategorical)
|| (src == radiobuttonFreeText)) {
if (radiobuttonCategorical.isSelected()) {
switchCategoricalFields(true);
} else {
switchCategoricalFields(false);
}
}
if (src == buttonAddCategory) {
String inputValue = JOptionPane
.showInputDialog("Please input a new value");
if ((inputValue == null) || (inputValue.trim().length() == 0))
return;
if (((DefaultListModel) listCategories.getModel())
.contains(inputValue)) {
desktop.displayErrorMessage("Value already exists.");
return;
}
((DefaultListModel) listCategories.getModel())
.addElement(inputValue);
}
if (src == buttonRemoveCategory) {
int[] selectedIndices = listCategories.getSelectedIndices();
if ((selectedIndices == null) || (selectedIndices.length == 0)) {
desktop.displayErrorMessage("Select at least one value first.");
return;
}
for (int selectedIndex : selectedIndices) {
((DefaultListModel) listCategories.getModel())