List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Setup the environment to save the current SPARQL results to a file. * /* w w w . ja v a2 s .c o m*/ * @see #writeSparqlResults(File) */ private void setupToWriteSparqlResults() { JFileChooser fileChooser; File destinationFile; int choice; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); if (sparqlResultsExportFile != null) { fileChooser.setSelectedFile(sparqlResultsExportFile); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save SPARQL Results to File (Format:" + (setupExportSparqlResultsAsCsv.isSelected() ? "CSV" : "TSV") + ")"); choice = fileChooser.showSaveDialog(this); destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } if (okToOverwriteFile(destinationFile)) { sparqlResultsExportFile = destinationFile; runSparqlResultsExport(); } }
From source file:app.RunApp.java
/** * Action of Save datasets button on Transformation tab * // w w w .j av a 2s. com * @param evt Event */ private void jButtonSaveDatasetsTransActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveDatasetsTransActionPerformed try { if (dataset == null) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "alert", JOptionPane.ERROR_MESSAGE); return; } if ((transformedDatasets == null || transformedDatasets.isEmpty())) { JOptionPane.showMessageDialog(null, "You must click on Start before.", "alert", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String dataName = datasetName.substring(0, datasetName.length() - 5); if (fc.isDirectorySelectionEnabled()) { if (radioBRTrans.isSelected()) { for (int i = 0; i < transformedDatasets.size(); i++) { ArffSaver saver = new ArffSaver(); saver.setInstances(transformedDatasets.get(i)); saver.setFile(new File( file.getAbsolutePath() + "/" + dataName + "_BRTransformed_" + i + ".arff")); saver.writeBatch(); } } else if (radioLPTrans.isSelected()) { ArffSaver saver = new ArffSaver(); saver.setInstances(transformedDatasets.get(0)); saver.setFile( new File(file.getAbsolutePath() + "/" + dataName + "_LPTransformed" + ".arff")); saver.writeBatch(); } else if (radioRemoveLabelsTrans.isSelected()) { ArffSaver saver = new ArffSaver(); saver.setInstances(transformedDatasets.get(0)); saver.setFile(new File( file.getAbsolutePath() + "/" + dataName + "_RemoveAllLabelsTransformed" + ".arff")); saver.writeBatch(); } else if (radioIncludeLabelsTrans.isSelected()) { ArffSaver saver = new ArffSaver(); saver.setInstances(transformedDatasets.get(0)); saver.setFile(new File( file.getAbsolutePath() + "/" + dataName + "_IncludeLabelsTransformed" + ".arff")); saver.writeBatch(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } } } catch (HeadlessException | IOException e) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, e); } }
From source file:app.RunApp.java
/** * Save MVML datasets/* w w w . ja v a2 s . co m*/ * * @return Positive number if successfull and negative otherwise */ private int saveMultiView() { if (dataset == null) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "alert", JOptionPane.ERROR_MESSAGE); return -1; } int[] selecteds = jTable2.getSelectedRows(); if (selecteds.length == 0) { JOptionPane.showMessageDialog(null, "You must select at least one view.", "alert", JOptionPane.ERROR_MESSAGE); return -1; } MultiLabelInstances mvData; int attSize = 0; for (int n : selecteds) { attSize += views.get("View " + (n + 1)).length; } int[] attToKeep = new int[attSize]; Integer[] view_i; int j = 0; for (int n : selecteds) { view_i = views.get("View " + (n + 1)); for (int k : view_i) { attToKeep[j] = k; j++; } } FeatureSelector fs = new FeatureSelector(dataset, attSize); mvData = fs.keepAttributes(attToKeep); try { String format = jComboBox_SaveFormat1.getSelectedItem().toString(); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String xmlPath; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (fc.isDirectorySelectionEnabled()) { String preprocessedType = "-views"; for (int n : selecteds) { preprocessedType += "_" + (n + 1); } BufferedWriter bwTrain; try { String dataName = datasetName.substring(0, datasetName.length() - 5); int sumNotSelected = 0; Hashtable<String, Integer[]> v = new Hashtable<>(); for (int i = 0; i < views.size(); i++) { if (Utils.contains(selecteds, i)) { Integer[] A = views.get("View " + (i + 1)); for (int a = 0; a < A.length; a++) { A[a] -= sumNotSelected; } v.put("View " + (i + 1), A); } else { sumNotSelected += views.get("View " + (i + 1))[views.get("View " + (i + 1)).length - 1] - views.get("View " + (i + 1))[0] + 1; } } String viewsString = "-V:"; for (int n : selecteds) { attSize += v.get("View " + (n + 1)).length; viewsString += viewsIntervals.get("View " + (n + 1)) + "!"; //viewsString += v.get("View " + (n+1))[0] + "-" + v.get("View " + (n+1))[v.get("View " + (n+1)).length-1] + "!"; } viewsString += ";"; viewsString = viewsString.replace("!;", ""); if (format.toLowerCase().contains("meka")) { String dataPath = file.getAbsolutePath() + "/" + dataName + preprocessedType + ".arff"; bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); DataIOUtils.saveMVMekaDataset(wrTrain, mvData, dataName, viewsString); wrTrain.close(); bwTrain.close(); } else { String dataPath = file.getAbsolutePath() + "/" + dataName + preprocessedType + ".arff"; xmlPath = file.getAbsolutePath() + "/" + dataName + preprocessedType + ".xml"; System.out.println("dataPath: " + dataPath); bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); DataIOUtils.saveDatasetMV(wrTrain, mvData, dataName, viewsString); wrTrain.close(); bwTrain.close(); BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.saveXMLFile(wrXml, mvData); wrXml.close(); bwXml.close(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "The selected folder to save the dataset does not exist. \nPlease select a correct folder.", "alert", JOptionPane.ERROR_MESSAGE); Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); return -1; } Toolkit.getDefaultToolkit().beep(); } } } catch (Exception e) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return -1; } return 1; }
From source file:app.RunApp.java
/** * Save heatmap graph as image//w w w .ja v a2s. co m * * @throws AWTException * @throws IOException */ private void saveHeatmapGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture( new Rectangle(panelHeatmap.getLocationOnScreen().x + 31, panelHeatmap.getLocationOnScreen().y + 31, panelHeatmap.getWidth() - 61, panelHeatmap.getHeight() - 61)); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Save co-ocurrence graph as image//from w ww. j a v a2s . co m * * @throws AWTException * @throws IOException */ private void saveCoocurrenceGraph() throws AWTException, IOException { BufferedImage image = new Robot().createScreenCapture(new Rectangle( panelCoOcurrenceRight.getLocationOnScreen().x, panelCoOcurrenceRight.getLocationOnScreen().y, panelCoOcurrenceRight.getWidth(), panelCoOcurrenceRight.getHeight())); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".png", "png"); fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); fc.addChoosableFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png"); ImageIO.write(image, "png", file); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); Toolkit.getDefaultToolkit().beep(); } }
From source file:app.RunApp.java
/** * Action of Save table button in MVML tab * /*from w ww. j a v a 2 s . com*/ * @param evt Event */ private void buttonSaveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveTableActionPerformed if (jTable2.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); if (f1.getDescription().equals(".csv")) { try { String path = file.getAbsolutePath() + ".csv"; BufferedWriter bw = new BufferedWriter(new FileWriter(path)); PrintWriter wr = new PrintWriter(bw); ResultsIOUtils.saveMVTableCsv(wr, jTable2, views, dataset); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Action for Export button/* w w w . j a v a 2s . com*/ * * @param evt Event * @param jtable Table */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable) { if (jtable.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); if (f1.getDescription().equals(".csv")) { try { String path = file.getAbsolutePath() + ".csv"; BufferedWriter bw = new BufferedWriter(new FileWriter(path)); PrintWriter wr = new PrintWriter(bw); switch (comboBoxLabelsInformation.getSelectedIndex()) { case 1: ResultsIOUtils.saveTableLabelsetsFrequencyCsv(wr, jtable, labelsetStringsByFreq); break; case 6: ResultsIOUtils.saveTableLabelsetsIRCsv(wr, jtable, labelsetStringByIR); break; default: ResultsIOUtils.saveTableCsv(wr, jtable); break; } wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Action for Export button/* w ww.jav a 2 s .c o m*/ * * @param evt Event * @param jtable Table * @param columns Columns * @param table Table type */ private void buttonExportActionPerformed(java.awt.event.ActionEvent evt, JTable jtable, JTable columns, String table) { if (jtable.getRowCount() == 0 || dataset == null) { JOptionPane.showMessageDialog(null, "The table is empty.", "Error", JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); //FileNameExtensionFilter fname = new FileNameExtensionFilter(".xls", "xls"); FileNameExtensionFilter fname1 = new FileNameExtensionFilter(".csv", "csv"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.setFileFilter(fname1); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); //Saving csv chi_phi if (f1.getDescription().equals(".csv")) { BufferedWriter bw; PrintWriter wr; try { String path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); switch (table) { case "ChiPhi": ResultsIOUtils.saveChiPhiTableCsv(wr, chiPhiCoefficients, dataset.getLabelNames()); break; case "Coocurrence": ResultsIOUtils.saveCoocurrenceTableCsv(wr, coocurrenceCoefficients, dataset.getLabelNames()); break; case "Heatmap": ResultsIOUtils.saveHeatmapTableCsv(wr, heatmapCoefficients, dataset.getLabelNames()); break; default: JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); break; } wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "File not saved correctly.", "Error", JOptionPane.ERROR_MESSAGE); } } } }
From source file:app.RunApp.java
/** * Action of Save datasets button in Preprocess tab * /*from w ww .java 2 s . c o m*/ * @param evt Event */ private void jButtonSaveDatasetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveDatasetsActionPerformed try { /* If only FS is selected, save FS dataset If any splitting method is selected, save the splitted datasets (those are FS too if it has been selected) */ String format = jComboBoxSaveFormat.getSelectedItem().toString(); if (dataset == null) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "alert", JOptionPane.ERROR_MESSAGE); return; } if (!(radioNoFS.isSelected() && radioNoIS.isSelected() && radioNoSplit.isSelected())) { if ((trainDatasets.isEmpty() && testDatasets.isEmpty()) && (radioRandomCV.isSelected() || radioIterativeStratifiedCV.isSelected() || radioLPStratifiedCV.isSelected())) { JOptionPane.showMessageDialog(null, "You must click on Start before.", "alert", JOptionPane.ERROR_MESSAGE); return; } if ((trainDataset == null && testDataset == null) && (radioIterativeStratifiedHoldout.isSelected() || radioRandomHoldout.isSelected() || radioLPStratifiedHoldout.isSelected())) { JOptionPane.showMessageDialog(null, "You must click on Start before.", "alert", JOptionPane.ERROR_MESSAGE); return; } if ((preprocessedDataset == null) && (radioBRFS.isSelected() || radioRandomFS.isSelected())) { JOptionPane.showMessageDialog(null, "You must click on Start before.", "alert", JOptionPane.ERROR_MESSAGE); return; } } //JFileChooser save JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String trainPath, testPath, xmlPath; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (fc.isDirectorySelectionEnabled()) { String dataName = datasetName.substring(0, datasetName.length() - 5); if (radioRandomIS.isSelected()) { dataName += "-randomIS"; } if (radioRandomFS.isSelected()) { dataName += "-randomFS"; } else if (radioBRFS.isSelected()) { dataName += "-BRFS"; } if (radioRandomCV.isSelected() || radioRandomHoldout.isSelected()) { dataName += "-random"; } else if (radioIterativeStratifiedCV.isSelected() || radioIterativeStratifiedHoldout.isSelected()) { dataName += "-iterative"; } else if (radioLPStratifiedCV.isSelected() || radioLPStratifiedHoldout.isSelected()) { dataName += "-LP"; } if ((radioNoIS.isSelected()) && (radioNoFS.isSelected()) && (radioNoSplit.isSelected())) { if (format.toLowerCase().contains("meka")) { dataName += "-mekaConverted"; } else if (format.toLowerCase().contains("mulan")) { dataName += "-mulanConverted"; } } //Check if none were selected -> Dataset conversion if (radioNoFS.isSelected() && radioNoIS.isSelected() && radioNoSplit.isSelected()) { BufferedWriter bwTrain; try { if (format.toLowerCase().contains("meka")) { String dataPath = file.getAbsolutePath() + "/" + dataName + ".arff"; bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); DataIOUtils.saveMekaDataset(wrTrain, dataset, dataset.getDataSet().relationName()); wrTrain.close(); bwTrain.close(); } else { String dataPath = file.getAbsolutePath() + "/" + dataName + ".arff"; xmlPath = file.getAbsolutePath() + "/" + dataName + ".xml"; bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); DataIOUtils.saveDataset(wrTrain, dataset, dataset.getDataSet().relationName()); wrTrain.close(); bwTrain.close(); BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.saveXMLFile(wrXml, dataset); wrXml.close(); bwXml.close(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } } //check if only FS and/or IS is selected if ((radioBRFS.isSelected() || radioRandomFS.isSelected() || radioRandomIS.isSelected()) && radioNoSplit.isSelected())//Feature and/or instance selection { BufferedWriter bwTrain; try { if (format.toLowerCase().contains("meka")) { String dataPath = file.getAbsolutePath() + "/" + dataName + ".arff"; bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); if (radioNoFS.isSelected()) { DataIOUtils.saveMekaDataset(wrTrain, preprocessedDataset, preprocessedDataset.getDataSet().relationName()); } else { DataIOUtils.saveMekaDataset(wrTrain, preprocessedDataset, dataName); } wrTrain.close(); bwTrain.close(); } else { String dataPath = file.getAbsolutePath() + "/" + dataName + ".arff"; xmlPath = file.getAbsolutePath() + "/" + dataName + ".xml"; bwTrain = new BufferedWriter(new FileWriter(dataPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); if (radioNoFS.isSelected()) { DataIOUtils.saveDataset(wrTrain, preprocessedDataset, preprocessedDataset.getDataSet().relationName()); } else { DataIOUtils.saveDataset(wrTrain, preprocessedDataset, dataName); } wrTrain.close(); bwTrain.close(); BufferedWriter bw_xml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wr_xml = new PrintWriter(bw_xml); DataIOUtils.saveXMLFile(wr_xml, preprocessedDataset); wr_xml.close(); bw_xml.close(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } } if (radioIterativeStratifiedHoldout.isSelected() || radioRandomHoldout.isSelected() || radioLPStratifiedHoldout.isSelected()) //holdout { BufferedWriter bwTrain; try { trainPath = file.getAbsolutePath() + "/" + dataName + "_train.arff"; testPath = file.getAbsolutePath() + "/" + dataName + "_test.arff"; xmlPath = file.getAbsolutePath() + "/" + dataName + ".xml"; if (format.toLowerCase().contains("meka")) { bwTrain = new BufferedWriter(new FileWriter(trainPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); if (radioNoFS.isSelected()) { DataIOUtils.saveMekaDataset(wrTrain, trainDataset, trainDataset.getDataSet().relationName()); } else { DataIOUtils.saveMekaDataset(wrTrain, trainDataset, dataName); } wrTrain.close(); bwTrain.close(); BufferedWriter bwTest = new BufferedWriter(new FileWriter(testPath)); PrintWriter wrTest = new PrintWriter(bwTest); if (radioNoFS.isSelected()) { DataIOUtils.saveMekaDataset(wrTest, testDataset, testDataset.getDataSet().relationName()); } else { DataIOUtils.saveMekaDataset(wrTest, testDataset, dataName); } wrTest.close(); bwTest.close(); } else { bwTrain = new BufferedWriter(new FileWriter(trainPath)); PrintWriter wrTrain = new PrintWriter(bwTrain); if (radioNoFS.isSelected()) { DataIOUtils.saveDataset(wrTrain, trainDataset, trainDataset.getDataSet().relationName()); } else { DataIOUtils.saveDataset(wrTrain, trainDataset, dataName); } wrTrain.close(); bwTrain.close(); BufferedWriter bwTest = new BufferedWriter(new FileWriter(testPath)); PrintWriter wrTest = new PrintWriter(bwTest); if (radioNoFS.isSelected()) { DataIOUtils.saveDataset(wrTest, testDataset, testDataset.getDataSet().relationName()); } else { DataIOUtils.saveDataset(wrTest, testDataset, dataName); } wrTest.close(); bwTest.close(); BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.saveXMLFile(wrXml, trainDataset); wrXml.close(); bwXml.close(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } } else if (radioIterativeStratifiedCV.isSelected() || radioRandomCV.isSelected() || radioLPStratifiedCV.isSelected())//CROSS VALIDATION { try { if (format.toLowerCase().contains("meka")) { DataIOUtils.saveMekaDataset(trainDatasets, file.getAbsolutePath(), dataName, "_train"); DataIOUtils.saveMekaDataset(testDatasets, file.getAbsolutePath(), dataName, "_test"); /* if(radioNoFS.isSelected() && radioNoIS.isSelected()){ DataIOUtils.saveMekaDataset(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveMekaDataset(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); } if(radioNoFS.isSelected()){ DataIOUtils.saveMekaDataset(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveMekaDataset(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); } else{ DataIOUtils.saveMekaDatasetsNoViews(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveMekaDatasetsNoViews(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); } */ } else { /* if(radioNoFS.isSelected() && radioNoIS.isSelected()){ DataIOUtils.saveDatasets(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveDatasets(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); xmlPath = file.getAbsolutePath()+"/"+datasetName.substring(0,datasetName.length()-5)+".xml"; } else if(radioNoFS.isSelected()){ DataIOUtils.saveDatasets(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveDatasets(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); xmlPath = file.getAbsolutePath()+"/"+datasetName.substring(0,datasetName.length()-5) + ".xml"; } else{ DataIOUtils.saveMVDatasets(trainDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_train"); DataIOUtils.saveMVDatasets(testDatasets,file.getAbsolutePath(), datasetName.substring(0,datasetName.length()-5), "_test"); xmlPath = file.getAbsolutePath()+"/"+datasetName.substring(0,datasetName.length()-5)+ ".xml"; } */ DataIOUtils.saveDatasets(trainDatasets, file.getAbsolutePath(), dataName, "_train"); DataIOUtils.saveDatasets(testDatasets, file.getAbsolutePath(), dataName, "_test"); xmlPath = file.getAbsolutePath() + "/" + dataName + ".xml"; BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.saveXMLFile(wrXml, trainDatasets.get(0)); wrXml.close(); bwXml.close(); } JOptionPane.showMessageDialog(null, "All files have been saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); } catch (IOException | HeadlessException e1) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } Toolkit.getDefaultToolkit().beep(); } } } catch (Exception e) { JOptionPane.showMessageDialog(null, "An error ocurred while saving the dataset files.", "alert", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }
From source file:app.RunApp.java
/** * Action for Save button from multiple datasets tab * /*from w w w . j ava 2 s .c o m*/ * @param evt Event * @param jtable Table * @throws IOException */ private void buttonSaveActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) throws IOException { ArrayList<String> metricsList = getSelectedMetricsMulti(jtable); if (listDatasets == null || listDatasets.isEmpty() || datasetNames.isEmpty()) { JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE); return; } //JFileChooser save JFileChooser fc = new JFileChooser(); FileNameExtensionFilter fname = new FileNameExtensionFilter(".txt", "txt"); FileNameExtensionFilter fname2 = new FileNameExtensionFilter(".csv", "csv"); FileNameExtensionFilter fname3 = new FileNameExtensionFilter(".arff", ".arff"); FileNameExtensionFilter fname4 = new FileNameExtensionFilter(".tex", ".tex"); //Remove default fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]); fc.addChoosableFileFilter(fname); fc.addChoosableFileFilter(fname2); fc.addChoosableFileFilter(fname3); fc.addChoosableFileFilter(fname4); fc.setFileFilter(fname); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileFilter f1 = fc.getFileFilter(); String path; BufferedWriter bw; PrintWriter wr; switch (f1.getDescription()) { case ".txt": path = file.getAbsolutePath() + ".txt"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsTxt(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".tex": path = file.getAbsolutePath() + ".tex"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsTex(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".csv": path = file.getAbsolutePath() + ".csv"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsCsv(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; case ".arff": path = file.getAbsolutePath() + ".arff"; bw = new BufferedWriter(new FileWriter(path)); wr = new PrintWriter(bw); ResultsIOUtils.saveMultiMetricsArff(wr, metricsList, datasetNames, tableMetricsMulti); wr.close(); bw.close(); JOptionPane.showMessageDialog(null, "File saved.", "Successful", JOptionPane.INFORMATION_MESSAGE); break; default: break; } Toolkit.getDefaultToolkit().beep(); } }