Example usage for javax.swing JFileChooser DIRECTORIES_ONLY

List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY

Introduction

In this page you can find the example usage for javax.swing JFileChooser DIRECTORIES_ONLY.

Prototype

int DIRECTORIES_ONLY

To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.

Click Source Link

Document

Instruction to display only directories.

Usage

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemJEPlusEAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemJEPlusEAActionPerformed
    // Check if JEPlus+EA folder is available
    if (JEPlusConfig.getDefaultInstance().getJEPlusEADir() == null) {
        // Select a file to open
        fc.resetChoosableFileFilters();/*from www.j ava 2 s  .  c o m*/
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setCurrentDirectory(new File("./"));
        fc.setMultiSelectionEnabled(false);
        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            String path = fc.getSelectedFile().getPath() + File.separator;
            JEPlusConfig.getDefaultInstance().setJEPlusEADir(path);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        } else {
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            return;
        }
    }
    // Launch JESS Client
    new Thread(new Runnable() {
        @Override
        public void run() {
            List<String> command = new ArrayList<>();
            command.add("java");
            command.add("-jar");
            command.add("jEPlus+EA.jar");
            command.add(getCurrentProjectFile());
            ProcessBuilder builder = new ProcessBuilder(command);
            builder.directory(new File(JEPlusConfig.getDefaultInstance().getJEPlusEADir()));
            builder.redirectErrorStream(true);
            try {
                Process proc = builder.start();
                // int ExitValue = proc.waitFor();
                try (BufferedReader ins = new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
                    int res = ins.read();
                    while (res != -1) {
                        res = ins.read();
                    }
                }
            } catch (IOException ex) {
                logger.error("Cannot run jEPlus+EA.", ex);
            }
        }
    }, "jEPlus+EA").start();
}

From source file:au.org.ala.delta.intkey.Intkey.java

/**
 * This method saves information about the currently opened dataset:<br/>
 * 1. If the dataset was downloaded from a remote location, the user will be
 * given the option to save it to disk<br/>
 * 2. The dataset is added to the list of most recently used datasets<br/>
 * 3. If the dataset is not currently saved in the dataset index, the user
 * will be given the option to do this.//w  w  w . j a v a  2  s  .  c o m
 */
private void saveCurrentlyOpenedDataset() {
    String datasetTitle = _context.getDataset().getHeadingWithoutFormatting();

    // if the dataset was downloaded, ask the user if they wish to save it
    StartupFileData startupFileData = _context.getStartupFileData();

    boolean remoteDatasetSavedLocally = false;

    // Always use the path to the startup file supplied to the NEWDATASET
    // directive
    // Ignore the "inkFile" URL listed in the startup file.
    String datasetPath;
    URL startupFileURL = _context.getDatasetStartupURL();
    if (startupFileURL.getProtocol().equalsIgnoreCase("file")) {
        try {
            datasetPath = new File(startupFileURL.toURI()).getAbsolutePath();
        } catch (URISyntaxException ex) {
            datasetPath = startupFileURL.toString();
        }
    } else {
        datasetPath = startupFileURL.toString();
    }

    if (startupFileData != null && startupFileData.isRemoteDataset()) {
        int chosenOption = JOptionPane.showConfirmDialog(getMainFrame(),
                UIUtils.getResourceString("SaveDownloadedDatasetPrompt.caption", datasetTitle),
                UIUtils.getResourceString("Save.caption"), JOptionPane.YES_NO_OPTION);
        if (chosenOption == JOptionPane.YES_OPTION) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            int returnVal = fileChooser.showOpenDialog(getMainFrame());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File saveDir = fileChooser.getSelectedFile();

                try {
                    File newInkFile = StartupUtils.saveRemoteDataset(_context, saveDir);
                    datasetPath = newInkFile.getAbsolutePath();
                    remoteDatasetSavedLocally = true;

                    // Remove the current startup file from the MRU as a new
                    // file will go in its
                    // place.
                    UIUtils.removeFileFromMRU(_context.getDatasetStartupFile().getAbsolutePath());
                } catch (IOException ex) {
                    Logger.error("Error saving downloaded dataset", ex);
                    displayErrorMessage(
                            UIUtils.getResourceString("ErrorSavingDownloadedDataset.error", ex.getMessage()));
                    // not much we can do here, just abort saving/adding to
                    // recents list.
                    return;
                }
            }
        }
    }

    // Add to list of most recently used datasets.
    if (_context.getDataset() != null) {
        UIUtils.addFileToMRU(datasetPath, datasetTitle, UIUtils.getPreviouslyUsedFiles());
    }

    // If the dataset is not present in the dataset index, give the user the
    // option to add it
    String promptMessage = null;
    if (startupFileData != null && startupFileData.isRemoteDataset()) {
        if (remoteDatasetSavedLocally) {
            promptMessage = UIUtils.getResourceString("AddSavedCopyOfDatasetToIndexPrompt.caption",
                    datasetTitle);
        } else {
            promptMessage = UIUtils.getResourceString("AddStartupFileForRemoteDatasetToIndexPrompt.caption",
                    datasetTitle);
        }
    } else {
        promptMessage = UIUtils.getResourceString("AddDatasetToIndexPrompt.caption", datasetTitle);
    }

    // check if the datasetPath is already present in the index
    if (!UIUtils.getDatasetIndexAsMap().containsKey(datasetPath)) {
        int chosenOption = JOptionPane.showConfirmDialog(getMainFrame(), promptMessage,
                UIUtils.getResourceString("AddToDataset.caption"), JOptionPane.YES_NO_OPTION);
        if (chosenOption == JOptionPane.YES_OPTION) {
            addToDatasetIndex(datasetTitle, datasetPath);
        }
    }
}

