Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 49.52 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  *
  3.  */
  4. package framework.ui;
  5.  
  6. import java.awt.Color;
  7. import java.awt.Component;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.FocusEvent;
  10. import java.awt.event.FocusListener;
  11. import java.awt.event.KeyEvent;
  12. import java.io.File;
  13. import java.io.FileNotFoundException;
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Map.Entry;
  20.  
  21. import javax.swing.AbstractAction;
  22. import javax.swing.Action;
  23. import javax.swing.BorderFactory;
  24. import javax.swing.JButton;
  25. import javax.swing.JCheckBox;
  26. import javax.swing.JComboBox;
  27. import javax.swing.JEditorPane;
  28. import javax.swing.JFileChooser;
  29. import javax.swing.JLabel;
  30. import javax.swing.JMenuItem;
  31. import javax.swing.JOptionPane;
  32. import javax.swing.JPanel;
  33. import javax.swing.JScrollPane;
  34. import javax.swing.ListSelectionModel;
  35. import javax.swing.event.ListSelectionEvent;
  36. import javax.swing.event.ListSelectionListener;
  37. import javax.swing.table.DefaultTableModel;
  38. import javax.swing.table.TableCellRenderer;
  39. import javax.swing.table.TableModel;
  40.  
  41. import org.jdesktop.swingx.JXTable;
  42. import org.jfree.ui.ExtensionFileFilter;
  43.  
  44. import framework.data.Current;
  45. import framework.data.Result;
  46. import framework.data.ResultIOManager;
  47. import framework.data.Tuple;
  48. import framework.data.Data.DataObject;
  49. import framework.exceptions.NonFittingResultException;
  50. import framework.exceptions.UnsupportedFileVersionException;
  51. import framework.visualization.PlotContainer;
  52. import framework.visualization.PlotData;
  53. import framework.visualization.Plotter;
  54. import framework.visualization.VisualizationFrame;
  55.  
  56.  
  57. /**
  58.  * This class implements a base framework tab that provides OM result management
  59.  * functionality for the static Current class, including the ability to start
  60.  * visualization of results as well as result import and export.
  61.  *
  62.  * @author Rene Glebke, Matthias Hannen
  63.  */
  64. public final class VisualizationTab extends Tab implements FocusListener {
  65.  
  66.         /** Table listing the attributes of the dataset. */
  67.         private JXTable attributesTable = null;
  68.  
  69.         /** Table listing the selected data. */
  70.         private JXTable dataTable = null;
  71.  
  72.         /** The table model for the algorithm parameters table. */
  73.         private final DefaultTableModel algoParamTableModel = new DefaultTableModel(new String[] { "Parameter", "Value" },
  74.                         0) {
  75.         };
  76.  
  77.         /** The table model for the result attributes table. */
  78.         private final DefaultTableModel attributesTableModel = new DefaultTableModel(new String[] { "Attribute" }, 0) {
  79.         };
  80.  
  81.         /** The table model for the data table. */
  82.         private DefaultTableModel dataTableModel = new DefaultTableModel(new String[] { "No data selected..." }, 0) {
  83.         };
  84.  
  85.         /** Combobox listing the currently available results. */
  86.         private JComboBox resultChooser;
  87.  
  88.         /** Combobox listing the currently available results for the combined XYPlot. */
  89.         private JComboBox resultChooser2;
  90.  
  91.         /** Combox listing the currently available evaluation results. */
  92.         private JComboBox evalChooser;
  93.  
  94.         /** Combobox listing the available types of Plots. */
  95.         public static JComboBox vizTypeChooser;
  96.  
  97.         /** ComboBox to activate plotting a combined XYPlot. */
  98.         private JCheckBox combinedPlotCB;
  99.  
  100.         /** Little legend for the dataTable. */
  101.         private JEditorPane legend = new JEditorPane();
  102.  
  103.         /** The extended plotter. */
  104.         private Plotter plotter = new Plotter();
  105.  
  106.         public boolean sameDataset = false;
  107.  
  108.         /**
  109.          * Creates the result management and visualization tab.
  110.          *
  111.          * @param title The title of the tab
  112.          */
  113.         public VisualizationTab(String title) {
  114.  
  115.                 super(title, getHelp("help/visualization.html"));
  116.  
  117.                 String[] labelItem = { "No results..." };
  118.                 String[] vizTypes = { "Select Plottype", "XYPlot", "BoxPlot" };
  119.  
  120.                 JPanel mainPanel = new JPanel();
  121.                 JPanel mainPanel2 = new JPanel();
  122.                 JPanel resultPanel = new JPanel();
  123.                 JPanel visualizationPanel = new JPanel();
  124.                 JPanel dataPanel = new JPanel();
  125.  
  126.                 JXTable algoParamTable = new JXTable(algoParamTableModel);
  127.                 attributesTable = new JXTable(attributesTableModel);
  128.                 dataTable = new JXTable(dataTableModel)
  129.                 {
  130.                         // Overwriting the default renderer to get coloring of specific rows
  131.                         public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
  132.  
  133.                                 Component c = super.prepareRenderer(renderer, row, column);
  134.                                 int convertedRow = dataTable.convertRowIndexToModel(row);
  135.                                 int classLabelPos = 0;
  136.                                 TableModel dataTableModel = this.dataModel;
  137.  
  138.                                 if (dataTableModel.getColumnCount() > 1) {
  139.                                         // Get the column of the classlabel
  140.                                         if (sameDataset) {
  141.                                                 classLabelPos = dataTableModel.getColumnCount() - 3;
  142.                                         }
  143.                                         else {
  144.                                                 classLabelPos = dataTableModel.getColumnCount() - 2;
  145.                                         }
  146.  
  147.  
  148.                                         // Coloring the row red, if the classlabel marks an outlier
  149.                                         if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos) != 0) {
  150.                                                 c.setBackground(Color.red);
  151.                                         }
  152.                                         // Coloring the row light red, if only the first result marks an outlier
  153.                                         if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos + 1) != 0) {
  154.                                                 c.setBackground(new Color (255, 200, 200));
  155.                                         }
  156.                                         if (sameDataset) {
  157.                                                 if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos + 2) !=0) {
  158.                                                         // Coloring the row light green, if both results mark an outlier
  159.                                                         if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos + 1) != 0) {
  160.                                                                 c.setBackground(new Color(204,255,204));
  161.                                                         }
  162.                                                         //Coloring the row orange, if only the second result marks an outlier
  163.                                                         else {
  164.                                                                 c.setBackground(new Color(255,230,102));
  165.                                                         }
  166.                                                 }
  167.                                                 // Coloring the row green, if the second result and the classlabel mark an outlier
  168.                                                 if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos + 2) != 0 && (Double)dataTableModel.getValueAt(convertedRow, classLabelPos) != 0) {
  169.                                                         c.setBackground(Color.green);
  170.                                                 }
  171.                                         }
  172.                                         // Coloring the row green, if the first result and the classlabel mark an outlier
  173.                                         if ((Double)dataTableModel.getValueAt(convertedRow, classLabelPos + 1) != 0 && (Double)dataTableModel.getValueAt(convertedRow, classLabelPos) != 0){
  174.                                                 c.setBackground(Color.green);
  175.                                         }
  176.                                         // Set the backgroundcolor for selected rows
  177.                                         if (isRowSelected(row) && isColumnSelected(column)) {
  178.                                                 c.setBackground(new Color(150,150,255));
  179.                                         }
  180.                                 }
  181.  
  182.                                 return c;
  183.                         }
  184.                 };
  185.  
  186.                 JScrollPane algoParamTablePane = new JScrollPane(algoParamTable);
  187.                 JScrollPane attributesTablePane = new JScrollPane(attributesTable);
  188.                 JScrollPane dataTablePane = new JScrollPane(dataTable);
  189.  
  190.                 resultChooser = new JComboBox(labelItem);
  191.                 resultChooser2 = new JComboBox(labelItem);
  192.                 vizTypeChooser = new JComboBox(vizTypes);
  193.                 evalChooser = new JComboBox(labelItem);
  194.  
  195.                 JButton loadResult = new JButton(loadOMResult);
  196.                 JButton saveResult = new JButton(saveOMResult);
  197.                 JButton deleteResult = new JButton(deleteOMResult);
  198.                 JButton createPlot = new JButton(createPlotFrame);
  199.                 JButton createEvalFrame = new JButton(createEvalOverview);
  200.                 JButton dispData = new JButton(showDataTable);
  201.                 JButton deleteEval = new JButton(deleteEvalResult);
  202.                 JButton extendPlotter = new JButton(loadExtendedPlotter);
  203.                 JButton showEvalPlotFrame = new JButton(showEvalPlot);
  204.  
  205.                 combinedPlotCB = new JCheckBox("Create combined Plot");
  206.  
  207.                 JLabel resultChooserLabel = new JLabel();
  208.                 JLabel evalChooserLabel = new JLabel();
  209.                 JLabel algoParamTableLabel = new JLabel();
  210.                 JLabel attributesTableLabel = new JLabel();
  211.                 JLabel dataTableLabel = new JLabel();
  212.  
  213.                 JPanel[] panels = { mainPanel, mainPanel2, resultPanel, visualizationPanel, dataPanel };
  214.                 JEditorPane[] editorPanes = { legend };
  215.                 JScrollPane[] scrollPanes = { algoParamTablePane, attributesTablePane, dataTablePane };
  216.                 JLabel[] labels = { resultChooserLabel, algoParamTableLabel, resultChooserLabel, attributesTableLabel,
  217.                                 dataTableLabel, evalChooserLabel };
  218.                 JButton[] buttons = { loadResult, saveResult, deleteResult, createPlot, createEvalFrame, dispData, deleteEval, extendPlotter, showEvalPlotFrame };
  219.  
  220.                 arrangeGui(panels, editorPanes, scrollPanes, labels, buttons);
  221.  
  222.                 // create menu of tab in the main window
  223.                 getMenu().add(new JMenuItem(loadOMResult));
  224.                 getMenu().add(new JMenuItem(loadExtendedPlotter));
  225.  
  226.                 // Create elements of the tab.
  227.                 // Panels
  228.                 resultPanel.setBorder(BorderFactory.createTitledBorder("Outlier mining results"));
  229.                 visualizationPanel.setBorder(BorderFactory.createTitledBorder("Visualization options"));
  230.                 visualizationPanel.addFocusListener(this);
  231.                 dataPanel.setBorder(BorderFactory.createTitledBorder("Data of selected Attributes"));
  232.  
  233.                 // Editorpanes
  234.                 legend.setEditable(false);
  235.                 legend.setContentType("text/html");
  236.                 legend.setBackground(VisualizationTab.this.getBackground());
  237.  
  238.                 // Tables
  239.                 algoParamTableLabel.setText("Algorithm parameters:");
  240.                 algoParamTableLabel.setLabelFor(algoParamTable);
  241.                 algoParamTable.setEditable(false);
  242.                 algoParamTable.setRowSelectionAllowed(false);
  243.                 algoParamTable.setCellSelectionEnabled(false);
  244.  
  245.                 attributesTableLabel.setText("Select Attributes to visualize:");
  246.                 attributesTableLabel.setLabelFor(attributesTable);
  247.                 attributesTable.setEditable(false);
  248.                 attributesTable.setRowSelectionAllowed(true);
  249.                 attributesTable.setColumnSelectionAllowed(false);
  250.                 ListSelectionModel listSM = attributesTable.getSelectionModel();
  251.                 SharedListSelectionHandler listSH = new SharedListSelectionHandler();
  252.  
  253.                 listSM.addListSelectionListener(listSH);
  254.                 attributesTable.setSelectionModel(listSM);
  255.  
  256.                 dataTableLabel.setText("Data of selected Attributes:");
  257.                 dataTableLabel.setLabelFor(dataTable);
  258.                 dataTable.setEditable(false);
  259.                 dataTable.setHorizontalScrollEnabled(true);
  260.  
  261.                 // Comboboxes
  262.                 resultChooserLabel.setText("Available mining results:");
  263.                 resultChooserLabel.setLabelFor(resultChooser);
  264.                 resultChooser.addActionListener(resultChooserAL);
  265.                 resultChooser.addFocusListener(this);
  266.  
  267.                 evalChooserLabel.setText("Available evaluation results:");
  268.                 evalChooserLabel.setLabelFor(evalChooser);
  269.                 evalChooser.addActionListener(evalChooserAL);
  270.  
  271.                 resultChooser2.setEnabled(false);
  272.  
  273.                 vizTypeChooser.addActionListener(vizTypeChooserAL);
  274.                 vizTypeChooser.setEnabled(false);
  275.  
  276.                 // Checkboxes
  277.                 combinedPlotCB.setMnemonic(KeyEvent.VK_C);
  278.                 combinedPlotCB.setEnabled(false);
  279.  
  280.                 // Add the main panel
  281.                 add(mainPanel);
  282.         }
  283.  
  284.         /** Action to load OM results. */
  285.         private final Action loadOMResult = new AbstractAction("Load result from file") {
  286.                 {
  287.                         setEnabled(false);
  288.                 }
  289.  
  290.                 public void actionPerformed(ActionEvent e) {
  291.                         // Create a file chooser so we can open the supported files
  292.                         JFileChooser fileChooser = new JFileChooser();
  293.                         ExtensionFileFilter filter = new ExtensionFileFilter("Outlier mining result (*.omr)", ".omr");
  294.                         fileChooser.addChoosableFileFilter(filter);
  295.                         fileChooser.setAcceptAllFileFilterUsed(false);
  296.  
  297.                         System.gc();
  298.  
  299.                         int option = fileChooser.showOpenDialog(Application.getWindow().frame);
  300.                         // If the user didn't abort loading, try to load the result
  301.                         if (option == JFileChooser.APPROVE_OPTION) {
  302.                                 String fileName = fileChooser.getSelectedFile().getPath();
  303.                                 try {
  304.                                         // Invoke the ResultIOManager to load the result
  305.                                         ResultIOManager.loadResult(fileName);
  306.                                         // Update the corresponding controls so the loaded result
  307.                                         // becomes available
  308.                                         updateAvailableResults();
  309.                                 } catch (FileNotFoundException e1) {
  310.                                         JOptionPane.showMessageDialog(Application.getWindow().frame, "Cannot access selected file.",
  311.                                                         "File access error", JOptionPane.ERROR_MESSAGE);
  312.                                         e1.printStackTrace();
  313.                                 } catch (IOException e1) {
  314.                                         JOptionPane.showMessageDialog(Application.getWindow().frame,
  315.                                                         "Cannot load contents of selected file.", "Load error", JOptionPane.ERROR_MESSAGE);
  316.                                         e1.printStackTrace();
  317.                                 } catch (ClassNotFoundException e1) {
  318.                                         JOptionPane.showMessageDialog(Application.getWindow().frame,
  319.                                                         "Internal loading error. Try reloading or updating the program.", "Class error",
  320.                                                         JOptionPane.ERROR_MESSAGE);
  321.                                         e1.printStackTrace();
  322.                                 } catch (UnsupportedFileVersionException e1) {
  323.                                         JOptionPane.showMessageDialog(Application.getWindow().frame,
  324.                                                         "The format of the selected file is not supported\nby this version of the OM framework.",
  325.                                                         "File version error", JOptionPane.ERROR_MESSAGE);
  326.                                         e1.printStackTrace();
  327.                                 } catch (NonFittingResultException e1) {
  328.                                         String errorCount = "Rows in current dataset: " + Current.data.getdataCount() + ", rows in file: "
  329.                                         + e1.getRowCount() + "\n" + "Attributes in current dataset: "
  330.                                         + Current.data.getAttributes().size() + ", attributes in file: " + e1.getAttributeCount();
  331.                                         JOptionPane.showMessageDialog(Application.getWindow().frame,
  332.                                                         "The result in the selected file does not fit the current dataset.\nPlease load the appropriate dataset first.\n"
  333.                                                         + errorCount, "Unfitting result", JOptionPane.ERROR_MESSAGE);
  334.                                 }
  335.  
  336.                         }
  337.                 }
  338.         };
  339.  
  340.         /** Action to save the current OM results. */
  341.         private final Action saveOMResult = new AbstractAction("Save result") {
  342.                 {
  343.                         setEnabled(false);
  344.                 }
  345.  
  346.                 public void actionPerformed(ActionEvent e) {
  347.                         boolean saved = false;
  348.  
  349.                         // Create a file chooser so we can save into the supported files
  350.                         JFileChooser fileChooser = new JFileChooser();
  351.                         ExtensionFileFilter filter = new ExtensionFileFilter(
  352.                                         "Outlier mining result (result + algorithm parameters) (*.omr)", ".omr");
  353.                         ExtensionFileFilter filter2 = new ExtensionFileFilter("Comma-separated values (result only) (*.csv)",
  354.                         ".csv");
  355.                         ExtensionFileFilter filter3 = new ExtensionFileFilter("Comma-separated values (result + dataset) (*.csv)",
  356.                         ".csv");
  357.  
  358.                         fileChooser.addChoosableFileFilter(filter);
  359.                         fileChooser.addChoosableFileFilter(filter2);
  360.                         fileChooser.addChoosableFileFilter(filter3);
  361.                         fileChooser.setFileFilter(filter);
  362.                         fileChooser.setAcceptAllFileFilterUsed(false);
  363.  
  364.                         while (!saved) {
  365.                                 int option = fileChooser.showSaveDialog(Application.getWindow().frame);
  366.                                 // If the user didn't abort the dialog, try to save or export the
  367.                                 // result
  368.                                 int overwrite = JOptionPane.NO_OPTION;
  369.                                 if (option == JFileChooser.APPROVE_OPTION) {
  370.                                         String fileName = fileChooser.getSelectedFile().getPath();
  371.                                         if (fileChooser.getSelectedFile().exists()) {
  372.                                                 overwrite = JOptionPane.showConfirmDialog(Application.getWindow().frame, "Do you want to overwirte the exisiting File?", "", JOptionPane.YES_NO_OPTION);
  373.                                         }
  374.                                         else {
  375.                                                 overwrite = JOptionPane.YES_OPTION;
  376.                                         }
  377.                                         if (overwrite == JOptionPane.YES_OPTION) {
  378.                                                 saved = true;
  379.                                                 if (fileChooser.getFileFilter().equals(filter)) {
  380.                                                         // Save into the proprietary OMR format
  381.                                                         if (!fileName.endsWith(".omr")) {
  382.                                                                 fileName = fileName + ".omr";
  383.                                                         }
  384.                                                         try {
  385.                                                                 // Invoke the ResultIOManager to save the result
  386.                                                                 ResultIOManager.saveResult(resultChooser.getSelectedIndex(), fileName);
  387.                                                         } catch (FileNotFoundException e1) {
  388.                                                                 JOptionPane.showMessageDialog(Application.getWindow().frame, "Cannot access selected file.",
  389.                                                                                 "File access error", JOptionPane.ERROR_MESSAGE);
  390.                                                                 e1.printStackTrace();
  391.                                                         } catch (IOException e1) {
  392.                                                                 JOptionPane.showMessageDialog(Application.getWindow().frame,
  393.                                                                                 "Error saving contents into selected file.", "Save error", JOptionPane.ERROR_MESSAGE);
  394.                                                                 e1.printStackTrace();
  395.                                                         }
  396.                                                 } else {
  397.                                                         // Export the result (optionally also the dataset) into CSV
  398.                                                         // format
  399.                                                         if (!fileName.endsWith(".csv")) {
  400.                                                                 fileName = fileName + ".csv";
  401.                                                         }
  402.                                                         try {
  403.                                                                 // Invoke ResultIOManager for export. If the full
  404.                                                                 // dataset is written is dependant on the selected file
  405.                                                                 // filter
  406.                                                                 ResultIOManager.exportResultToCSV(resultChooser.getSelectedIndex(), fileName, fileChooser
  407.                                                                                 .getFileFilter().equals(filter3));
  408.                                                         } catch (FileNotFoundException e1) {
  409.                                                                 JOptionPane.showMessageDialog(Application.getWindow().frame, "Cannot access selected file.",
  410.                                                                                 "File access error", JOptionPane.ERROR_MESSAGE);
  411.                                                                 e1.printStackTrace();
  412.                                                         } catch (IOException e1) {
  413.                                                                 JOptionPane.showMessageDialog(Application.getWindow().frame,
  414.                                                                                 "Error saving contents into selected file.", "Save error", JOptionPane.ERROR_MESSAGE);
  415.                                                                 e1.printStackTrace();
  416.                                                         }
  417.                                                 }
  418.                                         }
  419.                                 }
  420.                                 else {
  421.                                         saved = true;
  422.                                 }
  423.                         }
  424.                 }
  425.         };
  426.  
  427.         /** Action to remove the currently selected result [in the resultChooser ComboBox] and suggests garbage collection. */
  428.         private final Action deleteOMResult = new AbstractAction("Delete result") {
  429.                 {
  430.                         setEnabled(false);
  431.                 }
  432.  
  433.                 public void actionPerformed(ActionEvent e) {
  434.  
  435.                         if (resultChooser.getSelectedIndex() != -1) {
  436.                                 if (JOptionPane.showConfirmDialog(resultChooser,
  437.                                                 "Are you sure you want to delete the selected mining result?", "Confirm deletion",
  438.                                                 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
  439.                                         // Remove the currently-selected result
  440.                                         Current.results.remove(resultChooser.getSelectedIndex());
  441.  
  442.                                         // Update the display of available results
  443.                                         updateAvailableResults();
  444.  
  445.                                         // Suggest garbage collection
  446.                                         System.gc();
  447.                                 }
  448.                         }
  449.                 }
  450.         };
  451.  
  452.         /** Action to delete the currently selected evaluation result [in the evalChooser ComboBox] and suggests garbage collection. */
  453.         private final Action deleteEvalResult = new AbstractAction("Delete eval. result") {
  454.                 {
  455.                         setEnabled(false);
  456.                 }
  457.  
  458.                 public void actionPerformed(ActionEvent e) {
  459.                         if (evalChooser.getSelectedIndex() != -1) {
  460.                                 if (JOptionPane.showConfirmDialog(evalChooser,
  461.                                                 "Are you sure you want to delete the selected evaluation result?", "Confirm deletion",
  462.                                                 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
  463.                                         // Remove the currently-selected result
  464.                                         Current.results.get(resultChooser.getSelectedIndex()).delEvaluation(evalChooser.getSelectedIndex());
  465.  
  466.                                         // Update the display of available results
  467.                                         updateAvailableResults();
  468.  
  469.                                         // Suggest garbage collection
  470.                                         System.gc();
  471.                                 }
  472.                         }
  473.  
  474.                 }
  475.         };
  476.  
  477.         /** Action to create new frame containing the selected plot. */
  478.         private final Action createPlotFrame = new AbstractAction("Create Plot") {
  479.                 {
  480.                         setEnabled(false);
  481.                 }
  482.  
  483.                 public void actionPerformed(ActionEvent e) {
  484.                         // Title of the plot
  485.                         String title = null;
  486.  
  487.                         boolean run = true;
  488.                         // Collect data for the plot
  489.                         if (combinedPlotCB.isSelected()) {
  490.                                 sameDataset = checkDatasets(resultChooser.getSelectedIndex(), getResultIndex(resultChooser2.getSelectedItem()));
  491.                                 if (sameDataset) {
  492.                                         title = "Algo 1: " + resultChooser.getSelectedItem().toString() + "\n" + "Algo 2: "
  493.                                         + resultChooser2.getSelectedItem().toString();
  494.                                 }
  495.                                 else {
  496.                                         JOptionPane.showMessageDialog(VisualizationTab.this, "The selected results are not produced with the same dataset", "Not the same dataset", JOptionPane.ERROR_MESSAGE);
  497.                                         combinedPlotCB.setSelected(false);
  498.                                         run = false;
  499.                                 }
  500.  
  501.                         } else {
  502.                                 title = "Algo: " + resultChooser.getSelectedItem().toString();
  503.                         }
  504.  
  505.                         if (run) {
  506.                                 // Parameters need to be final for creation of the task in background
  507.                                 final String ref_title = title;
  508.  
  509.                                 // Start calculation of plot in a task in background so the gui is still available
  510.                                 Task<VisualizationFrame> t = new Task<VisualizationFrame>("Preparing results for visualization...") {
  511.                                         protected VisualizationFrame doInBackground() throws Exception {
  512.                                                 List<PlotData> data = new ArrayList<PlotData>();
  513.                                                 int visType = vizTypeChooser.getSelectedIndex();
  514.  
  515.                                                 // Create the plot
  516.                                                 if (combinedPlotCB.isSelected()) {
  517.                                                         visType = Plotter.VIS_TYPE_CXYPLOT;
  518.                                                         data.add(new PlotData("Result 1", Current.results.get(resultChooser.getSelectedIndex())));
  519.                                                         data.add(new PlotData("Result 2", Current.results.get(getResultIndex(resultChooser2.getSelectedItem()))));
  520.                                                 }
  521.                                                 else {
  522.                                                         data.add(new PlotData("Result", Current.results.get(resultChooser.getSelectedIndex())));
  523.                                                 }
  524.                                                 for (int i = 0; i < attributesTable.getSelectedRowCount(); i++) {
  525.                                                         int convertedRow = attributesTable.convertRowIndexToModel(attributesTable.getSelectedRows()[i]);
  526.                                                         data.add(new PlotData(attributesTableModel.getValueAt(convertedRow, 0).toString(), Current.results.get(resultChooser.getSelectedIndex()), attributesTableModel.getValueAt(convertedRow, 0).toString(),true));
  527.                                                 }
  528.                                                 if (visType < 4) {
  529.                                                         plotter.createPlot(ref_title, visType, data);
  530.                                                 }
  531.                                                 else {
  532.                                                         plotter.createPlot(ref_title, data, vizTypeChooser.getSelectedIndex() - 3);
  533.                                                 }
  534.  
  535.                                                 // Finally create the frame
  536.                                                 VisualizationFrame frame = new VisualizationFrame(plotter.plotContainer, ref_title);
  537.  
  538.                                                 return frame;
  539.                                         }
  540.  
  541.                                         // Preparations done. Show the frame.
  542.                                         protected void done(VisualizationFrame frame) {
  543.                                                 frame.setLocationRelativeTo(Application.getWindow().frame);
  544.                                                 frame.setVisible(true);
  545.                                         }
  546.                                 };
  547.  
  548.                                 // Execute task...
  549.                                 t.execute();
  550.                         }
  551.                 }
  552.         };
  553.  
  554.         private final Action showEvalPlot = new AbstractAction("View plot of eval.") {
  555.                 {
  556.                         setEnabled(false);
  557.                 }
  558.                 public void actionPerformed(ActionEvent e) {
  559.                         Tuple<String, Tuple<Double, PlotContainer>> evalResult = Current.results.get(resultChooser.getSelectedIndex()).getEvaluation(evalChooser.getSelectedIndex());
  560.                         VisualizationFrame frame = new VisualizationFrame(evalResult.second.second, evalResult.first);
  561.                         frame.setLocationRelativeTo(Application.getWindow().frame);
  562.                         frame.setVisible(true);
  563.                 }
  564.         };
  565.  
  566.         /** This action updates the displayed algorithm parameters when the selection in the combo box has changed. */
  567.         private final Action resultChooserAL = new AbstractAction("Update the displayed algorithm parameters") {
  568.                 public void actionPerformed(ActionEvent e) {
  569.                         if (Current.results.size() > 0) {
  570.                                 saveOMResult.setEnabled(true);
  571.                                 deleteOMResult.setEnabled(true);
  572.                                 updateAlgoParamTable();
  573.                                 updateAttributesTable();
  574.                                 updateResultChooser2();
  575.                                 updateEvalChooser();
  576.                         }
  577.                 }
  578.         };
  579.  
  580.         /**
  581.          * This action checks if the result of an evaluation contains a plot and activates
  582.          * the button to show the plot, if there is one.
  583.          */
  584.         private final Action evalChooserAL = new AbstractAction("Open a VisualizationFrame") {
  585.                 public void actionPerformed(ActionEvent e) {
  586.                         if (evalChooser.getSelectedIndex() != -1) {
  587.                                 showEvalPlot.setEnabled(evalChooser.getSelectedItem().toString().contains("Result: Plot")
  588.                                                 || evalChooser.getSelectedItem().toString().contains("Result 2: Plot"));
  589.                         }
  590.                 }
  591.         };
  592.  
  593.         /** Action enables/disables the checkbox and the second resultChooser to create a combined xy-plot and enables/disables the attributesTable so the user is only able to select rows if he chooses a plot-type. */
  594.         private final Action vizTypeChooserAL = new AbstractAction("Activate Checkbox if necessary") {
  595.                 public void actionPerformed(ActionEvent e) {
  596.                         if (vizTypeChooser.getSelectedIndex() == Plotter.VIS_TYPE_XYPLOT && resultChooser.getItemCount() > 1) {
  597.                                 combinedPlotCB.setEnabled(true);
  598.                         } else {
  599.                                 combinedPlotCB.setEnabled(false);
  600.                                 combinedPlotCB.setSelected(false);
  601.                         }
  602.                         checkVisType(attributesTable.getSelectedRowCount());
  603.                 }
  604.         };
  605.  
  606.         /** Action create a frame with a barplot of the evaluation results. */
  607.         private final Action createEvalOverview = new AbstractAction("Evaluation overview") {
  608.                 {
  609.                         setEnabled(false);
  610.                 }
  611.                 public void actionPerformed(ActionEvent e) {
  612.                         plotter.createPlot("Overview of evaluation results", Plotter.VIS_TYPE_BARPLOT, null);
  613.  
  614.                         VisualizationFrame frame = new VisualizationFrame(plotter.plotContainer, "Overview of evaluation results");
  615.  
  616.                         frame.setLocationRelativeTo(Application.getWindow().frame);
  617.                         frame.setVisible(true);
  618.                 }
  619.         };
  620.  
  621.         /** Action to show the data of the selected attributes [in the attributesTable] and the current OM results in the dataTable in the VisualizationTab. */
  622.         private final Action showDataTable = new AbstractAction("Show selected data") {
  623.                 {
  624.                         setEnabled(false);
  625.                 }
  626.                 public void actionPerformed(ActionEvent e) {
  627.  
  628.                         if (resultChooser2.isEnabled()) {
  629.                                 sameDataset = checkDatasets(resultChooser.getSelectedIndex(), getResultIndex(resultChooser2.getSelectedItem()));
  630.                         }
  631.  
  632.                         final boolean ref_sameData = sameDataset;
  633.  
  634.                         // Create a task, because it could take a while to collect the data
  635.                         Task<DefaultTableModel> t = new Task<DefaultTableModel>("Getting data of selected Attributes...") {
  636.                                 protected DefaultTableModel doInBackground() throws Exception {
  637.                                         // Fill the tablemodel
  638.                                         DefaultTableModel tableModel = updateDataTable();
  639.                                         return tableModel;
  640.                                 }
  641.                                 protected void done(DefaultTableModel tableModel) {
  642.                                         // Link the filled tablemodel to the table and activate the legend
  643.                                         if (!ref_sameData && resultChooser2.isEnabled()) {
  644.                                                 JOptionPane.showMessageDialog(VisualizationTab.this, "The selected results are not produced with the same dataset.\n So only the result of\n    " + resultChooser.getSelectedItem() + "\n will be shown.", "Not the same dataset", JOptionPane.INFORMATION_MESSAGE);
  645.                                         }
  646.                                         dataTable.setModel(tableModel);
  647.                                         legend.setText(Tab.getHelp("help/VisualizationTabMinihelp.html"));
  648.                                 }
  649.                         };
  650.  
  651.                         // Execute task...
  652.                         t.execute();
  653.                 }
  654.         };
  655.  
  656.         /** This action loads a jar-file to extend the plotter used in the visualization. */
  657.         private final Action loadExtendedPlotter = new AbstractAction("Extend the Plotter") {
  658.                 public void actionPerformed(ActionEvent e) {
  659.                         // Create a file chooser so we can open the supported files
  660.                         JFileChooser fileChooser = new JFileChooser();
  661.                         File currentWorkPath = new File(System.getProperty("user.dir"));
  662.                         fileChooser.setCurrentDirectory(currentWorkPath);
  663.                         ExtensionFileFilter filter = new ExtensionFileFilter("Jar Files including classes (*.jar)", ".jar");
  664.                         fileChooser.addChoosableFileFilter(filter);
  665.                         fileChooser.setAcceptAllFileFilterUsed(false);
  666.  
  667.                         int option = fileChooser.showOpenDialog(Application.getWindow().frame);
  668.                         // If the user didn't abort loading, try to load the file
  669.                         if (option == JFileChooser.APPROVE_OPTION) {
  670.                                 File file = fileChooser.getSelectedFile();
  671.                                 String fileName = file.getPath();
  672.  
  673.                                 try {
  674.                                         plotter.addPlotType(fileName);
  675.                                 } catch (FileNotFoundException e1) {
  676.                                         JOptionPane.showMessageDialog(Application.getWindow().frame, "Cannot access selected file.",
  677.                                                         "File access error", JOptionPane.ERROR_MESSAGE);
  678.                                         e1.printStackTrace();
  679.                                 }
  680.                         }
  681.                 }
  682.         };
  683.  
  684.         /**
  685.          * Updates the whole tab if the tab gains the focus.
  686.          *
  687.          * @param e The event.
  688.          *
  689.          * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
  690.          */
  691.         public void focusGained(FocusEvent e) {
  692.                 // save the selected item
  693.                 Object item = resultChooser.getSelectedItem();
  694.                 updateAvailableResults();
  695.                 // set the selected item before the update again
  696.                 resultChooser.setSelectedItem(item);
  697.         }
  698.  
  699.         /**
  700.          * Focus lost.
  701.          *
  702.          * @param e The event
  703.          *
  704.          * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
  705.          */
  706.         public void focusLost(FocusEvent e) {
  707.                 // do nothing
  708.         }
  709.  
  710.         /**
  711.          * Class to implement the ListSelectionListener.
  712.          *
  713.          * @author Matthias Hannen
  714.          */
  715.         class SharedListSelectionHandler implements ListSelectionListener {
  716.  
  717.                 /**
  718.                  * Value changed.
  719.                  *
  720.                  * @param e The event
  721.                  *
  722.                  * @see
  723.                  * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.
  724.                  * event.ListSelectionEvent)
  725.                  */
  726.                 public void valueChanged(ListSelectionEvent e) {
  727.                         ListSelectionModel lSM = (ListSelectionModel) e.getSource();
  728.  
  729.                         int indexCount = 0;
  730.                         if (!(lSM.isSelectionEmpty())) {
  731.                                 indexCount = attributesTable.getSelectedRowCount();
  732.                         }
  733.  
  734.                         checkVisType(indexCount);
  735.  
  736.                         // Activate the button, if attributes are selected
  737.                         showDataTable.setEnabled(indexCount > 0);
  738.  
  739.                         // If no data is shown in the table...
  740.                         if (dataTable.getColumnCount() == 1) {
  741.                                 if (indexCount > 0) {
  742.                                         // Show a little hint in the table
  743.                                         dataTableModel = new DefaultTableModel(new String[] { "Press 'Show selected data' to display data of selected Attributes" }, 0);
  744.                                         dataTable.setModel(dataTableModel);
  745.                                 }
  746.                                 else {
  747.                                         // If no attributes are selected, reset the table.
  748.                                         dataTableModel = new DefaultTableModel(new String[] { "No data selected..." }, 0);
  749.                                         dataTable.setModel(dataTableModel);
  750.                                         legend.setText("");
  751.                                 }
  752.                         }
  753.                 }
  754.         }
  755.  
  756.         /**
  757.          * Updates the content of the combobox displaying the available results.
  758.          */
  759.         private void updateResultChooser() {
  760.                 // Remove all items
  761.                 resultChooser.removeAllItems();
  762.  
  763.                 // Get the available results
  764.                 for (int i = 0; i < Current.results.size(); i++) {
  765.                         resultChooser.addItem((i + 1) + " - " + Current.results.get(i).algorithm);
  766.                 }
  767.  
  768.                 // Set the selection to the last item
  769.                 resultChooser.setSelectedIndex(resultChooser.getItemCount() - 1);
  770.         }
  771.  
  772.         /**
  773.          * Update the content of the second combobox displaying the available results for
  774.          * combined XYPlots and the dataTable.
  775.          */
  776.         private void updateResultChooser2() {
  777.                 // If more than one result is there
  778.                 if (resultChooser.getItemCount() > 1) {
  779.  
  780.                         // Remove all items
  781.                         resultChooser2.removeAllItems();
  782.  
  783.                         // Get the available results except the one selected in the first resultChooser
  784.                         for (int i = 0; i < Current.results.size(); i++) {
  785.                                 if (i != resultChooser.getSelectedIndex()) {
  786.                                         resultChooser2.addItem((i + 1) + " - " + Current.results.get(i).algorithm);
  787.                                 }
  788.                         }
  789.                 } else {
  790.                         // Remove all items, if there is just one result
  791.                         resultChooser2.removeAllItems();
  792.                         resultChooser2.addItem("No results...");
  793.                 }
  794.  
  795.                 // Set the selection to the last item
  796.                 resultChooser2.setSelectedIndex(resultChooser2.getItemCount() - 1);
  797.         }
  798.  
  799.         /**
  800.          * Updates the content of the combobox displaying the available evaluation results for the selected result
  801.          * in the resultChooser.
  802.          */
  803.         private void updateEvalChooser() {
  804.                 // If a result is selected ...
  805.                 if (resultChooser.getSelectedIndex() != -1) {
  806.  
  807.                         int algo = resultChooser.getSelectedIndex();
  808.  
  809.                         // Remove all items
  810.                         evalChooser.removeAllItems();
  811.  
  812.                         // If there is a evaluation result
  813.                         if (Current.results.get(algo).getNumberEvaluations() > 0) {
  814.                                 // Activate the button to delete it
  815.                                 deleteEvalResult.setEnabled(true);
  816.  
  817.                                 // Get the result
  818.                                 for (int i = 0; i < Current.results.get(algo).getNumberEvaluations(); i++) {
  819.                                         Tuple<String, Tuple<Double, PlotContainer>> evalResult = Current.results.get(algo).getEvaluation(i);
  820.                                         if (evalResult.second.first != null && evalResult.second.second != null) {
  821.                                                 evalChooser.addItem(i + 1 + " - " + evalResult.first + " - Result 1: " + evalResult.second.first + " - Result 2: Plot");
  822.                                         }
  823.                                         else {
  824.                                                 if (evalResult.second.first != null) {
  825.                                                         evalChooser.addItem(i + 1 + " - " + evalResult.first + " - Result: " + evalResult.second.first);
  826.                                                 }
  827.                                                 else {
  828.                                                         evalChooser.addItem(i + 1 + " - " + evalResult.first + " - Result: Plot");
  829.                                                 }
  830.                                         }
  831.                                 }
  832.                         } else {
  833.                                 // If there is no evaluation result, rest the combobox
  834.                                 evalChooser.removeAllItems();
  835.                                 evalChooser.addItem("No results...");
  836.                                 deleteEvalResult.setEnabled(false);
  837.                         }
  838.  
  839.                         // Set selection to the last item
  840.                         evalChooser.setSelectedIndex(evalChooser.getItemCount() - 1);
  841.                 }
  842.         }
  843.  
  844.         /**
  845.          * Updates the displayed algorithm parameters.
  846.          */
  847.         private void updateAlgoParamTable() {
  848.                 // Remove all the old parameters
  849.                 for (int i = algoParamTableModel.getRowCount() - 1; i >= 0; i--) {
  850.                         algoParamTableModel.removeRow(i);
  851.                 }
  852.                 // Iterate through the parameters of the selected result and add them to
  853.                 // the table
  854.                 if (resultChooser.getSelectedIndex() != -1) {
  855.                         for (Map.Entry<String, Double> entry : Current.results.get(resultChooser.getSelectedIndex()).parameters
  856.                                         .entrySet()) {
  857.                                 algoParamTableModel.addRow(new Object[] { entry.getKey(), entry.getValue() });
  858.                         }
  859.                 }
  860.         }
  861.  
  862.         /**
  863.          * Update the displayed attributes.
  864.          */
  865.         private void updateAttributesTable() {
  866.                 // Remove all rows
  867.                 for (int i = attributesTableModel.getRowCount() - 1; i >= 0; i--) {
  868.                         attributesTableModel.removeRow(i);
  869.                 }
  870.  
  871.                 // If a result is selected
  872.                 if (resultChooser.getSelectedIndex() != -1) {
  873.  
  874.                         // Get the attributes of the result
  875.                         for (int i = 0; i < Current.results.get(resultChooser.getSelectedIndex()).data.getAttributes().size(); i++) {
  876.                                 attributesTableModel.addRow(new Object[] { Current.results.get(resultChooser.getSelectedIndex()).data
  877.                                                 .getAttributes().get(i).toString() });
  878.                         }
  879.                 }
  880.  
  881.                 // Set the dataTable to the default content
  882.                 showDataTable.setEnabled(false);
  883.                 dataTableModel = new DefaultTableModel(new String[] { "No data selected..." }, 0);
  884.                 dataTable.setModel(dataTableModel);
  885.                 legend.setText("");
  886.         }
  887.  
  888.         /**
  889.          * Update this displayed data of selected attributes.
  890.          *
  891.          * @return the default table model
  892.          */
  893.         private DefaultTableModel updateDataTable() {
  894.                 // Count of selected attributes
  895.                 int dim = attributesTable.getSelectedRowCount();
  896.                 // The row that will be added to the dataTable
  897.                 Double[] newRow = new Double[dim+2];
  898.                 // Count of elements in one new row
  899.                 int rowCount = 0;
  900.  
  901.                 // Vars for the second result, if available
  902.                 Result result2 = null;
  903.                 Iterator<Map.Entry<DataObject, Float>> it = null;
  904.                 Entry<DataObject, Float> currentEntry2 = null;
  905.  
  906.                 // New tablemodel to fill
  907.                 DefaultTableModel tableModel = new DefaultTableModel();
  908.  
  909.                 // Just to be sure...
  910.                 if (Current.results.size() > 0) {
  911.                         if (dim > 0) {
  912.  
  913.                                 // Add the Columns
  914.                                 for (int i = 0; i < dim; i++) {
  915.                                         int convertedRow = attributesTable.convertRowIndexToModel(attributesTable.getSelectedRows()[i]);
  916.                                         tableModel.addColumn(attributesTableModel.getValueAt(convertedRow, 0).toString());
  917.                                         rowCount++;
  918.                                 }
  919.  
  920.                                 // Those columns will be in every table
  921.                                 tableModel.addColumn("ClassLabel");
  922.                                 tableModel.addColumn("Result");
  923.  
  924.                                 // If there is a second result, add a column for it and set result2 to iterate through it
  925.                                 if (sameDataset) {
  926.                                         newRow = new Double[dim+3];
  927.                                         tableModel.addColumn("Result 2");
  928.                                         result2 = Current.results.get(getResultIndex(resultChooser2.getSelectedItem()));
  929.                                         it = result2.iterator();
  930.                                 }
  931.  
  932.                                 // Just to be sure... again?! WTH?! ... Never mind ;)
  933.                                 if (resultChooser.getSelectedIndex() != -1) {
  934.                                         // Get the first result
  935.                                         Result result = Current.results.get(resultChooser.getSelectedIndex());
  936.  
  937.                                         // Iterate through the first result
  938.                                         for (Entry<DataObject, Float> currentEntry : result) {
  939.                                                 // Fill the new row with the data of the attributes
  940.                                                 for (int i = 0; i < rowCount; i++) {
  941.                                                         int convertedRow = attributesTable.convertRowIndexToModel(attributesTable.getSelectedRows()[i]);
  942.                                                         newRow[i] = currentEntry.getKey().get(attributesTableModel.getValueAt(convertedRow, 0).toString());
  943.                                                 }
  944.  
  945.                                                 // Add the classlabel to the new row
  946.                                                 newRow[rowCount] = currentEntry.getKey().getclassLabel();
  947.                                                 // Add the first result to the new row
  948.                                                 newRow[rowCount+1] = currentEntry.getValue().doubleValue();
  949.                                                 // Iterate through the second result and add it to the new row... if it exists
  950.                                                 if (sameDataset && it.hasNext()) {
  951.                                                         currentEntry2 = it.next();
  952.                                                         newRow[rowCount+2] = currentEntry2.getValue().doubleValue();
  953.                                                 }
  954.  
  955.                                                 // Finally add the new row to the tablemodel
  956.                                                 tableModel.addRow(newRow);
  957.                                         }
  958.                                 }
  959.                         }
  960.                 }
  961.  
  962.                 // return the filled tablemodel and it will be linked with the dataTable
  963.                 return tableModel;
  964.         }
  965.  
  966.         /**
  967.          * Loads the available OM results into the result manager. Call this method
  968.          * whenever a result is added, edited or removed or if any other changes
  969.          * have been made to the Current working set.
  970.          */
  971.         private void updateAvailableResults() {
  972.                 // Activate the load button, if data is already loaded
  973.                 loadOMResult.setEnabled(Current.data != null);
  974.  
  975.                 // If there are results available
  976.                 if (Current.results.size() > 0) {
  977.  
  978.                         //Update the whole tab
  979.                         updateResultChooser();
  980.                         updateResultChooser2();
  981.                         updateAlgoParamTable();
  982.                         updateAttributesTable();
  983.                         updateEvalChooser();
  984.  
  985.                         // Enable/disable buttons
  986.                         vizTypeChooser.setEnabled(true);
  987.                         combinedPlotCB.setSelected(false);
  988.                         combinedPlotCB.setEnabled(false);
  989.                         resultChooser2.setEnabled(false);
  990.                         attributesTable.setEnabled(true);
  991.                         // Clear the selection in the attributesTable
  992.                         attributesTable.clearSelection();
  993.                         // Reset the vizTypeChooser
  994.                         vizTypeChooser.setSelectedIndex(0);
  995.                         // Activate resultChooser2, if there is more than one result
  996.                         if (Current.results.size() > 1) {
  997.                                 resultChooser2.setEnabled(true);
  998.                         }
  999.  
  1000.                         // Disable the button for the evaluation overview. Will be enabled, if there is a eval result
  1001.                         createEvalOverview.setEnabled(false);
  1002.                         // Search for evaluation results
  1003.                         for (int algo = 0; algo < resultChooser.getItemCount(); algo++) {
  1004.                                 for (int i = 0; i < Current.results.get(algo).getNumberEvaluations(); i++) {
  1005.                                         if (Current.results.get(algo).getEvaluation(i).second.first != null) {
  1006.                                                 // Activate the button for the overview, if there are any evaluation results...
  1007.                                                 createEvalOverview.setEnabled(true);
  1008.                                         }
  1009.                                 }
  1010.                         }
  1011.  
  1012.                 } else {
  1013.                         // No results there... Reset everything to the default
  1014.                         for (int i = algoParamTableModel.getRowCount() - 1; i >= 0; i--) {
  1015.                                 algoParamTableModel.removeRow(i);
  1016.                         }
  1017.                         for (int i = attributesTableModel.getRowCount() - 1; i >= 0; i--) {
  1018.                                 attributesTableModel.removeRow(i);
  1019.                         }
  1020.                         attributesTable.setEnabled(false);
  1021.  
  1022.                         dataTableModel = new DefaultTableModel(new String[] { "No data selected..." }, 0);
  1023.                         dataTable.setModel(dataTableModel);
  1024.                         legend.setText("");
  1025.  
  1026.                         resultChooser.removeAllItems();
  1027.                         resultChooser.addItem("No results...");
  1028.  
  1029.                         evalChooser.removeAllItems();
  1030.                         evalChooser.addItem("No results...");
  1031.  
  1032.                         vizTypeChooser.setSelectedIndex(0);
  1033.                         vizTypeChooser.setEnabled(false);
  1034.  
  1035.                         combinedPlotCB.setSelected(false);
  1036.                         combinedPlotCB.setEnabled(false);
  1037.  
  1038.                         resultChooser2.removeAllItems();
  1039.                         resultChooser2.addItem("No results...");
  1040.                         resultChooser2.setEnabled(false);
  1041.  
  1042.                         deleteOMResult.setEnabled(false);
  1043.                         saveOMResult.setEnabled(false);
  1044.                         createEvalOverview.setEnabled(false);
  1045.                         showDataTable.setEnabled(false);
  1046.                         deleteEvalResult.setEnabled(false);
  1047.                 }
  1048.  
  1049.                 sameDataset = false;
  1050.         }
  1051.  
  1052.         /**
  1053.          * Checks the selected type of visualization and if the count of selected attributes is right for the type,
  1054.          * it activates the button to create a plot.
  1055.          *
  1056.          * @param indexCount Count of selected Attributes in the attributesTable
  1057.          */
  1058.         private void checkVisType(int indexCount) {
  1059.                 if (vizTypeChooser.getSelectedIndex() == Plotter.VIS_TYPE_XYPLOT) {
  1060.                         createPlotFrame.setEnabled(indexCount == 2);
  1061.                 }
  1062.                 else if (vizTypeChooser.getSelectedIndex() == Plotter.VIS_TYPE_BOXPLOT) {
  1063.                         createPlotFrame.setEnabled(indexCount > 0);
  1064.                 }
  1065.                 else if (vizTypeChooser.getSelectedIndex() > 2) {
  1066.                         int index = vizTypeChooser.getSelectedIndex() - 3;
  1067.                         boolean max_infinity = (plotter.plotTypes.get(index).allowedAttrCountMax == 0);
  1068.                         if (plotter.plotTypes.get(index).neededAttrCountMin > 0) {
  1069.                                 if (plotter.plotTypes.get(index).allowedAttrCountMax >= plotter.plotTypes.get(index).neededAttrCountMin || max_infinity) {
  1070.                                         createPlotFrame.setEnabled(indexCount >= plotter.plotTypes.get(index).neededAttrCountMin
  1071.                                                         && (indexCount <= plotter.plotTypes.get(index).allowedAttrCountMax
  1072.                                                                         || max_infinity));
  1073.                                 }
  1074.                         }
  1075.                 }
  1076.                 else {
  1077.                         createPlotFrame.setEnabled(false);
  1078.                 }
  1079.         }
  1080.  
  1081.         /**
  1082.          * Checks if 2 results are produced with the same dataset.
  1083.          *
  1084.          * @param index1 The index of the first result.
  1085.          * @param index2 The index of the second result.
  1086.          * @return True or false.
  1087.          */
  1088.         private boolean checkDatasets(int index1, int index2) {
  1089.                 return Current.results.get(index1).data.equals(Current.results.get(index2).data);
  1090.         }
  1091.  
  1092.         /**
  1093.          * Converts the index of an item in the resultChooser2 to the index of the result represented by the item.
  1094.          *
  1095.          * @param item Item of the resultChooser2
  1096.          * @return Index of the result represented by the item.
  1097.          */
  1098.         private int getResultIndex(Object item) {
  1099.                 int i = 0;
  1100.                 for (i = 0; i < resultChooser.getItemCount() && !item.equals(resultChooser.getItemAt(i)); i++);
  1101.                 return i;
  1102.         }
  1103.  
  1104.         /**
  1105.          * Arrange gui.
  1106.          *
  1107.          * @param panels the panels
  1108.          * @param scrollPanes the scroll panes
  1109.          * @param labels the labels
  1110.          * @param buttons the buttons
  1111.          * @param editorPanes the editor panes
  1112.          */
  1113.         private void arrangeGui(JPanel[] panels, JEditorPane[] editorPanes, JScrollPane[] scrollPanes, JLabel[] labels, JButton[] buttons) {
  1114.                 // Layout of the tab... just blabla for the ui which eclipse formats
  1115.                 // like a stupid moron
  1116.                 // swing...stupid brainfuck
  1117.                 // If you understand it, you are lucky. But you don't need to... so stop crying about missing comments!
  1118.  
  1119.                 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(panels[0]);
  1120.                 panels[0].setLayout(mainPanelLayout);
  1121.  
  1122.                 mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(
  1123.                                 javax.swing.GroupLayout.Alignment.LEADING).addGroup(
  1124.                                                 mainPanelLayout.createSequentialGroup().addContainerGap().addGroup(
  1125.                                                                 mainPanelLayout.createSequentialGroup().addComponent(panels[2]).addComponent(panels[3]).addComponent(panels[4]))));
  1126.  
  1127.                 mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(
  1128.                                 javax.swing.GroupLayout.Alignment.LEADING).addGroup(
  1129.                                                 mainPanelLayout.createParallelGroup().addComponent(panels[2]).addComponent(panels[3]).addComponent(panels[4])));
  1130.  
  1131.                 javax.swing.GroupLayout dataPanelLayout = new javax.swing.GroupLayout(panels[4]);
  1132.                 panels[4].setLayout(dataPanelLayout);
  1133.  
  1134.                 dataPanelLayout.setHorizontalGroup(dataPanelLayout.createParallelGroup(
  1135.                                 javax.swing.GroupLayout.Alignment.LEADING).addGroup(
  1136.                                                 dataPanelLayout.createSequentialGroup().addContainerGap().addGroup(
  1137.                                                                 dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  1138.                                                                 .addComponent(scrollPanes[2],
  1139.                                                                                 javax.swing.GroupLayout.Alignment.LEADING, 0, 450, Short.MAX_VALUE).addGroup(dataPanelLayout.createSequentialGroup().addComponent(buttons[5]).addComponent(editorPanes[0])))));
  1140.  
  1141.                 dataPanelLayout.setVerticalGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  1142.                                 .addGroup(
  1143.                                                 dataPanelLayout.createSequentialGroup().addComponent(scrollPanes[2],
  1144.                                                                 javax.swing.GroupLayout.PREFERRED_SIZE, 475, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(dataPanelLayout.createParallelGroup().addComponent(buttons[5]).addComponent(editorPanes[0]))));
  1145.  
  1146.                 javax.swing.GroupLayout resultPanelLayout = new javax.swing.GroupLayout(panels[2]);
  1147.                 panels[2].setLayout(resultPanelLayout);
  1148.  
  1149.                 resultPanelLayout
  1150.                 .setHorizontalGroup(resultPanelLayout
  1151.                                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  1152.                                 .addGroup(
  1153.                                                 resultPanelLayout
  1154.                                                 .createSequentialGroup()
  1155.                                                 .addContainerGap()
  1156.                                                 .addGroup(
  1157.                                                                 resultPanelLayout
  1158.                                                                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
  1159.                                                                                 false)
  1160.                                                                                 .addComponent(labels[0])
  1161.                                                                                 .addGroup(
  1162.                                                                                                 resultPanelLayout
  1163.                                                                                                 .createSequentialGroup()
  1164.                                                                                                 .addGap(10, 10, 10)
  1165.                                                                                                 .addGroup(
  1166.                                                                                                                 resultPanelLayout
  1167.                                                                                                                 .createParallelGroup(
  1168.                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING)
  1169.                                                                                                                                 .addGroup(
  1170.                                                                                                                                                 resultPanelLayout
  1171.                                                                                                                                                 .createParallelGroup(
  1172.                                                                                                                                                                 javax.swing.GroupLayout.Alignment.TRAILING,
  1173.                                                                                                                                                                 false)
  1174.                                                                                                                                                                 .addComponent(
  1175.                                                                                                                                                                                 scrollPanes[0],
  1176.                                                                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING,
  1177.                                                                                                                                                                                 0,
  1178.                                                                                                                                                                                 0,
  1179.                                                                                                                                                                                 Short.MAX_VALUE)
  1180.                                                                                                                                                                                 .addComponent(
  1181.                                                                                                                                                                                                 resultChooser,
  1182.                                                                                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING,
  1183.                                                                                                                                                                                                 0,
  1184.                                                                                                                                                                                                 javax.swing.GroupLayout.DEFAULT_SIZE,
  1185.                                                                                                                                                                                                 Short.MAX_VALUE).addGroup(resultPanelLayout.createParallelGroup().addComponent(labels[5]).addComponent(evalChooser)
  1186.                                                                                                                                                                                                                 .addGroup(resultPanelLayout.createSequentialGroup().addComponent(buttons[4]).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(buttons[8]).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(buttons[6]))
  1187.                                                                                                                                                                                                                 .addGroup(
  1188.                                                                                                                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING,
  1189.                                                                                                                                                                                                                                 resultPanelLayout
  1190.                                                                                                                                                                                                                                 .createSequentialGroup()
  1191.                                                                                                                                                                                                                                 .addComponent(
  1192.                                                                                                                                                                                                                                                 buttons[0])
  1193.                                                                                                                                                                                                                                                 .addPreferredGap(
  1194.                                                                                                                                                                                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  1195.                                                                                                                                                                                                                                                                 .addComponent(
  1196.                                                                                                                                                                                                                                                                                 buttons[1])
  1197.                                                                                                                                                                                                                                                                                 .addPreferredGap(
  1198.                                                                                                                                                                                                                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  1199.                                                                                                                                                                                                                                                                                                 .addComponent(
  1200.                                                                                                                                                                                                                                                                                                                 buttons[2]))
  1201.                                                                                                                                                                                                                                                                                                                 .addComponent(labels[1]))))))));
  1202.                 resultPanelLayout.setVerticalGroup(resultPanelLayout.createParallelGroup(
  1203.                                 javax.swing.GroupLayout.Alignment.LEADING).addGroup(resultPanelLayout.createSequentialGroup().addGroup(
  1204.                                                 resultPanelLayout.createSequentialGroup().addComponent(labels[0]).addPreferredGap(
  1205.                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(resultChooser,
  1206.                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
  1207.                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(resultPanelLayout.createSequentialGroup().addComponent(labels[5]).addPreferredGap(
  1208.                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(evalChooser,
  1209.                                                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
  1210.                                                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(resultPanelLayout.createParallelGroup().addComponent(buttons[4]).addComponent(buttons[8]).addComponent(buttons[6])).addPreferredGap(
  1211.                                                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
  1212.                                                                                                                                                 resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
  1213.                                                                                                                                                                 buttons[0]).addComponent(buttons[1]).addComponent(buttons[2])).addPreferredGap(
  1214.                                                                                                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(labels[1]).addPreferredGap(
  1215.                                                                                                                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPanes[0],
  1216.                                                                                                                                                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
  1217.                                                                                                                                                                                                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  1218.                                                                                                                                                                                                                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
  1219.  
  1220.                 panels[3].setBorder(javax.swing.BorderFactory.createTitledBorder("Visualization options"));
  1221.  
  1222.                 javax.swing.GroupLayout visualizationPanelLayout = new javax.swing.GroupLayout(panels[3]);
  1223.                 panels[3].setLayout(visualizationPanelLayout);
  1224.  
  1225.                 visualizationPanelLayout
  1226.                 .setHorizontalGroup(visualizationPanelLayout
  1227.                                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  1228.                                 .addGroup(
  1229.                                                 visualizationPanelLayout
  1230.                                                 .createSequentialGroup()
  1231.                                                 .addContainerGap()
  1232.                                                 .addGroup(
  1233.                                                                 visualizationPanelLayout
  1234.                                                                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
  1235.                                                                                 false)
  1236.                                                                                 .addComponent(vizTypeChooser)
  1237.                                                                                 .addComponent(buttons[7])
  1238.  
  1239.                                                                                 .addComponent(labels[3])
  1240.                                                                                 .addGroup(
  1241.                                                                                                 visualizationPanelLayout
  1242.                                                                                                 .createSequentialGroup()
  1243.                                                                                                 .addGap(10, 10, 10)
  1244.                                                                                                 .addGroup(
  1245.                                                                                                                 visualizationPanelLayout
  1246.                                                                                                                 .createParallelGroup(
  1247.                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING)
  1248.                                                                                                                                 .addGroup(
  1249.                                                                                                                                                 visualizationPanelLayout
  1250.                                                                                                                                                 .createParallelGroup(
  1251.                                                                                                                                                                 javax.swing.GroupLayout.Alignment.TRAILING,
  1252.                                                                                                                                                                 false)
  1253.                                                                                                                                                                 .addComponent(
  1254.                                                                                                                                                                                 scrollPanes[1],
  1255.                                                                                                                                                                                 javax.swing.GroupLayout.Alignment.LEADING,
  1256.                                                                                                                                                                                 0,
  1257.                                                                                                                                                                                 225,
  1258.                                                                                                                                                                                 Short.MAX_VALUE)
  1259.                                                                                                                                                                                 .addComponent(
  1260.                                                                                                                                                                                                 combinedPlotCB)
  1261.                                                                                                                                                                                                 .addComponent(
  1262.                                                                                                                                                                                                                 resultChooser2)))).addComponent(buttons[3], javax.swing.GroupLayout.DEFAULT_SIZE,
  1263.                                                                                                                                                                                                                                 javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
  1264.  
  1265.                 visualizationPanelLayout.setVerticalGroup(visualizationPanelLayout.createParallelGroup(
  1266.                                 javax.swing.GroupLayout.Alignment.LEADING).addGroup(
  1267.                                                 visualizationPanelLayout.createSequentialGroup().addComponent(vizTypeChooser).addContainerGap(5,
  1268.                                                                 5).addComponent(buttons[7]).addContainerGap(10, 10).addComponent(labels[3])
  1269.                                                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
  1270.                                                                                 scrollPanes[1], javax.swing.GroupLayout.PREFERRED_SIZE, 275,
  1271.                                                                                 javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
  1272.                                                                                                 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(combinedPlotCB)
  1273.                                                                                                 .addComponent(resultChooser2).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
  1274.                                                                                                                 Short.MAX_VALUE).addComponent(buttons[3])));
  1275.         }
  1276.  
  1277. }