@Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(decoyStrategy_pattern)
        || e.getSource().equals(decoyStrategy_searchengine)) {
      // decoy pattern can only be edited, if decoy strategy is pattern
      decoyPattern_pattern.setEnabled(decoyStrategy_pattern.isSelected());
    } else if (e.getSource().equals(addToPreferred_button)
        && (availableScoresList.getSelectedIndex() > -1)) {
      preferredScoresModel.addElement(availableScoresList.getSelectedValue());
      availableScoresModel.remove(availableScoresList.getSelectedIndex());
    } else if (e.getSource().equals(removeFromPreferred_button)
        && (preferredScoresList.getSelectedIndex() > -1)) {
      availableScoresModel.addElement(preferredScoresList.getSelectedValue());
      preferredScoresModel.remove(preferredScoresList.getSelectedIndex());
    } else if (e.getSource().equals(calculatePSMFDR)) {
      // execute PSM level operations
      if (piaViewModel != null) {
        for (Map.Entry<String, Object> setIt : getSettings().entrySet()) {
          piaViewModel.addSetting(setIt.getKey(), setIt.getValue());
        }
        piaViewModel.executePSMOperations();
      }

      updateFDRPanel();
    }
  }
  /** Paints the FDR information on the panel, if it is calculated */
  public void updateFDRPanel() {
    if (piaViewModel == null) {
      psmFDRPanel.removeAll();
      psmFDRPanel.add(new JLabel("No file loaded yet."));
    } else {
      psmFDRPanel.removeAll();

      GridBagConstraints cFDRPanel = new GridBagConstraints();
      cFDRPanel.fill = GridBagConstraints.HORIZONTAL;
      cFDRPanel.insets = new Insets(5, 5, 5, 5);

      JPanel overviewPanel = new JPanel(new GridBagLayout());
      overviewPanel.setBorder(BorderFactory.createTitledBorder("FDR for PSM sets / all files"));

      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.insets = new Insets(5, 5, 5, 5);

      // >> the information data --------------------
      JPanel fdrDataPanel = new JPanel(new GridBagLayout());

      if (piaViewModel.getPSMModeller().isCombinedFDRScoreCalculated()) {
        c.insets = new Insets(0, 5, 5, 5);
        c.gridx = 0;
        c.gridy = 0;
        fdrDataPanel.add(new JLabel("#PSM sets:"), c);
        c.gridx = 1;
        c.gridy = 0;
        fdrDataPanel.add(new JLabel("" + piaViewModel.getPSMModeller().getNrReportPSMs(0L)), c);

        FDRData fdrData = piaViewModel.getPSMModeller().getFilesFDRData(0L);

        c.gridx = 0;
        c.gridy = 1;
        fdrDataPanel.add(new JLabel("#PSM sets with FDR:"), c);
        c.gridx = 1;
        c.gridy = 1;
        fdrDataPanel.add(new JLabel("" + fdrData.getNrItems()), c);

        c.gridx = 0;
        c.gridy = 2;
        fdrDataPanel.add(new JLabel("#targets:"), c);
        c.gridx = 1;
        c.gridy = 2;
        fdrDataPanel.add(new JLabel("" + fdrData.getNrTargets()), c);

        c.gridx = 0;
        c.gridy = 3;
        fdrDataPanel.add(new JLabel("#decoys:"), c);
        c.gridx = 1;
        c.gridy = 3;
        fdrDataPanel.add(new JLabel("" + fdrData.getNrDecoys()), c);

        c.gridx = 0;
        c.gridy = 4;
        fdrDataPanel.add(new JLabel("#targets below threshold:"), c);
        c.gridx = 1;
        c.gridy = 4;
        fdrDataPanel.add(new JLabel("" + fdrData.getNrFDRGoodTargets()), c);

        c.gridx = 0;
        c.gridy = 5;
        fdrDataPanel.add(new JLabel("#decoys below threshold:"), c);
        c.gridx = 1;
        c.gridy = 5;
        fdrDataPanel.add(new JLabel("" + fdrData.getNrFDRGoodDecoys()), c);

        c.insets = new Insets(5, 5, 5, 5);
      } else {
        fdrDataPanel.add(new JLabel("<html>Combined FDR score<br/>was not calculated.</html>"), c);
      }

      c.gridx = 0;
      c.gridy = 0;
      overviewPanel.add(fdrDataPanel, c);
      // >> the information data --------------------

      // >> draw PPM deviation ----------------------
      /*
      VisualizePSM vPSM = new VisualizePSM(piaViewModel.getPSMModeller());

      HistogramDataset hd = vPSM.getPPMHistogramData(0l, piaViewModel.getPSMModeller().isCombinedFDRScoreCalculated());

      JFreeChart chart = ChartFactory.createHistogram("mass shift (PPM)",
      		null,
      		"nrPSMs",
      		hd,
      		PlotOrientation.VERTICAL,
      		false,
      		false,
      		false);

      chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 14));

      XYPlot plot = chart.getXYPlot();
      plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

            plot.getDomainAxis().setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
            plot.getRangeAxis().setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));

            plot.getRangeAxis().setLabelFont(new Font("Dialog", Font.BOLD, 12));

      XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
      renderer.setBarPainter(new StandardXYBarPainter());

      renderer.setDrawBarOutline(false);
      renderer.setShadowVisible(false);

      renderer.setSeriesPaint(0, new Color(47, 105, 191));

      JPanel ppmPanel = new ChartPanel(chart,
      		240, 140,
      		240, 140,
      		800, 600,
      		true, true, false, false, true, true);
      ppmPanel.setMinimumSize(new Dimension(240, 140));

      c.insets = new Insets(0, 0, 0, 0);
      c.gridx = 1;
      c.gridy = 0;
      overviewPanel.add(ppmPanel, c);
      */
      // << draw PPM deviation ----------------------

      cFDRPanel.gridx = 0;
      cFDRPanel.gridy = 0;
      psmFDRPanel.add(overviewPanel, cFDRPanel);
    }

    psmFDRPanel.validate();
    psmFDRPanel.repaint();
  }
  /** Sets recommended settings, based on the loaded PIA interemdiate data. */
  public void applyRecommendedSettings() {
    if (piaViewModel != null) {
      checkCreatePSMSets.setSelected(piaViewModel.getPSMModeller().getFiles().size() > 2);

      boolean allAllowStrategySearchengine = true;
      for (Long fileID : piaViewModel.getPSMModeller().getFiles().keySet()) {
        if (!piaViewModel.getPSMModeller().getFileHasInternalDecoy(fileID)) {
          allAllowStrategySearchengine = false;
          break;
        }
      }

      if (allAllowStrategySearchengine) {
        decoyStrategy_searchengine.setSelected(true);
      } else {
        decoyStrategy_searchengine.setText("by searchengine (files without internal decoys)");
        decoyStrategy_searchengine.setEnabled(false);
        decoyStrategy_pattern.setSelected(true);
      }

      preferredScoresModel.removeAllElements();
      availableScoresModel.removeAllElements();
      for (Long fileID : piaViewModel.getPSMModeller().getFiles().keySet()) {
        for (String scoreShort :
            piaViewModel.getPSMModeller().getFilesAvailableScoreShortsForFDR(fileID)) {

          ScoreModelEnum modelType = ScoreModelEnum.getModelByDescription(scoreShort);
          ScoreModel model;

          if (modelType.equals(ScoreModelEnum.UNKNOWN_SCORE)) {
            model =
                new ScoreModel(
                    0.0, scoreShort, piaViewModel.getPSMModeller().getScoreName(scoreShort));
          } else {
            model = new ScoreModel(0.0, modelType);
          }

          if (!ScoreModelEnum.getNotForPSMFdrScore().contains(model)) {
            if (modelType.isSearchengineMainScore()) {
              if (!preferredScoresModel.contains(model)) {
                preferredScoresModel.addElement(model);
              }
            } else {
              if (!availableScoresModel.contains(model)) {
                availableScoresModel.addElement(model);
              }
            }
          }
        }
      }

      calculatePSMFDR.setEnabled(true);
    } else {
      // the default settings
      checkCreatePSMSets.setSelected(true);

      decoyStrategy_pattern.setSelected(true);

      for (ScoreModelEnum model : ScoreModelEnum.values()) {
        if (!ScoreModelEnum.getNotForPSMFdrScore().contains(model)
            && !model.equals(ScoreModelEnum.UNKNOWN_SCORE)) {
          availableScoresModel.addElement(
              new ScoreModel(0.0, model.getShortName(), model.getName()));
        }
      }

      calculatePSMFDR.setEnabled(false);
    }
  }