From source file:v800_trainer.JCicloTronic.java

private void jMenuOpenallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenallActionPerformed
    // Add your handling code here:

    int i;// ww w.  java 2 s.  c o  m
    StringBuffer Buffer = new StringBuffer();
    String[] liste = new String[1];
    byte Data[] = new byte[81930];
    File path = new File(Properties.getProperty("data.dir"));
    File Datei;

    FileFilter directoryFilter = new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }

        public String getDescription() {
            return "";
        };
    };

    chooser.setCurrentDirectory(
            new java.io.File(Properties.getProperty("import.dir", Properties.getProperty("data.dir"))));
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    ExampleFileFilter filtera = new ExampleFileFilter();
    ExampleFileFilter filterb = new ExampleFileFilter();
    ExampleFileFilter filterc = new ExampleFileFilter();
    ExampleFileFilter filterd = new ExampleFileFilter();
    ExampleFileFilter filtere = new ExampleFileFilter();

    filtera.addExtension("dat");
    filtera.setDescription("HAC Rohdaten");
    filterb.addExtension("tur");
    filterb.setDescription("Hactronic Dateien");
    filterc.addExtension("hrm");
    filterc.setDescription("Polar Daten");
    filterd.addExtension("");
    filterd.setDescription("Polar V800 Verzeichnis");
    filtere.addExtension("csv");
    filtere.setDescription("Polar V800 CSV Flow export");

    chooser.resetChoosableFileFilters();
    chooser.addChoosableFileFilter(filtera);
    chooser.addChoosableFileFilter(filterb);
    chooser.addChoosableFileFilter(filterc);
    chooser.addChoosableFileFilter(filterd);
    chooser.addChoosableFileFilter(filtere);
    chooser.setFileFilter(filtere);

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int returnVal = chooser.showDialog(this, null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        if (chooser.getSelectedFile().getName().endsWith(".dat")) {
            path = new File(chooser.getCurrentDirectory().getPath());
        } else {
            path = new File(chooser.getSelectedFile().getPath());
        }

        if (chooser.getFileFilter().equals(filtera)) {
            liste = path.list(new DirFilter(".dat"));
        }
        if (chooser.getFileFilter().equals(filterb)) {
            liste = path.list(new DirFilter(".tur"));
        }
        if (chooser.getFileFilter().equals(filterc)) {
            liste = path.list(new DirFilter(".hrm"));
        }
        if (chooser.getFileFilter().equals(filtere)) {
            liste = path.list(new DirFilter(".csv"));
        }

        if (chooser.getFileFilter().equals(filterd)) {

            File[] files = path.listFiles();
            ArrayList<String> pathliste = new ArrayList();
            for (File file : files) {
                try {
                    if (file.isDirectory()) {
                        pathliste.add(file.getCanonicalPath());
                    }
                } catch (Exception e) {
                }
            }

            Thread thread = new Thread(new Runnable() {

                public void run() {
                    setCursor(new Cursor(Cursor.WAIT_CURSOR));
                    pm = new ProgressMonitor(JCicloTronic.this, "Importiere...", "", 0, 100);
                    pm.setMillisToPopup(1);

                    v800export V800_export = new v800export();
                    V800_export.export_sessions(JCicloTronic.this, pathliste);
                    pm.close();
                    ChangeModel();
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

                    try {

                        Thread.sleep(100);
                    } catch (Exception e) {
                        if (Thread.interrupted()) {
                            return;
                        }
                    }
                }

            });

            thread.start();

            return;

        }

        //alle auer V800 Dateien importieren
        if (liste == null) {
            JOptionPane.showMessageDialog(null, "Keine Rohdaten-Files gefunden!", "Achtung!",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        final String[] liste_final = liste.clone();
        final File path_final = path;

        Thread thread = new Thread(new Runnable() {

            public void run() {
                File Datei;
                byte Data[] = new byte[81930];

                setCursor(new Cursor(Cursor.WAIT_CURSOR));
                pm = new ProgressMonitor(JCicloTronic.this, "Importiere...", "", 0, 100);
                pm.setMillisToPopup(1);

                for (int i = 0; i < liste_final.length; i++) {
                    pm.setProgress((int) 100.0 * i / liste_final.length);
                    pm.setNote(liste_final[i]);

                    try {
                        Eingabedatei = new java.io.FileInputStream(path_final.getPath()
                                + SystemProperties.getProperty("file.separator") + liste_final[i]);

                        try {
                            Datei = new File(path_final.getPath()
                                    + SystemProperties.getProperty("file.separator") + liste_final[i]);
                            Data = new byte[(int) Datei.length()];
                            //                        Eingabedatei.read()

                            Eingabedatei.read(Data);
                            Eingabedatei.close();
                            if (chooser.getFileFilter().equals(filtera)) {
                                ExtractTour(Data);
                            }
                            if (chooser.getFileFilter().equals(filterb)) {
                                ExtractHactronicFile(Data);
                            }
                            if (chooser.getFileFilter().equals(filterc)) {
                                ExtractPolarFile(Data);
                            }
                            if (chooser.getFileFilter().equals(filtere)) {
                                ExtractCSV(Data);
                            }

                        } catch (IOException e) {
                            JOptionPane.showMessageDialog(null, "IO-Fehler bei Datenlesen", "Achtung!",
                                    JOptionPane.ERROR_MESSAGE);
                        }

                    } catch (FileNotFoundException e) {
                        JOptionPane.showMessageDialog(null,
                                "IO-Fehler bei " + path_final.getPath()
                                        + SystemProperties.getProperty("file.separator") + liste_final[i],
                                "Achtung!", JOptionPane.ERROR_MESSAGE);

                    }

                }
                pm.close();
                JOptionPane.showMessageDialog(null, "Daten  Ende", "Achtung!", JOptionPane.ERROR_MESSAGE);

                Properties.setProperty("import.dir", chooser.getCurrentDirectory().getPath());

                ChangeModel();
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

                try {

                    Thread.sleep(100);
                } catch (Exception e) {
                    if (Thread.interrupted()) {
                        return;
                    }
                }
            }

        });

        thread.start();

    }
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

private boolean checkTestsession() {
    if (wizardtfBugInvestigation.getText().isEmpty() || wizardtfSessionSetup.getText().isEmpty()
            || wizardtfTestDesignExecution.getText().isEmpty() || wizardtfCharter.getText().isEmpty()
            || wizardtfOpportunity.getText().isEmpty()) {
        JOptionPane.showMessageDialog(wizardPanelTaskBreakd, "Please fill out all text fields!",
                "Missing Value", JOptionPane.ERROR_MESSAGE);
        return false;
    }//w  ww  .  ja  v a  2s . co  m
    percent.clear();
    percent.put(wizardLblBugReporting, wizardtfBugInvestigation.getText().toString());
    percent.put(wizardLblSetup, wizardtfSessionSetup.getText().toString());
    percent.put(wizardLblDesignExecution, wizardtfTestDesignExecution.getText().toString());

    if (textHelper.checkTaskBreakdown(percent)) {
        percent.clear();
        percent.put(wizardLblChartervs, wizardtfCharter.getText().toString());
        percent.put(wizardLblOpportunity, wizardtfOpportunity.getText().toString());
    } else {
        return false;
    }
    if (textHelper.checkTaskBreakdown(percent)) {
        //Prfen des Dateinamens
        submittedFolder = wizardTfPathSubmitted.getText();
        realFilename = "et-" + TesterRealname.substring(0, 3) + "-" + textHelper.Timestamp("yyMMdd") + "-a.ses";
        if (submittedFolder.isEmpty()) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new java.io.File("."));
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showOpenDialog(wizardbtnSave) == JFileChooser.APPROVE_OPTION) {
                wizardTfPathSubmitted.setText(chooser.getCurrentDirectory().toString() + "\\");
                checkTestsession();
            }
        } else {
            return true;
        }

    }
    return false;
}

