/***********************************************************************
This file is part of KEEL-software, the Data Mining tool for regression,
classification, clustering, pattern mining and so on.
Copyright (C) 2004-2010
F. Herrera (herrera@decsai.ugr.es)
L. S�nchez (luciano@uniovi.es)
J. Alcal�-Fdez (jalcala@decsai.ugr.es)
S. Garc�a (sglopez@ujaen.es)
A. Fern�ndez (alberto.fernandez@ujaen.es)
J. Luengo (julianlm@decsai.ugr.es)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
**********************************************************************/
package keel.GraphInterKeel.datacf.exportData;
import keel.GraphInterKeel.datacf.util.FileUtils;
import keel.GraphInterKeel.datacf.util.OptionsDialog;
import keel.GraphInterKeel.datacf.util.KeelFileFilter;
import keel.GraphInterKeel.util.Path;
import java.awt.CardLayout;
import java.awt.Cursor;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import keel.Algorithms.Preprocess.Converter.KeelToCsv;
import keel.Algorithms.Preprocess.Converter.KeelToDb;
import keel.Algorithms.Preprocess.Converter.KeelToDif;
import keel.Algorithms.Preprocess.Converter.KeelToExcel;
import keel.Algorithms.Preprocess.Converter.KeelToHtml;
import keel.Algorithms.Preprocess.Converter.KeelToPrn;
import keel.Algorithms.Preprocess.Converter.KeelToPropertyList;
import keel.Algorithms.Preprocess.Converter.KeelToTxt;
import keel.Algorithms.Preprocess.Converter.KeelToUci;
import keel.Algorithms.Preprocess.Converter.KeelToWeka;
import keel.Algorithms.Preprocess.Converter.KeelToXml;
/**
* <p>
* @author Written by Pedro Antonio Gutiérrez and Juan Carlos Fernández(University of Córdoba) 23/10/2008
* @version 1.0
* @since JDK1.5
* </p>
*/
public class ExportPanel extends javax.swing.JPanel {
/**
* <p>
* Panel for exporting datasets
* </p>
*/
/**
* <p>
* Constructor that initializes the panel
* </p>
*/
public ExportPanel() {
initComponents();
}
/**
* <p>
* This method is called from within the constructor to
* initialize the form.
* </p>
* <p>
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
* </p>
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
exportSelectPanel = new javax.swing.JPanel();
exportSelectMainPanel = new javax.swing.JPanel();
nextSelectDatasetButton = new javax.swing.JButton();
datasetIcon = new javax.swing.JLabel();
nextSelectPartitionsButton = new javax.swing.JButton();
partitionsIcon = new javax.swing.JLabel();
exportSeparator = new javax.swing.JSeparator();
exportDatasetLabel = new javax.swing.JLabel();
exportPartitionsLabel = new javax.swing.JLabel();
exportBrowserPanel = new javax.swing.JPanel();
buttonPanel = new javax.swing.JPanel();
optionsButton = new javax.swing.JButton();
outputFormatLabel = new javax.swing.JLabel();
outputFormatComboBox = new javax.swing.JComboBox();
backBrowserButton = new javax.swing.JButton();
nextBrowserButton = new javax.swing.JButton();
fileBrowserPanel = new keel.GraphInterKeel.datacf.util.FileBrowserPanel();
KeelFileFilter fileFilter = new KeelFileFilter();
fileFilter.addExtension("dat");
fileFilter.setFilterName("KEEL Files (.dat)");
fileBrowserPanel.getFileChooser().addChoosableFileFilter(fileFilter);
exportPreviewPanel = new javax.swing.JPanel();
mainPanel = new javax.swing.JPanel();
leftPreviewPanel = new javax.swing.JPanel();
originalScrollPanel = new javax.swing.JScrollPane();
originalTextArea = new javax.swing.JTextArea();
originalSeparator = new javax.swing.JSeparator();
originalLabel = new javax.swing.JLabel();
rightPreviewPanel = new javax.swing.JPanel();
resultScrollPanel = new javax.swing.JScrollPane();
resultTextArea = new javax.swing.JTextArea();
resultSeparator = new javax.swing.JSeparator();
resultsLabel = new javax.swing.JLabel();
informationPartitionsLabel = new javax.swing.JLabel();
nextPreviewButton = new javax.swing.JButton();
backPreviewButton = new javax.swing.JButton();
exportPartitionsPanel = new javax.swing.JPanel();
mainPartitionsPanel = new javax.swing.JPanel();
informationLabel = new javax.swing.JLabel();
nextPartitionsButton = new javax.swing.JButton();
backPartitionsButton = new javax.swing.JButton();
trainingPanel = new javax.swing.JPanel();
trainingScrollPanel = new javax.swing.JScrollPane();
trainingList = new JList(trainingModel);
testingPanel = new javax.swing.JPanel();
testingScrollPanel = new javax.swing.JScrollPane();
testingList = new JList(testingModel);
cleanButton = new javax.swing.JButton();
trainingButtons = new javax.swing.JPanel();
addTrainingButton = new javax.swing.JButton();
removeTrainingButton = new javax.swing.JButton();
testingButtons = new javax.swing.JPanel();
addTestingButton = new javax.swing.JButton();
removeTestingButton = new javax.swing.JButton();
outputFormatPartitionsPanel = new javax.swing.JPanel();
optionsPartitionsButton = new javax.swing.JButton();
outputFormatPartitionsComboBox = new javax.swing.JComboBox();
outputFormatPartitionsLabel = new javax.swing.JLabel();
fileBrowserPanel1 = new keel.GraphInterKeel.datacf.util.FileBrowserPanel();
fileBrowserPanel1 = new keel.GraphInterKeel.datacf.util.FileBrowserPanel();
fileFilter = new KeelFileFilter();
fileFilter.addExtension("dat");
fileFilter.setFilterName("KEEL Files (.dat)");
fileBrowserPanel1.getFileChooser().addChoosableFileFilter(fileFilter);
fileBrowserPanel1.getFileChooser().setMultiSelectionEnabled(true);
setName("Form"); // NOI18N
setLayout(new java.awt.CardLayout());
exportSelectPanel.setMinimumSize(new java.awt.Dimension(638, 300));
exportSelectPanel.setName("exportSelectPanel"); // NOI18N
exportSelectPanel.setLayout(new java.awt.GridBagLayout());
exportSelectMainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Select Export Option"));
exportSelectMainPanel.setName("exportSelectMainPanel"); // NOI18N
exportSelectMainPanel.setLayout(new java.awt.GridBagLayout());
nextSelectDatasetButton.setText("Next->");
nextSelectDatasetButton.setToolTipText("Export Dataset");
nextSelectDatasetButton.setMaximumSize(new java.awt.Dimension(100, 100));
nextSelectDatasetButton.setMinimumSize(new java.awt.Dimension(88, 30));
nextSelectDatasetButton.setName("nextSelectDatasetButton"); // NOI18N
nextSelectDatasetButton.setPreferredSize(new java.awt.Dimension(88, 30));
nextSelectDatasetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextSelectDatasetButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
exportSelectMainPanel.add(nextSelectDatasetButton, gridBagConstraints);
datasetIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/keel/GraphInterKeel/resources/ico/datacf/exportDataset.png"))); // NOI18N
datasetIcon.setName("datasetIcon"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(10, 5, 0, 0);
exportSelectMainPanel.add(datasetIcon, gridBagConstraints);
nextSelectPartitionsButton.setText("Next->");
nextSelectPartitionsButton.setToolTipText("Export Partitions");
nextSelectPartitionsButton.setMaximumSize(new java.awt.Dimension(100, 100));
nextSelectPartitionsButton.setMinimumSize(new java.awt.Dimension(88, 30));
nextSelectPartitionsButton.setName("nextSelectPartitionsButton"); // NOI18N
nextSelectPartitionsButton.setPreferredSize(new java.awt.Dimension(88, 30));
nextSelectPartitionsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextSelectPartitionsButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
exportSelectMainPanel.add(nextSelectPartitionsButton, gridBagConstraints);
partitionsIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/keel/GraphInterKeel/resources/ico/datacf/exportPartitions.png"))); // NOI18N
partitionsIcon.setName("partitionsIcon"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(10, 5, 0, 0);
exportSelectMainPanel.add(partitionsIcon, gridBagConstraints);
exportSeparator.setOrientation(javax.swing.SwingConstants.VERTICAL);
exportSeparator.setName("exportSeparator"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridheight = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
exportSelectMainPanel.add(exportSeparator, gridBagConstraints);
exportDatasetLabel.setText("<html><b>Export Dataset</b><hr>Select this option if you want to export only a single file from KEEL format to other format.</html>");
exportDatasetLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
exportDatasetLabel.setMinimumSize(new java.awt.Dimension(250, 200));
exportDatasetLabel.setName("exportDatasetLabel"); // NOI18N
exportDatasetLabel.setPreferredSize(new java.awt.Dimension(250, 200));
exportDatasetLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
exportSelectMainPanel.add(exportDatasetLabel, gridBagConstraints);
exportPartitionsLabel.setText("<html><b>Export Partitions</b><hr>Select this option if you have partitions in KEEL format and you want to export them to other format.</html>");
exportPartitionsLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
exportPartitionsLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
exportPartitionsLabel.setMinimumSize(new java.awt.Dimension(250, 200));
exportPartitionsLabel.setName("exportPartitionsLabel"); // NOI18N
exportPartitionsLabel.setPreferredSize(new java.awt.Dimension(250, 200));
exportPartitionsLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
exportSelectMainPanel.add(exportPartitionsLabel, gridBagConstraints);
exportSelectPanel.add(exportSelectMainPanel, new java.awt.GridBagConstraints());
add(exportSelectPanel, "Select");
exportBrowserPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Export Dataset"));
exportBrowserPanel.setName("exportBrowserPanel"); // NOI18N
exportBrowserPanel.setLayout(new java.awt.GridBagLayout());
buttonPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Output Format"));
buttonPanel.setName("buttonPanel"); // NOI18N
optionsButton.setText("Options");
optionsButton.setToolTipText("Click to configure the options of this format");
optionsButton.setMinimumSize(new java.awt.Dimension(88, 30));
optionsButton.setName("optionsButton"); // NOI18N
optionsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
optionsButtonActionPerformed(evt);
}
});
outputFormatLabel.setText("Select Output Format");
outputFormatLabel.setName("outputFormatLabel"); // NOI18N
outputFormatComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Keel to CSV", "Keel to TXT", "Keel to PRN", "Keel to C4.5", "Keel to Excel", "Keel to Dif", "Keel to PropertyList", "Keel to Weka", "Keel to XML", "Keel to HTML Tab", "Keel to Database SQL" }));
outputFormatComboBox.setToolTipText("Select Output Format");
outputFormatComboBox.setName("outputFormatComboBox"); // NOI18N
exportOptionsDialog = new OptionsDialog(parent, true);
exportOptionsDialog.addProperty("Separator",",");
exportOptionsDialog.addProperty("Null Value","");
outputFormatComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
outputFormatComboBoxItemStateChanged(evt);
}
});
javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
buttonPanel.setLayout(buttonPanelLayout);
buttonPanelLayout.setHorizontalGroup(
buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(buttonPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(outputFormatLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(outputFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(optionsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(268, Short.MAX_VALUE))
);
buttonPanelLayout.setVerticalGroup(
buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(buttonPanelLayout.createSequentialGroup()
.addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(outputFormatLabel)
.addComponent(outputFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(optionsButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
exportBrowserPanel.add(buttonPanel, gridBagConstraints);
backBrowserButton.setText("<-Back");
backBrowserButton.setToolTipText("Return to previous window for selecting import option");
backBrowserButton.setMaximumSize(new java.awt.Dimension(100, 100));
backBrowserButton.setMinimumSize(new java.awt.Dimension(88, 30));
backBrowserButton.setName("backBrowserButton"); // NOI18N
backBrowserButton.setPreferredSize(new java.awt.Dimension(88, 30));
backBrowserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backBrowserButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
exportBrowserPanel.add(backBrowserButton, gridBagConstraints);
nextBrowserButton.setText("Next->");
nextBrowserButton.setToolTipText("Preview exported file");
nextBrowserButton.setMaximumSize(new java.awt.Dimension(100, 100));
nextBrowserButton.setMinimumSize(new java.awt.Dimension(88, 30));
nextBrowserButton.setName("nextBrowserButton"); // NOI18N
nextBrowserButton.setPreferredSize(new java.awt.Dimension(88, 30));
nextBrowserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextBrowserButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
exportBrowserPanel.add(nextBrowserButton, gridBagConstraints);
fileBrowserPanel.setName("fileBrowserPanel"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
exportBrowserPanel.add(fileBrowserPanel, gridBagConstraints);
add(exportBrowserPanel, "Browser");
exportPreviewPanel.setName("exportPreviewPanel"); // NOI18N
exportPreviewPanel.setLayout(new java.awt.GridLayout(1, 0));
mainPanel.setMinimumSize(new java.awt.Dimension(600, 190));
mainPanel.setName("mainPanel"); // NOI18N
mainPanel.setLayout(new java.awt.GridBagLayout());
leftPreviewPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
leftPreviewPanel.setMaximumSize(new java.awt.Dimension(10000000, 10000000));
leftPreviewPanel.setMinimumSize(new java.awt.Dimension(300, 124));
leftPreviewPanel.setName("leftPreviewPanel"); // NOI18N
originalScrollPanel.setName("originalScrollPanel"); // NOI18N
originalTextArea.setEditable(false);
originalTextArea.setMaximumSize(new java.awt.Dimension(999999999, 999999999));
originalTextArea.setMinimumSize(new java.awt.Dimension(260, 260));
originalTextArea.setName("originalTextArea"); // NOI18N
originalScrollPanel.setViewportView(originalTextArea);
originalSeparator.setName("originalSeparator"); // NOI18N
originalLabel.setText("Original File (KEEL format)");
originalLabel.setName("originalLabel"); // NOI18N
javax.swing.GroupLayout leftPreviewPanelLayout = new javax.swing.GroupLayout(leftPreviewPanel);
leftPreviewPanel.setLayout(leftPreviewPanelLayout);
leftPreviewPanelLayout.setHorizontalGroup(
leftPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(leftPreviewPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(leftPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(leftPreviewPanelLayout.createSequentialGroup()
.addComponent(originalScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
.addContainerGap())
.addComponent(originalSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
.addGroup(leftPreviewPanelLayout.createSequentialGroup()
.addComponent(originalLabel)
.addContainerGap(179, Short.MAX_VALUE))))
);
leftPreviewPanelLayout.setVerticalGroup(
leftPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(leftPreviewPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(originalLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(originalSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(originalScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
.addContainerGap())
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
mainPanel.add(leftPreviewPanel, gridBagConstraints);
rightPreviewPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
rightPreviewPanel.setMaximumSize(new java.awt.Dimension(10000000, 10000000));
rightPreviewPanel.setMinimumSize(new java.awt.Dimension(300, 124));
rightPreviewPanel.setName("rightPreviewPanel"); // NOI18N
resultScrollPanel.setName("resultScrollPanel"); // NOI18N
resultTextArea.setEditable(false);
resultTextArea.setMaximumSize(new java.awt.Dimension(999999999, 999999999));
resultTextArea.setMinimumSize(new java.awt.Dimension(260, 260));
resultTextArea.setName("resultTextArea"); // NOI18N
resultScrollPanel.setViewportView(resultTextArea);
resultSeparator.setName("resultSeparator"); // NOI18N
resultsLabel.setText("Exported File");
resultsLabel.setName("resultsLabel"); // NOI18N
javax.swing.GroupLayout rightPreviewPanelLayout = new javax.swing.GroupLayout(rightPreviewPanel);
rightPreviewPanel.setLayout(rightPreviewPanelLayout);
rightPreviewPanelLayout.setHorizontalGroup(
rightPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, rightPreviewPanelLayout.createSequentialGroup()
.addGroup(rightPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, rightPreviewPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(resultScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))
.addComponent(resultSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, rightPreviewPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(resultsLabel)))
.addContainerGap())
);
rightPreviewPanelLayout.setVerticalGroup(
rightPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(rightPreviewPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(resultsLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resultSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resultScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
.addContainerGap())
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
mainPanel.add(rightPreviewPanel, gridBagConstraints);
informationPartitionsLabel.setText("This is a previsualization of the result of exporting the files you have given");
informationPartitionsLabel.setName("informationPartitionsLabel"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(7, 6, 2, 0);
mainPanel.add(informationPartitionsLabel, gridBagConstraints);
nextPreviewButton.setText("Save");
nextPreviewButton.setToolTipText("Save the exported files");
nextPreviewButton.setMaximumSize(new java.awt.Dimension(100, 100));
nextPreviewButton.setMinimumSize(new java.awt.Dimension(88, 30));
nextPreviewButton.setName("nextPreviewButton"); // NOI18N
nextPreviewButton.setPreferredSize(new java.awt.Dimension(88, 30));
nextPreviewButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextPreviewButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
mainPanel.add(nextPreviewButton, gridBagConstraints);
backPreviewButton.setText("<-Back");
backPreviewButton.setToolTipText("Return to select files");
backPreviewButton.setMaximumSize(new java.awt.Dimension(100, 100));
backPreviewButton.setMinimumSize(new java.awt.Dimension(88, 30));
backPreviewButton.setName("backPreviewButton"); // NOI18N
backPreviewButton.setPreferredSize(new java.awt.Dimension(88, 30));
backPreviewButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backPreviewButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
mainPanel.add(backPreviewButton, gridBagConstraints);
exportPreviewPanel.add(mainPanel);
add(exportPreviewPanel, "Preview");
exportPartitionsPanel.setName("exportPartitionsPanel"); // NOI18N
mainPartitionsPanel.setName("mainPartitionsPanel"); // NOI18N
mainPartitionsPanel.setPreferredSize(new java.awt.Dimension(800, 800));
mainPartitionsPanel.setLayout(new java.awt.GridBagLayout());
informationLabel.setText("Export Partitions:");
informationLabel.setName("informationLabel"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 10;
gridBagConstraints.ipady = 5;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
mainPartitionsPanel.add(informationLabel, gridBagConstraints);
nextPartitionsButton.setText("Next->");
nextPartitionsButton.setToolTipText("Preview exported files");
nextPartitionsButton.setMaximumSize(new java.awt.Dimension(100, 100));
nextPartitionsButton.setMinimumSize(new java.awt.Dimension(88, 30));
nextPartitionsButton.setName("nextPartitionsButton"); // NOI18N
nextPartitionsButton.setPreferredSize(new java.awt.Dimension(88, 30));
nextPartitionsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextPartitionsButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
mainPartitionsPanel.add(nextPartitionsButton, gridBagConstraints);
backPartitionsButton.setText("<-Back");
backPartitionsButton.setToolTipText("Return to previous window for selecting export option");
backPartitionsButton.setMaximumSize(new java.awt.Dimension(100, 100));
backPartitionsButton.setMinimumSize(new java.awt.Dimension(88, 30));
backPartitionsButton.setName("backPartitionsButton"); // NOI18N
backPartitionsButton.setPreferredSize(new java.awt.Dimension(88, 30));
backPartitionsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backPartitionsButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
mainPartitionsPanel.add(backPartitionsButton, gridBagConstraints);
trainingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Training Files"));
trainingPanel.setName("trainingPanel"); // NOI18N
trainingScrollPanel.setName("trainingScrollPanel"); // NOI18N
trainingList.setName("trainingList"); // NOI18N
trainingScrollPanel.setViewportView(trainingList);
javax.swing.GroupLayout trainingPanelLayout = new javax.swing.GroupLayout(trainingPanel);
trainingPanel.setLayout(trainingPanelLayout);
trainingPanelLayout.setHorizontalGroup(
trainingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(trainingPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(trainingScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addContainerGap())
);
trainingPanelLayout.setVerticalGroup(
trainingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(trainingPanelLayout.createSequentialGroup()
.addComponent(trainingScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.addContainerGap())
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 0.2;
gridBagConstraints.weighty = 0.5;
mainPartitionsPanel.add(trainingPanel, gridBagConstraints);
testingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Test Files"));
testingPanel.setName("testingPanel"); // NOI18N
testingScrollPanel.setName("testingScrollPanel"); // NOI18N
testingList.setName("testingList"); // NOI18N
testingScrollPanel.setViewportView(testingList);
javax.swing.GroupLayout testingPanelLayout = new javax.swing.GroupLayout(testingPanel);
testingPanel.setLayout(testingPanelLayout);
testingPanelLayout.setHorizontalGroup(
testingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(testingPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(testingScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addContainerGap())
);
testingPanelLayout.setVerticalGroup(
testingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(testingPanelLayout.createSequentialGroup()
.addComponent(testingScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
.addContainerGap())
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 0.2;
gridBagConstraints.weighty = 0.5;
mainPartitionsPanel.add(testingPanel, gridBagConstraints);
cleanButton.setText("Clean");
cleanButton.setToolTipText("Clean training and test file");
cleanButton.setMaximumSize(new java.awt.Dimension(100, 100));
cleanButton.setMinimumSize(new java.awt.Dimension(88, 30));
cleanButton.setName("cleanButton"); // NOI18N
cleanButton.setPreferredSize(new java.awt.Dimension(69, 23));
cleanButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cleanButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
mainPartitionsPanel.add(cleanButton, gridBagConstraints);
trainingButtons.setName("trainingButtons"); // NOI18N
trainingButtons.setLayout(new java.awt.GridLayout(2, 1));
addTrainingButton.setText("-->");
addTrainingButton.setToolTipText("Add selected file to training files");
addTrainingButton.setName("addTrainingButton"); // NOI18N
addTrainingButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addTrainingButtonaddButtonActionPerformed(evt);
}
});
trainingButtons.add(addTrainingButton);
removeTrainingButton.setText("<--");
removeTrainingButton.setToolTipText("Remove selected file from training files");
removeTrainingButton.setName("removeTrainingButton"); // NOI18N
removeTrainingButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeTrainingButtonremoveButtonActionPerformed(evt);
}
});
trainingButtons.add(removeTrainingButton);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
mainPartitionsPanel.add(trainingButtons, gridBagConstraints);
testingButtons.setName("testingButtons"); // NOI18N
testingButtons.setLayout(new java.awt.GridLayout(2, 1));
addTestingButton.setText("-->");
addTestingButton.setToolTipText("Add selected file to test files");
addTestingButton.setName("addTestingButton"); // NOI18N
addTestingButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addTestingButtonaddButtonActionPerformed(evt);
}
});
testingButtons.add(addTestingButton);
removeTestingButton.setText("<--");
removeTestingButton.setToolTipText("Remove selected file from test files");
removeTestingButton.setName("removeTestingButton"); // NOI18N
removeTestingButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeTestingButtonremoveButtonActionPerformed(evt);
}
});
testingButtons.add(removeTestingButton);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
mainPartitionsPanel.add(testingButtons, gridBagConstraints);
outputFormatPartitionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Options"));
outputFormatPartitionsPanel.setName("outputFormatPartitionsPanel"); // NOI18N
optionsPartitionsButton.setText("Options");
optionsPartitionsButton.setToolTipText("Click to configure the options of this format");
optionsPartitionsButton.setMaximumSize(new java.awt.Dimension(100, 100));
optionsPartitionsButton.setMinimumSize(new java.awt.Dimension(88, 30));
optionsPartitionsButton.setName("optionsPartitionsButton"); // NOI18N
optionsPartitionsButton.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
optionsPartitionsButtonItemStateChanged(evt);
}
});
optionsPartitionsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
optionsPartitionsButtonActionPerformed(evt);
}
});
outputFormatPartitionsComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Keel to CSV", "Keel to TXT", "Keel to PRN", "Keel to C4.5", "Keel to Excel", "Keel to Dif", "Keel to PropertyList", "Keel to Weka", "Keel to XML", "Keel to HTML Tab" }));
outputFormatPartitionsComboBox.setToolTipText("Select Output Format");
outputFormatPartitionsComboBox.setName("outputFormatPartitionsComboBox"); // NOI18N
outputFormatPartitionsComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
outputFormatPartitionsComboBoxItemStateChanged(evt);
}
});
outputFormatPartitionsLabel.setText("Select Output Format");
outputFormatPartitionsLabel.setName("outputFormatPartitionsLabel"); // NOI18N
javax.swing.GroupLayout outputFormatPartitionsPanelLayout = new javax.swing.GroupLayout(outputFormatPartitionsPanel);
outputFormatPartitionsPanel.setLayout(outputFormatPartitionsPanelLayout);
outputFormatPartitionsPanelLayout.setHorizontalGroup(
outputFormatPartitionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outputFormatPartitionsPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(outputFormatPartitionsLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(outputFormatPartitionsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(optionsPartitionsButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(90, Short.MAX_VALUE))
);
outputFormatPartitionsPanelLayout.setVerticalGroup(
outputFormatPartitionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outputFormatPartitionsPanelLayout.createSequentialGroup()
.addGroup(outputFormatPartitionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(outputFormatPartitionsLabel)
.addComponent(outputFormatPartitionsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(optionsPartitionsButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridheight = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
mainPartitionsPanel.add(outputFormatPartitionsPanel, gridBagConstraints);
fileBrowserPanel1.setName("fileBrowserPanel1"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridheight = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 0.8;
mainPartitionsPanel.add(fileBrowserPanel1, gridBagConstraints);
javax.swing.GroupLayout exportPartitionsPanelLayout = new javax.swing.GroupLayout(exportPartitionsPanel);
exportPartitionsPanel.setLayout(exportPartitionsPanelLayout);
exportPartitionsPanelLayout.setHorizontalGroup(
exportPartitionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainPartitionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE)
);
exportPartitionsPanelLayout.setVerticalGroup(
exportPartitionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mainPartitionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
);
add(exportPartitionsPanel, "Partitions");
}// </editor-fold>//GEN-END:initComponents
private void nextSelectDatasetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextSelectDatasetButtonActionPerformed
lastSelectedPanel = "Select";
((CardLayout) this.getLayout()).show(this, "Browser");
datasets = true;
}//GEN-LAST:event_nextSelectDatasetButtonActionPerformed
private void nextSelectPartitionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextSelectPartitionsButtonActionPerformed
lastSelectedPanel = "Select";
((CardLayout) this.getLayout()).show(this, "Partitions");
datasets = false;
}//GEN-LAST:event_nextSelectPartitionsButtonActionPerformed
private void optionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsButtonActionPerformed
exportOptionsDialog.setVisible(true);
if (!exportOptionsDialog.isOk()) {
exportOptionsDialog = createNewOptionsDialog(((String) outputFormatComboBox.getSelectedItem()));
}
}//GEN-LAST:event_optionsButtonActionPerformed
private void outputFormatComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputFormatComboBoxItemStateChanged
if (((String) outputFormatComboBox.getSelectedItem()).equals("Keel to Dif") || ((String) outputFormatComboBox.getSelectedItem()).equals("Keel to PropertyList") || ((String) outputFormatComboBox.getSelectedItem()).equals("Keel to Weka") || ((String) outputFormatComboBox.getSelectedItem()).equals("Keel to XML") || ((String) outputFormatComboBox.getSelectedItem()).equals("Keel to HTML Tab")) {
optionsButton.setEnabled(false);
} else {
optionsButton.setEnabled(true);
}
exportOptionsDialog = createNewOptionsDialog(((String) outputFormatComboBox.getSelectedItem()));
}//GEN-LAST:event_outputFormatComboBoxItemStateChanged
private void nextBrowserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextBrowserButtonActionPerformed
File originalFile = null;
String outputFileName = null;
originalFile = fileBrowserPanel.getFileChooser().getSelectedFile();
if (originalFile == null) {
JOptionPane.showMessageDialog(this, "You have to select a file", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
outputFileName = convert(originalFile.getPath(), System.getProperty("java.io.tmpdir"));
if (outputFileName == null) {
return;
} else if (outputFileName.equals("")) {
return;
}
tmpTrainingExportedFile = new File(outputFileName);
showText(originalFile, originalTextArea);
if (!lastSelectedType.equals("Keel to Excel") && !lastSelectedType.equals("Keel to Database SQL")) {
showText(tmpTrainingExportedFile, resultTextArea);
} else {
resultTextArea.setText("Previsualization not available!");
}
informationPartitionsLabel.setText("This is a previsualization of the result of exporting the file you have given");
originalLabel.setText("Original File " + originalFile.getName() + " (KEEL format)");
String format = ((String) outputFormatComboBox.getSelectedItem());
if (!lastSelectedType.equals("Keel to Database SQL")) {
resultsLabel.setText("Exported File " + originalFile.getName() + " (" + format.substring(8) + " format)");
} else {
resultsLabel.setText("Exported Database (" + format.substring(8) + " format)");
}
lastSelectedPanel = "Browser";
((CardLayout) this.getLayout()).show(this, "Preview");
Path.setFilePath(fileBrowserPanel.getFileChooser().getCurrentDirectory());
fileBrowserPanel1.getFileChooser().setCurrentDirectory(Path.getFilePath());
}//GEN-LAST:event_nextBrowserButtonActionPerformed
private void backBrowserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBrowserButtonActionPerformed
lastSelectedPanel = "Browser";
((CardLayout) this.getLayout()).show(this, "Select");
Path.setFilePath(fileBrowserPanel.getFileChooser().getCurrentDirectory());
fileBrowserPanel1.getFileChooser().setCurrentDirectory(Path.getFilePath());
}//GEN-LAST:event_backBrowserButtonActionPerformed
private void nextPreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPreviewButtonActionPerformed
if (!datasets) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle("Select a folder to save the files");
chooser.setCurrentDirectory(Path.getFilePath());
String name = tmpTrainingExportedFile.getName();
int index = name.indexOf("-");
if (index == -1) {
index = name.lastIndexOf(".");
}
if (index == -1) {
index = name.length();
}
name = name.substring(0, index);
chooser.setSelectedFile(new File(Path.getFilePath() + File.separator + name));
int returnVal = chooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
Path.setFilePath(chooser.getCurrentDirectory());
File directory = new File(chooser.getSelectedFile().getPath());
if (!directory.exists()) {
if (!directory.mkdirs()) {
JOptionPane.showMessageDialog(this, "Problem Creating Directory", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
String outputPath = directory.getPath();
if (!outputPath.endsWith(File.separator)) {
outputPath = outputPath.concat(File.separator);
}
for (int i = 0; i < trainingModel.size(); i++) {
String ext = tmpTrainingExportedFile.getName();
ext = ext.substring(ext.lastIndexOf("."), ext.length());
File trainingFile = new File(outputPath + (new File((String) trainingModel.getElementAt(i))).getName().replaceAll(".dat", ext));
File testFile = new File(outputPath + (new File((String) testingModel.getElementAt(i))).getName().replaceAll(".dat", ext));
if (!wantToBeOverwritten(trainingFile) || !wantToBeOverwritten(testFile)) {
return;
}
}
try {
FileUtils.copy(tmpTrainingExportedFile.getPath(), outputPath + tmpTrainingExportedFile.getName());
tmpTrainingExportedFile.delete();
if (lastSelectedType.equals("Keel to C4.5")) {
File namesFile = new File(tmpTrainingExportedFile.getPath().replaceAll(".data", ".names"));
FileUtils.copy(namesFile.getPath(), outputPath + namesFile.getName());
namesFile.delete();
}
File firstTestFile = new File((String) testingModel.getElementAt(0));
String firstTestOutputFileName = convert(firstTestFile.getPath(), outputPath);
if (firstTestOutputFileName == null) {
return;
} else if (firstTestOutputFileName.equals("") || firstTestOutputFileName.equals("")) {
return;
}
for (int i = 1; i < trainingModel.size(); i++) {
File originalTrainingFile = new File((String) trainingModel.getElementAt(i));
File originalTestFile = new File((String) testingModel.getElementAt(i));
String trainingOutputFileName = convert(originalTrainingFile.getPath(), outputPath);
String testOutputFileName = convert(originalTestFile.getPath(), outputPath);
if (trainingOutputFileName == null || testOutputFileName == null) {
return;
} else if (trainingOutputFileName.equals("") || testOutputFileName.equals("")) {
return;
}
}
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, "Error importing data file:\n" + ex.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return;
}
((CardLayout) this.getLayout()).show(this, "Select");
datasets = false;
} else {
return;
}
} else {
String ext = "";
String desc = "";
if (lastSelectedType.equals("Keel to CSV")) {
ext = "csv";
desc = "CSV Files (.csv)";
} else if (lastSelectedType.equals("Keel to TXT")) {
ext = "txt";
desc = "TXT Files (.txt)";
} else if (lastSelectedType.equals("Keel to PRN")) {
ext = "prn";
desc = "PRN Files (.prn)";
} else if (lastSelectedType.equals("Keel to C4.5")) {
ext = "data";
desc = "C45 Files (.data)";
} else if (lastSelectedType.equals("Keel to Excel")) {
ext = "xls";
desc = "Excel Files (.xls)";
} else if (lastSelectedType.equals("Keel to Dif")) {
ext = "dif";
desc = "DIF Files (.dif)";
} else if (lastSelectedType.equals("Keel to PropertyList")) {
ext = "plist";
desc = "Properties' Files (.plist)";
} else if (lastSelectedType.equals("Keel to Weka")) {
ext = "arff";
desc = "Weka Files (.arff)";
} else if (lastSelectedType.equals("Keel to XML")) {
ext = "xml";
desc = "XML Files (.xml)";
} else if (lastSelectedType.equals("Keel to HTML Tab")) {
ext = "html";
desc = "HTML Files (.html)";
} else if (lastSelectedType.equals("Keel to Database SQL")) {
((CardLayout) this.getLayout()).show(this, "Select");
datasets = false;
return;
}
JFileChooser chooser = new JFileChooser();
KeelFileFilter fileFilter = new KeelFileFilter();
fileFilter.addExtension(ext);
fileFilter.setFilterName(desc);
chooser.setFileFilter(fileFilter);
chooser.setCurrentDirectory(Path.getFilePath());
//chooser.setName(ext);
chooser.setSelectedFile(new File(Path.getFilePath() + File.separator + tmpTrainingExportedFile.getName()));
int returnVal = chooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
Path.setFilePath(chooser.getCurrentDirectory());
File file = chooser.getSelectedFile();
if (!wantToBeOverwritten(file)) {
return;
}
try {
FileUtils.copy(tmpTrainingExportedFile.getPath(), file.getPath());
tmpTrainingExportedFile.delete();
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, "Error importing data file:\n" + ex.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return;
}
((CardLayout) this.getLayout()).show(this, "Select");
datasets = false;
} else {
return;
}
}
}//GEN-LAST:event_nextPreviewButtonActionPerformed
private void backPreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backPreviewButtonActionPerformed
if (tmpTrainingExportedFile != null) {
tmpTrainingExportedFile.delete();
// if(tmpTestingExportedFile!=null)
// tmpTestingExportedFile.delete();
}
((CardLayout) this.getLayout()).show(this, lastSelectedPanel);
lastSelectedPanel = "Preview";//GEN-LAST:event_backPreviewButtonActionPerformed
}
private void nextPartitionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPartitionsButtonActionPerformed
File originalTrainingFile = null;
File originalTestFile = null;
if (trainingModel.getSize() == 0 || testingModel.getSize() == 0) {
JOptionPane.showMessageDialog(this, "You have to select at least one training/test pair of files", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (trainingModel.getSize() != testingModel.getSize()) {
JOptionPane.showMessageDialog(this, "You have to select the same number of training and test files", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
originalTrainingFile = new File((String) trainingModel.firstElement());
originalTestFile = new File((String) testingModel.firstElement());
String trainingOutputFileName = convert(originalTrainingFile.getPath(), System.getProperty("java.io.tmpdir"));
// String testOutputFileName = convert(originalTestFile.getPath(), System.getProperty("java.io.tmpdir"));
if (trainingOutputFileName == null) {
return;
} else if (trainingOutputFileName.equals("")) {
return;
}
tmpTrainingExportedFile = new File(trainingOutputFileName);
// tmpTestingExportedFile = new File(testOutputFileName);
showText(originalTrainingFile, originalTextArea);
if (!lastSelectedType.equals("Keel to Excel")) {
showText(tmpTrainingExportedFile, resultTextArea);
} else {
resultTextArea.setText("Previsualization not available!");
}
informationPartitionsLabel.setText("This is a previsualization of the result of exporting the files you have given");
lastSelectedPanel = "Partitions";
String format = ((String) outputFormatPartitionsComboBox.getSelectedItem());
originalLabel.setText("Original File " + originalTrainingFile.getName() + " (KEEL format)");
resultsLabel.setText("Exported File " + tmpTrainingExportedFile.getName() + " (" + format.substring(8) + " format)");
((CardLayout) this.getLayout()).show(this, "Preview");
Path.setFilePath(fileBrowserPanel1.getFileChooser().getCurrentDirectory());
fileBrowserPanel.getFileChooser().setCurrentDirectory(Path.getFilePath());
}//GEN-LAST:event_nextPartitionsButtonActionPerformed
private void backPartitionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backPartitionsButtonActionPerformed
lastSelectedPanel = "Partitions";
((CardLayout) this.getLayout()).show(this, "Select");
Path.setFilePath(fileBrowserPanel1.getFileChooser().getCurrentDirectory());
fileBrowserPanel.getFileChooser().setCurrentDirectory(Path.getFilePath());
}//GEN-LAST:event_backPartitionsButtonActionPerformed
private void addTrainingButtonaddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTrainingButtonaddButtonActionPerformed
File[] files = fileBrowserPanel1.getFileChooser().getSelectedFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (!trainingModel.contains(files[i].getPath())) {
trainingModel.addElement(files[i].getPath());
}
}
}
}//GEN-LAST:event_addTrainingButtonaddButtonActionPerformed
private void removeTrainingButtonremoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTrainingButtonremoveButtonActionPerformed
Object[] seleccionados = trainingList.getSelectedValues();
if (seleccionados != null) {
for (int i = 0; i < seleccionados.length; i++) {
trainingModel.removeElement(seleccionados[i]);
}
}
}//GEN-LAST:event_removeTrainingButtonremoveButtonActionPerformed
private void addTestingButtonaddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTestingButtonaddButtonActionPerformed
File[] files = fileBrowserPanel1.getFileChooser().getSelectedFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (!testingModel.contains(files[i].getPath())) {
testingModel.addElement(files[i].getPath());
}
}
}
}//GEN-LAST:event_addTestingButtonaddButtonActionPerformed
private void removeTestingButtonremoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTestingButtonremoveButtonActionPerformed
int[] indices = testingList.getSelectedIndices();
if (indices != null) {
for (int i = 0; i < indices.length; i++) {
testingModel.remove(i);
}
}
}//GEN-LAST:event_removeTestingButtonremoveButtonActionPerformed
private void optionsPartitionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsPartitionsButtonActionPerformed
exportOptionsDialog.setVisible(true);
if (!exportOptionsDialog.isOk()) {
exportOptionsDialog = createNewOptionsDialog(((String) outputFormatPartitionsComboBox.getSelectedItem()));
}
}//GEN-LAST:event_optionsPartitionsButtonActionPerformed
private void outputFormatPartitionsComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputFormatPartitionsComboBoxItemStateChanged
if (((String) outputFormatPartitionsComboBox.getSelectedItem()).equals("Keel to Dif") || ((String) outputFormatPartitionsComboBox.getSelectedItem()).equals("Keel to PropertyList") || ((String) outputFormatPartitionsComboBox.getSelectedItem()).equals("Keel to Weka") || ((String) outputFormatPartitionsComboBox.getSelectedItem()).equals("Keel to XML") || ((String) outputFormatPartitionsComboBox.getSelectedItem()).equals("Keel to HTML Tab")) {
optionsPartitionsButton.setEnabled(false);
} else {
optionsPartitionsButton.setEnabled(true);
}
exportOptionsDialog = createNewOptionsDialog(((String) outputFormatPartitionsComboBox.getSelectedItem()));
}//GEN-LAST:event_outputFormatPartitionsComboBoxItemStateChanged
private void optionsPartitionsButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_optionsPartitionsButtonItemStateChanged
}//GEN-LAST:event_optionsPartitionsButtonItemStateChanged
private void cleanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cleanButtonActionPerformed
trainingModel.removeAllElements();
testingModel.removeAllElements();
}//GEN-LAST:event_cleanButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addTestingButton;
private javax.swing.JButton addTrainingButton;
private javax.swing.JButton backBrowserButton;
private javax.swing.JButton backPartitionsButton;
private javax.swing.JButton backPreviewButton;
private javax.swing.JPanel buttonPanel;
private javax.swing.JButton cleanButton;
private javax.swing.JLabel datasetIcon;
private javax.swing.JPanel exportBrowserPanel;
private javax.swing.JLabel exportDatasetLabel;
private javax.swing.JLabel exportPartitionsLabel;
private javax.swing.JPanel exportPartitionsPanel;
private javax.swing.JPanel exportPreviewPanel;
private javax.swing.JPanel exportSelectMainPanel;
private javax.swing.JPanel exportSelectPanel;
private javax.swing.JSeparator exportSeparator;
private keel.GraphInterKeel.datacf.util.FileBrowserPanel fileBrowserPanel;
private keel.GraphInterKeel.datacf.util.FileBrowserPanel fileBrowserPanel1;
private javax.swing.JLabel informationLabel;
private javax.swing.JLabel informationPartitionsLabel;
private javax.swing.JPanel leftPreviewPanel;
private javax.swing.JPanel mainPanel;
private javax.swing.JPanel mainPartitionsPanel;
private javax.swing.JButton nextBrowserButton;
private javax.swing.JButton nextPartitionsButton;
private javax.swing.JButton nextPreviewButton;
private javax.swing.JButton nextSelectDatasetButton;
private javax.swing.JButton nextSelectPartitionsButton;
private javax.swing.JButton optionsButton;
private javax.swing.JButton optionsPartitionsButton;
private javax.swing.JLabel originalLabel;
private javax.swing.JScrollPane originalScrollPanel;
private javax.swing.JSeparator originalSeparator;
private javax.swing.JTextArea originalTextArea;
private javax.swing.JComboBox outputFormatComboBox;
private javax.swing.JLabel outputFormatLabel;
private javax.swing.JComboBox outputFormatPartitionsComboBox;
private javax.swing.JLabel outputFormatPartitionsLabel;
private javax.swing.JPanel outputFormatPartitionsPanel;
private javax.swing.JLabel partitionsIcon;
private javax.swing.JButton removeTestingButton;
private javax.swing.JButton removeTrainingButton;
private javax.swing.JScrollPane resultScrollPanel;
private javax.swing.JSeparator resultSeparator;
private javax.swing.JTextArea resultTextArea;
private javax.swing.JLabel resultsLabel;
private javax.swing.JPanel rightPreviewPanel;
private javax.swing.JPanel testingButtons;
private javax.swing.JList testingList;
private javax.swing.JPanel testingPanel;
private javax.swing.JScrollPane testingScrollPanel;
private javax.swing.JPanel trainingButtons;
private javax.swing.JList trainingList;
private javax.swing.JPanel trainingPanel;
private javax.swing.JScrollPane trainingScrollPanel;
// End of variables declaration//GEN-END:variables
/** Parent frame */
protected JFrame parent = null;
/** String for having an history of the last selected panel */
protected String lastSelectedPanel = "";
/** Dataset mode (true) or partition mode (false) */
protected boolean datasets = false;
/** An option dialog for obtaining the options of the export proccess */
protected OptionsDialog exportOptionsDialog = null;
/** The model for storing the training files used in the partition mode */
protected DefaultListModel trainingModel = new DefaultListModel();
/** The model for storing the testing files used in the partition mode */
protected DefaultListModel testingModel = new DefaultListModel();
/** String for having an history of the last type of conversion */
protected String lastSelectedType = "Keel to CSV";
/** Temporal File used for previsualizing the results of the export proccess (in training)*/
protected File tmpTrainingExportedFile;
/**
* <p>
* Sets the JFrame parent
* </p>
* @param parent JFrame parent
*/
public void setParent(JFrame parent) {
this.parent = parent;
}
/**
* <p>
* Exports inputFile (in KEEL format) to outputFile (in a given format).
* </p>
* @param inputFile Path of the input file.
* @param outputFile Path of the output file.
*/
public String convert(String inputFile, String outputFile) {
if (exportOptionsDialog == null) {
return null;
}
String separatorValue = "";
String nullValueValue = "";
String dBdriver = "";
String dBURL = "";
String user = "";
Object passw = "";
String pathnameOutput = "";
// CSV file
// --------
if (lastSelectedType.equals("Keel to CSV")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
separatorValue = exportOptionsDialog.getOptionValue("Separator");
if (separatorValue.equals("")) {
separatorValue = "none";
}
nullValueValue = exportOptionsDialog.getOptionValue("Null Value");
String pathnameInput = inputFile;
pathnameOutput = outputFile;
String nullValue = nullValueValue;
String separator = separatorValue;
if (nullValue.equalsIgnoreCase("none")) {
nullValue = "";
}
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
/*Pattern p=Pattern.compile("\\.[A-Za-z]+");
Matcher m=p.matcher(filenameOutput);
filenameOutput=m.replaceAll("");*/
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".csv");
/* try
{
String cadena = "\n ficheroEntrada:"+ pathnameInput+"\n ficheroSalida:"+ pathnameOutput;
BufferedWriter fout = new BufferedWriter(new FileWriter("log.txt",true) );
fout.write(cadena,0,cadena.length());
fout.close();
}catch(IOException e1){
}
*/
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToCsv keel2csv = new KeelToCsv(nullValue, separator);
keel2csv.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToCsv.getStable())
// TXT file
// --------
if (lastSelectedType.equals("Keel to TXT")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
nullValueValue = exportOptionsDialog.getOptionValue("Null Value");
String pathnameInput = inputFile;
pathnameOutput = outputFile;
String nullValue = nullValueValue;
if (nullValue.equalsIgnoreCase("none")) {
nullValue = "";
}
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
/*Pattern p=Pattern.compile("\\.[A-Za-z]+");
Matcher m=p.matcher(filenameOutput);
filenameOutput=m.replaceAll("");*/
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".txt");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToTxt keel2txt = new KeelToTxt(nullValue);
keel2txt.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToTxt.getState())
// PRN file
// --------
if (lastSelectedType.equals("Keel to PRN")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
nullValueValue = exportOptionsDialog.getOptionValue("Null Value");
if (nullValueValue.equals("")) {
JOptionPane.showMessageDialog(this, "The null value parameter cannot be empty, change it in \"Options\"");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
String nullValue = nullValueValue;
if (nullValue.equalsIgnoreCase("none")) {
nullValue = "";
}
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
// String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".prn");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToPrn keel2prn = new KeelToPrn(nullValue);
keel2prn.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToPrn.getState())
// C4.5 file
// ---------
if (lastSelectedType.equals("Keel to C4.5")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
separatorValue = exportOptionsDialog.getOptionValue("Separator");
if (separatorValue.equals("")) {
JOptionPane.showMessageDialog(this, "The Separator parameter cannot be empty, change it in \"Options\"");
return null;
}
nullValueValue = exportOptionsDialog.getOptionValue("Null Value");
String pathnameInput = inputFile;
pathnameOutput = outputFile;
String nullValue = nullValueValue;
String separator = separatorValue;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
// String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
String pathnameOutputNames = pathnameOutput.concat(".names");
//String pathnameOutputData = pathnameOutput.concat(".data");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToUci keel2uci = new KeelToUci(nullValue, separator);
keel2uci.Start(pathnameInput, pathnameOutputNames, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
pathnameOutput = pathnameOutput.concat(".data");
}//end if(checkboxKeelToUci.getState())
// Excel file
// ----------
if (lastSelectedType.equals("Keel to Excel")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
nullValueValue = exportOptionsDialog.getOptionValue("Null Value");
String pathnameInput = inputFile;
pathnameOutput = outputFile;
String nullValue = nullValueValue;
if (nullValue.equals("?")) {
nullValue = "";
}
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".xls");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToExcel keel2excel = new KeelToExcel(nullValue);
keel2excel.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToExcel.getState())
// DIF file
// --------
if (lastSelectedType.equals("Keel to Dif")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".dif");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToDif keel2dif = new KeelToDif();
keel2dif.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxoKeelToDif.getState())
// Property list file
// ------------------
if (lastSelectedType.equals("Keel to PropertyList")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't existse");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".plist");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToPropertyList keel2propertylist = new KeelToPropertyList();
keel2propertylist.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToPlist.getState())
// Weka file
// ---------
if (lastSelectedType.equals("Keel to Weka")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".arff");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToWeka keel2weka = new KeelToWeka();
keel2weka.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToWeka.getState())
// XML file
// --------
if (lastSelectedType.equals("Keel to XML")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
// pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".xml");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToXml keel2xml = new KeelToXml();
keel2xml.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToXml.getState())
// HTML Tab file
// -------------
if (lastSelectedType.equals("Keel to HTML Tab")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Input file doesn't exists");
return null;
}
File fileOutput = new File(outputFile);
if (!fileOutput.exists()) {
JOptionPane.showMessageDialog(this, "The output path doesn't exists");
return null;
}
String pathnameInput = inputFile;
pathnameOutput = outputFile;
File fileInput1 = new File(pathnameInput);
// Obtenemos la ruta del fichero de salida
String filenameOutput = fileInput1.getName();
// le quito la extension al nombre del fichero
filenameOutput = filenameOutput.substring(0, filenameOutput.indexOf('.'));
String folder = filenameOutput;
String separatorFile = File.separator;
if (!pathnameOutput.endsWith(separatorFile)) {
pathnameOutput = pathnameOutput.concat(separatorFile);
}
pathnameOutput = pathnameOutput.concat(folder + separatorFile);
File fileOutput1 = new File(pathnameOutput);
fileOutput1.mkdirs();
pathnameOutput = pathnameOutput.concat(filenameOutput);
pathnameOutput = pathnameOutput.concat(".html");
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToHtml keel2html = new KeelToHtml();
keel2html.Start(pathnameInput, pathnameOutput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToHtml.getState())
// Database
// --------
if (lastSelectedType.equals("Keel to Database SQL")) {
File fileInput = new File(inputFile);
if (!fileInput.exists()) {
JOptionPane.showMessageDialog(this, "Please select an output path");
return null;
}
dBdriver = exportOptionsDialog.getOptionValue("Driver");
dBURL = exportOptionsDialog.getOptionValue("Database URL");
user = exportOptionsDialog.getOptionValue("User");
passw = exportOptionsDialog.getOptionValue("Password");
if (dBdriver.equals("")) {
JOptionPane.showMessageDialog(this, "The Driver parameter cannot be empty, change it in \"Options\"");
return null;
}
if (dBURL.equals("")) {
JOptionPane.showMessageDialog(this, "The Database-URL parameter cannot be empty, change it in \"Options\"");
return null;
}
String tableName = fileInput.getName();
tableName = tableName.substring(0, tableName.indexOf('.'));
String pathnameInput = inputFile;
String driverName = dBdriver;
String databaseURL = dBURL;
String login = user;
String password = passw.toString();
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
KeelToDb keel2db = new KeelToDb(driverName, databaseURL, tableName, login, password);
keel2db.Start(pathnameInput);
this.setCursor(Cursor.getDefaultCursor());
//JOptionPane.showMessageDialog(this, "File " + fileInput.getName() + " correctly exported");
} catch (Exception ex) {
this.setCursor(Cursor.getDefaultCursor());
JOptionPane.showMessageDialog(this, "Error exporting data file", "Error", JOptionPane.ERROR_MESSAGE);
}
}//end if(checkboxKeelToDb.getState())
return pathnameOutput;
}
/**
* <p>
* Creates an options dialog with the options corresponding to a type
* of conversion
* </p>
* @param type String with the type of conversion
* @return OptionsDialog New options dialog.
*/
private OptionsDialog createNewOptionsDialog(String type) {
OptionsDialog newExportOptionsDialog = new OptionsDialog(parent, true);
if (type.equals("Keel to CSV")) {
newExportOptionsDialog.addProperty("Separator", ",");
newExportOptionsDialog.addProperty("Null Value", "");
} else if (type.equals("Keel to TXT")) {
newExportOptionsDialog.addProperty("Null Value", "");
} else if (type.equals("Keel to PRN")) {
newExportOptionsDialog.addProperty("Null Value", "?");
} else if (type.equals("Keel to C4.5")) {
newExportOptionsDialog.addProperty("Separator", ",");
newExportOptionsDialog.addProperty("Null Value", "");
} else if (type.equals("Keel to Excel")) {
newExportOptionsDialog.addProperty("Null Value", "");
} else if (type.equals("Keel to Database SQL")) {
newExportOptionsDialog.addProperty("Driver", "sun.jdbc.odbc.JdbcOdbcDriver");
newExportOptionsDialog.addProperty("Database URL", "jdbc:subprotocol:subname");
newExportOptionsDialog.addProperty("User", "");
newExportOptionsDialog.addProperty("Password", "");
}
lastSelectedType = type;
return newExportOptionsDialog;
}
/**
* <p>
* Shows the text of a file in a JTextArea
* </p>
* @param file File to be shown
* @param textArea JTextArea to include the text
*/
private void showText(File file, JTextArea textArea) {
FileReader in = null;
try {
in = new FileReader(file);
textArea.read(in, file.toString());
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* <p>
* Shows an Option Dialog for confirming if a file should be overwritten
* (if the file exists)
* </p>
* @param file File object to check if it should be overwritten
* @return boolean This value indicates if the file should be overwritten
*/
private boolean wantToBeOverwritten(File file) {
// Check if the file exists
if (file.exists()) {
// Do you want to overwrite the file?
Object[] options = {"Yes",
"No"
};
int n = JOptionPane.showOptionDialog(parent,
"File \"" + file.getName() + "\" exists.\nDo you want to overwrite it?",
"File exists",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
if (n == 1) {
return false;
}
}
return true;
}
}