/** Set up the GUI. */
 private void setUpGui() {
   reagentsTableJScrollPane.getViewport().setOpaque(false);
   reagentsTable.getTableHeader().setReorderingAllowed(false);
   if (newDialog.getMethodsFile() != null) {
     txtConfigurationFileLocation.setText(newDialog.getMethodsFile().getAbsolutePath());
   } else {
     txtConfigurationFileLocation.setText("(not saved to file)");
   }
   reagentsTable.getColumnModel().getColumn(0).setMaxWidth(30);
   reagentsTable.getColumnModel().getColumn(1).setMaxWidth(100);
 }
  /**
   * Opens a file chooser for importing method settings.
   *
   * @param evt
   */
  private void browseConfigButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_browseConfigButtonActionPerformed

    if (txtConfigurationFileLocation.getText().length() > 0) {
      newDialog
          .getReporterGui()
          .getLastSelectedFolder()
          .setLastSelectedFolder(txtConfigurationFileLocation.getText());
    }

    File selectedFile =
        Util.getUserSelectedFile(
            this,
            ".xml",
            "Reporter Method File (*.xml)",
            "Select Settings File",
            newDialog.getReporterGui().getLastSelectedFolder().getLastSelectedFolder(),
            null,
            true);

    if (selectedFile != null) {
      try {
        methodsFactory.importMethods(selectedFile);
        newDialog.setSelectedMethod(newDialog.getMethod(newDialog.getSelectedMethod().getName()));
        newDialog.setReagents(newDialog.getSelectedMethod().getReagentsSortedByMass());
        refresh();
        txtConfigurationFileLocation.setText(selectedFile.getAbsolutePath());
        newDialog.setMethodsFile(selectedFile);
        newDialog
            .getReporterGui()
            .getLastSelectedFolder()
            .setLastSelectedFolder(selectedFile.getPath());
      } catch (IOException e) {
        JOptionPane.showMessageDialog(
            null,
            "File " + selectedFile.getAbsolutePath() + " not found.",
            "File Not Found",
            JOptionPane.WARNING_MESSAGE);
      } catch (XmlPullParserException e) {
        JOptionPane.showMessageDialog(
            null,
            "An error occurred while parsing "
                + selectedFile.getAbsolutePath()
                + " at line "
                + e.getLineNumber()
                + ".",
            "Parsing Error",
            JOptionPane.WARNING_MESSAGE);
        e.printStackTrace();
      }
    }
  } // GEN-LAST:event_browseConfigButtonActionPerformed
  /**
   * Save the method settings.
   *
   * @param evt
   */
  private void saveConfigButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_saveConfigButtonActionPerformed

    String tempFileName = null;
    if (txtConfigurationFileLocation.getText().length() > 0) {
      newDialog
          .getReporterGui()
          .getLastSelectedFolder()
          .setLastSelectedFolder(txtConfigurationFileLocation.getText());
      tempFileName = new File(txtConfigurationFileLocation.getText()).getName();
    }

    File selectedFile =
        Util.getUserSelectedFile(
            this,
            ".xml",
            "Reporter Method File (*.xml)",
            "Save Settings File",
            newDialog.getReporterGui().getLastSelectedFolder().getLastSelectedFolder(),
            tempFileName,
            false);

    if (selectedFile != null) {
      try {
        methodsFactory.saveFile(selectedFile);
        newDialog.setMethodsFile(selectedFile);
        txtConfigurationFileLocation.setText(selectedFile.getAbsolutePath());
        valuesChanged = false;
        JOptionPane.showMessageDialog(
            null,
            "Settings saved to " + selectedFile.getAbsolutePath() + ".",
            "Settings Saved",
            JOptionPane.INFORMATION_MESSAGE);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            null,
            "An error occured when saving the file.",
            "File Error",
            JOptionPane.WARNING_MESSAGE);
        ex.printStackTrace();
      }
    }
  } // GEN-LAST:event_saveConfigButtonActionPerformed
  /**
   * Close the dialog.
   *
   * @param evt
   */
  private void okButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_okButtonActionPerformed

    if (valuesChanged) {
      int selection =
          JOptionPane.showConfirmDialog(
              this,
              "Do you want to save the new settings to a file?",
              "Save File?",
              JOptionPane.YES_NO_CANCEL_OPTION);
      if (selection == JOptionPane.YES_OPTION) {
        saveConfigButtonActionPerformed(null);
      } else if (selection == JOptionPane.CANCEL_OPTION) {
        return;
      } else if (selection == JOptionPane.NO_OPTION) {
        newDialog.setMethodsFile(null);
      }
    }

    newDialog.updateReagentNames();
    dispose();
  } // GEN-LAST:event_okButtonActionPerformed