From source file:com.mirth.connect.client.ui.Frame.java

public void doExportAlerts() {
    JFileChooser exportFileChooser = new JFileChooser();
    exportFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    File currentDir = new File(userPreferences.get("currentDirectory", ""));
    if (currentDir.exists()) {
        exportFileChooser.setCurrentDirectory(currentDir);
    }//from   www.  ja  v a 2 s  . com

    int returnVal = exportFileChooser.showSaveDialog(this);
    File exportFile = null;
    File exportDirectory = null;

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath());
        try {
            exportDirectory = exportFileChooser.getSelectedFile();

            List<AlertModel> alerts;
            try {
                alerts = mirthClient.getAllAlerts();
            } catch (ClientException e) {
                alertThrowable(this, e);
                return;
            }

            for (AlertModel alert : alerts) {
                ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance();
                String channelXML = serializer.serialize(alert);

                exportFile = new File(exportDirectory.getAbsolutePath() + "/" + alert.getName() + ".xml");

                if (exportFile.exists()) {
                    if (!alertOption(this, "The file " + alert.getName()
                            + ".xml already exists.  Would you like to overwrite it?")) {
                        continue;
                    }
                }

                FileUtils.writeStringToFile(exportFile, channelXML, UIConstants.CHARSET);
            }
            alertInformation(this, "All files were written successfully to " + exportDirectory.getPath() + ".");
        } catch (IOException ex) {
            alertError(this, "File could not be written.");
        }
    }
}

From source file:app.RunApp.java

/**
 * Action of Save datasets button on Transformation tab
 * // w w  w.jav  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:gui.images.ImageHubExplorer.java

/**
 * This method sets the workspace to the selected directory.
 *
 * @param evt ActionEvent object.//from w  w  w  .  j a  v  a  2s  .c o  m
 */
private void workspaceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_workspaceMenuItemActionPerformed
    JFileChooser jfc = new JFileChooser(currentDirectory);
    jfc.setDialogTitle("Set Workspace");
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int rVal = jfc.showOpenDialog(ImageHubExplorer.this);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        currentDirectory = jfc.getSelectedFile();
        workspace = jfc.getSelectedFile();
        workspaceLabelValue.setText(workspace.getAbsolutePath());
    }
}

From source file:app.RunApp.java

/**
 * Action of Save datasets button in Preprocess tab
 * //w  ww  .j a  v a  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

/**
 * Save MVML datasets//from w  ww.j  a  va  2  s  .c o 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:net.technicpack.launcher.ui.InstallerFrame.java

protected void selectPortable() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        portableInstallDir.setText(chooser.getSelectedFile().getAbsolutePath());
        portableInstallButton.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
        portableInstallButton.setEnabled(true);
    }//from   w  ww  .  ja  va 2  s .c  o  m
}