Example usage for javax.swing JFileChooser setFileSelectionMode

List of usage examples for javax.swing JFileChooser setFileSelectionMode

Introduction

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

Prototype

@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY",
        "JFileChooser.DIRECTORIES_ONLY",
        "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.")
public void setFileSelectionMode(int mode) 

Source Link

Document

Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories.

Usage

From source file:app.RunApp.java

/**
 * Action of Save datasets button on Transformation tab
 * /*  w ww  .ja v a  2 s . c o  m*/
 * @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/*from   w w  w .  ja v  a2s. 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:app.RunApp.java

/**
 * Action of Save datasets button in Preprocess tab
 * /*from  w w  w  .  j  ava 2 s .c om*/
 * @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:src.gui.ItSIMPLE.java

/**
 * @return Returns the planAnalysisFramePanel.
 *//*from   w  ww. j a  v  a 2  s . co  m*/
private ItFramePanel getPlanAnalysisFramePanel() {
    if (planAnalysisFramePanel == null) {
        planAnalysisFramePanel = new ItFramePanel(":: Plan Analysis", ItFramePanel.NO_MINIMIZE_MAXIMIZE);

        // tool bar
        JToolBar chartsToolBar = new JToolBar();
        chartsToolBar.add(new JButton(drawChartAction));

        // charts panel
        chartsPanel = new JPanel();
        chartsPanel.setLayout(new BoxLayout(chartsPanel, BoxLayout.Y_AXIS));

        ItFramePanel variableSelectionPanel = new ItFramePanel(".: Select variables to be tracked",
                ItFramePanel.NO_MINIMIZE_MAXIMIZE);
        //variableSelectionPanel.setBackground(new Color(151,151,157));

        JSplitPane split = new JSplitPane();
        split.setContinuousLayout(true);
        split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
        split.setDividerLocation(2 * screenSize.height / 3);

        split.setDividerSize(8);
        //split.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50));
        //split.setPreferredSize(new Dimension(screenSize.width/4-20, 120));
        split.setLeftComponent(new JScrollPane(variablesPlanTree));
        split.setRightComponent(new JScrollPane(selectedVariablesPlanTree));

        variableSelectionPanel.setContent(split, false);
        //variableSelectionPanel.setParentSplitPane()

        //JPanel variableSelectionPanel  = new JPanel(new BorderLayout());
        //variableSelectionPanel.add(new JScrollPane(variablesPlanTree), BorderLayout.CENTER);
        //variableSelectionPanel.add(new JScrollPane(selectedVariablesPlanTree), BorderLayout.EAST);

        ItFramePanel variableGraphPanel = new ItFramePanel(".: Chart", ItFramePanel.NO_MINIMIZE_MAXIMIZE);
        variableGraphPanel.setContent(chartsPanel, true);

        JSplitPane mainvariablesplit = new JSplitPane();
        mainvariablesplit.setContinuousLayout(true);
        mainvariablesplit.setOrientation(JSplitPane.VERTICAL_SPLIT);
        mainvariablesplit.setDividerLocation(150);
        mainvariablesplit.setDividerSize(8);
        //mainvariablesplit.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50));
        mainvariablesplit.setTopComponent(variableSelectionPanel);
        mainvariablesplit.setBottomComponent(variableGraphPanel);

        // main charts panel - used to locate the tool bar above the charts panel
        JPanel mainChartsPanel = new JPanel(new BorderLayout());
        mainChartsPanel.add(chartsToolBar, BorderLayout.NORTH);
        //mainChartsPanel.add(new JScrollPane(chartsPanel), BorderLayout.CENTER);
        mainChartsPanel.add(mainvariablesplit, BorderLayout.CENTER);

        //Results
        planInfoEditorPane = new JEditorPane();
        planInfoEditorPane.setContentType("text/html");
        planInfoEditorPane.setEditable(false);
        planInfoEditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR));
        planInfoEditorPane.setBackground(Color.WHITE);

        JPanel resultsPanel = new JPanel(new BorderLayout());

        JToolBar resultsToolBar = new JToolBar();
        resultsToolBar.setRollover(true);

        JButton planReportButton = new JButton("View Full Report",
                new ImageIcon("resources/images/viewreport.png"));
        planReportButton.setToolTipText("<html>View full plan report.<br> For multiple plans you will need "
                + "access to the Internet.<br> The components used in the report require such access (no data is "
                + "sent through the Internet).</html>");
        planReportButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //Opens html with defaut browser
                String path = "resources/report/Report.html";
                File report = new File(path);
                path = report.getAbsolutePath();
                try {
                    BrowserLauncher launcher = new BrowserLauncher();
                    launcher.openURLinBrowser("file://" + path);
                } catch (BrowserLaunchingInitializingException ex) {
                    Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex);
                    appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n");
                } catch (UnsupportedOperatingSystemException ex) {
                    Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex);
                    appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n");
                }
            }
        });
        resultsToolBar.add(planReportButton);

        resultsToolBar.addSeparator();
        JButton planReportDataButton = new JButton("Save Report Data",
                new ImageIcon("resources/images/savePDDL.png"));
        planReportDataButton.setToolTipText("<html>Save report data to file</html>");
        planReportDataButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //Save report data
                if (solveResult != null) {
                    Element lastOpenFolderElement = itSettings.getChild("generalSettings")
                            .getChild("lastOpenFolder");
                    JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText());
                    fc.setDialogTitle("Save Report Data");
                    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    fc.setFileFilter(new XMLFileFilter());

                    int returnVal = fc.showSaveDialog(ItSIMPLE.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File selectedFile = fc.getSelectedFile();
                        String path = selectedFile.getPath();

                        if (!path.toLowerCase().endsWith(".xml")) {
                            path += ".xml";
                        }
                        //save file (xml)
                        try {
                            FileWriter file = new FileWriter(path);
                            file.write(XMLUtilities.toString(solveResult));
                            file.close();
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }

                        //Save as a last open folder
                        String folder = selectedFile.getParent();
                        //Element lastOpenFolderElement = itSettings.getChild("generalSettings").getChild("lastOpenFolder");
                        lastOpenFolderElement.setText(folder);
                        XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument());

                        //Ask if the user wants to save plans individually too.
                        boolean needToSavePlans = false;
                        int option = JOptionPane.showOptionDialog(instance,
                                "<html><center>Do you also want to save the plans"
                                        + "<br>in individual files?</center></html>",
                                "Save plans", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                                null, null);
                        switch (option) {
                        case JOptionPane.YES_OPTION: {
                            needToSavePlans = true;
                        }
                            break;
                        case JOptionPane.NO_OPTION: {
                            needToSavePlans = false;
                        }
                            break;
                        }

                        if (needToSavePlans) {
                            //Close Open tabs
                            List<?> problems = null;
                            try {
                                XPath ppath = new JDOMXPath("project/domains/domain/problems/problem");
                                problems = ppath.selectNodes(solveResult);
                            } catch (JaxenException e2) {
                                e2.printStackTrace();
                            }

                            for (int i = 0; i < problems.size(); i++) {
                                Element problem = (Element) problems.get(i);
                                //create a folder for each problem and put all plans inside as xml files
                                String folderName = problem.getChildText("name");
                                String folderPath = selectedFile.getAbsolutePath()
                                        .replace(selectedFile.getName(), folderName);
                                //System.out.println(folderPath);
                                File planfolder = new File(folderPath);
                                boolean canSavePlan = false;
                                try {
                                    if (planfolder.mkdir()) {
                                        System.out.println("Directory '" + folderPath + "' created.");
                                        canSavePlan = true;
                                    } else {
                                        System.out.println("Directory '" + folderPath + "' was not created.");
                                    }

                                } catch (Exception ep) {
                                    ep.printStackTrace();
                                }

                                if (canSavePlan) {
                                    Element plans = problem.getChild("plans");
                                    for (Iterator<Element> it = plans.getChildren("xmlPlan").iterator(); it
                                            .hasNext();) {
                                        Element eaplan = it.next();
                                        Element theplanner = eaplan.getChild("planner");
                                        //save file (xml)
                                        String planFileName = "solution" + theplanner.getChildText("name") + "-"
                                                + theplanner.getChildText("version") + "-"
                                                + Integer.toString(plans.getChildren().indexOf(eaplan))
                                                + ".xml";
                                        String planPath = folderPath + File.separator + planFileName;
                                        /*
                                        try {
                                            FileWriter planfile = new FileWriter(planPath);
                                            planfile.write(XMLUtilities.toString(eaplan));
                                            planfile.close();
                                            System.out.println("File '" + planPath + "' created.");
                                        } catch (IOException e1) {
                                            e1.printStackTrace();
                                        }
                                        *
                                        */
                                        if (eaplan.getChild("plan").getChildren().size() > 0) {

                                            //TODO: save the plan in PDDL too. It should be done through the XPDDL/PDDL classes
                                            String pddlplan = ToXPDDL.XMLtoXPDDLPlan(eaplan);
                                            String planFileNamePDDL = "solution"
                                                    + theplanner.getChildText("name") + "-"
                                                    + theplanner.getChildText("version") + "-"
                                                    + Integer.toString(plans.getChildren().indexOf(eaplan))
                                                    + ".pddl";
                                            String planPathPDDL = folderPath + File.separator
                                                    + planFileNamePDDL;

                                            //String cfolderPath = selectedFile.getAbsolutePath().replace(selectedFile.getName(), "");
                                            //String planFileNamePDDL = theplanner.getChildText("name")+"-"+theplanner.getChildText("version") + "-" + folderName+"-solution.pddl";
                                            //String planPathPDDL = cfolderPath + File.separator + planFileNamePDDL;
                                            //if (!theplanner.getChildText("name").contains("MIPS")){
                                            try {
                                                FileWriter planfile = new FileWriter(planPathPDDL);
                                                planfile.write(pddlplan);
                                                planfile.close();
                                                System.out.println("File '" + planPathPDDL + "' created.");
                                            } catch (IOException e1) {
                                                e1.printStackTrace();
                                            }
                                        } //}

                                    }

                                }

                            }
                        }

                    }
                } else {
                    appendOutputPanelText(">> No report data available to save! \n");
                }

            }
        });
        resultsToolBar.add(planReportDataButton);

        JButton openPlanReportDataButton = new JButton("Open Report Data",
                new ImageIcon("resources/images/openreport.png"));
        openPlanReportDataButton.setToolTipText("<html>Open report data to file</html>");
        openPlanReportDataButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                planSimStatusBar.setText("Status: Opening File...");
                appendOutputPanelText(">> Opening File... \n");
                //Open report data
                Element lastOpenFolderElement = itSettings.getChild("generalSettings")
                        .getChild("lastOpenFolder");
                JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText());
                fc.setDialogTitle("Open Report Data");
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                fc.setFileFilter(new XMLFileFilter());

                int returnVal = fc.showOpenDialog(ItSIMPLE.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    File file = fc.getSelectedFile();
                    // Get itSIMPLE itSettings from itSettings.xml
                    org.jdom.Document resultsDoc = null;
                    try {
                        resultsDoc = XMLUtilities.readFromFile(file.getPath());
                        solveResult = resultsDoc.getRootElement();
                        //XMLUtilities.printXML(solveResult);
                        if (solveResult.getName().equals("projects")) {

                            String report = PlanAnalyzer.generatePlannersComparisonReport(solveResult);
                            String comparisonReport = PlanAnalyzer
                                    .generateFullPlannersComparisonReport(solveResult);
                            //Save Comparison Report file
                            saveFile("resources/report/Report.html", comparisonReport);
                            setPlanInfoPanelText(report);
                            setPlanEvaluationInfoPanelText("");
                            appendOutputPanelText(">> Report data read! \n");

                            //My experiments
                            PlanAnalyzer.myAnalysis(itPlanners.getChild("planners"), solveResult);
                        }
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }

                    //Save as a last open folder
                    String folder = fc.getSelectedFile().getParent();
                    lastOpenFolderElement.setText(folder);
                    XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument());

                } else {
                    planSimStatusBar.setText("Status:");
                    appendOutputPanelText(">> Canceled \n");
                }

            }
        });
        resultsToolBar.add(openPlanReportDataButton);

        JButton compareProjectReportDataButton = new JButton("Compare Project Data",
                new ImageIcon("resources/images/compare.png"));
        compareProjectReportDataButton.setToolTipText(
                "<html>Compare different project report data <br> This is commonly use to compare diferent domain models with different adjustments.<br>"
                        + "One project data must be chosen as a reference; others will be compared to this referencial one.</html>");
        compareProjectReportDataButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                final ProjectComparisonDialog dialog = new ProjectComparisonDialog();
                dialog.setVisible(true);

                final List<String> files = dialog.getFiles();

                if (files.size() > 1) {

                    new Thread() {
                        public void run() {
                            appendOutputPanelText(">> Project comparison report requested. Processing... \n");

                            planSimStatusBar.setText("Status: Reading files ...");
                            appendOutputPanelText(">> Reading files ... \n");

                            //base project file
                            String baseFileName = files.get(0);
                            appendOutputPanelText(">> Reading file '" + baseFileName + "' \n");
                            org.jdom.Document baseProjectDoc = null;
                            try {
                                baseProjectDoc = XMLUtilities.readFromFile(baseFileName);
                            } catch (Exception ec) {
                                ec.printStackTrace();
                            }
                            Element baseProject = null;
                            if (baseProjectDoc != null) {
                                baseProject = baseProjectDoc.getRootElement().getChild("project");
                            }

                            //The comparible projects
                            List<Element> comparableProjects = new ArrayList<Element>();

                            for (int i = 1; i < files.size(); i++) {
                                String eafile = files.get(i);
                                appendOutputPanelText(">> Reading file '" + eafile + "' \n");
                                org.jdom.Document eaProjectDoc = null;
                                try {
                                    eaProjectDoc = XMLUtilities.readFromFile(eafile);
                                } catch (Exception ec) {
                                    ec.printStackTrace();
                                }
                                if (eaProjectDoc != null) {
                                    comparableProjects.add(eaProjectDoc.getRootElement().getChild("project"));
                                }

                            }
                            appendOutputPanelText(">> Files read. Building report... \n");

                            String comparisonReport = PlanAnalyzer.generateProjectComparisonReport(baseProject,
                                    comparableProjects);
                            saveFile("resources/report/Report.html", comparisonReport);
                            appendOutputPanelText(
                                    ">> Project comparison report generated. Press 'View Full Report'\n");
                            appendOutputPanelText(" \n");

                        }
                    }.start();

                }

            }
        });
        resultsToolBar.add(compareProjectReportDataButton);

        resultsPanel.add(resultsToolBar, BorderLayout.NORTH);
        resultsPanel.add(new JScrollPane(planInfoEditorPane), BorderLayout.CENTER);

        JTabbedPane planAnalysisTabbedPane = new JTabbedPane();
        planAnalysisTabbedPane.addTab("Results", resultsPanel);
        planAnalysisTabbedPane.addTab("Variable Tracking", mainChartsPanel);
        planAnalysisTabbedPane.addTab("Movie Maker", getMovieMakerPanel());
        planAnalysisTabbedPane.addTab("Plan Evaluation", getPlanEvaluationPanel());
        planAnalysisTabbedPane.addTab("Plan Database", getPlanDatabasePanel());
        planAnalysisTabbedPane.addTab("Rationale Database", getRationaleDatabasePanel());

        JPanel planAnalysisPanel = new JPanel(new BorderLayout());
        //planAnalysisPanel.add(chartsToolBar, BorderLayout.NORTH);
        planAnalysisPanel.add(planAnalysisTabbedPane, BorderLayout.CENTER);
        planAnalysisFramePanel.setContent(planAnalysisPanel, false);

    }

    return planAnalysisFramePanel;
}

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);
    }//ww  w  .j ava 2  s  .co m
}

From source file:net.technicpack.launcher.ui.InstallerFrame.java

protected void selectStandard() {
    File installDir = new File(standardInstallDir.getText());

    while (!installDir.exists()) {
        installDir = installDir.getParentFile();
    }/*from   w w w .ja v  a  2 s. c  om*/

    JFileChooser chooser = new JFileChooser(installDir);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().listFiles().length > 0) {
            JOptionPane.showMessageDialog(this, resources.getString("modpackoptions.move.errortext"),
                    resources.getString("modpackoptions.move.errortitle"), JOptionPane.OK_OPTION);
            return;
        }

        standardInstallDir.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}

From source file:net.technicpack.launcher.ui.LauncherFrame.java

protected void launchModpack() {
    ModpackModel pack = modpackSelector.getSelectedPack();
    boolean requiresInstall = false;

    if (pack == null || (pack.getInstalledPack() == null
            && (pack.getPackInfo() == null || !pack.getPackInfo().isComplete())))
        return;/* www .  ja  v a  2  s. c om*/

    if (pack.getInstalledDirectory() == null) {
        requiresInstall = true;
        pack.save();
        modpackSelector.forceRefresh();
    }

    if (requiresInstall) {
        try {
            if (pack.getPackInfo().shouldForceDirectory()
                    && FilenameUtils.directoryContains(directories.getLauncherDirectory().getCanonicalPath(),
                            pack.getInstalledDirectory().getCanonicalPath())) {
                JFileChooser chooser = new JFileChooser(directories.getLauncherDirectory());
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setCurrentDirectory(directories.getLauncherDirectory());
                int result = chooser.showOpenDialog(this);

                if (result == JFileChooser.APPROVE_OPTION) {
                    File file = chooser.getSelectedFile();

                    if (file.list().length > 0) {
                        JOptionPane.showMessageDialog(this,
                                resources.getString("modpackoptions.move.errortext"),
                                resources.getString("modpackoptions.move.errortitle"),
                                JOptionPane.WARNING_MESSAGE);
                        return;
                    } else if (FileUtils.directoryContains(directories.getLauncherDirectory(), file)) {
                        JOptionPane.showMessageDialog(this, resources.getString("launcher.launch.requiresmove"),
                                resources.getString("launcher.launch.requiretitle"),
                                JOptionPane.WARNING_MESSAGE);
                        return;
                    }

                    pack.setInstalledDirectory(file);
                }
            }
        } catch (IOException ex) {
            Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        }
    }

    boolean forceInstall = false;
    Version installedVersion = pack.getInstalledVersion();

    //Force a full install (check cache, redownload, unzip files) if we have no current installation of this modpack
    if (installedVersion == null)
        forceInstall = true;
    else if (pack.getBuild() != null && !pack.isLocalOnly()) {

        //Ask the user if they want to update to the newer version if:
        //1- the pack build is RECOMMENDED & the recommended version is diff from the installed version
        //2- the pack build is LATEST & the latest version is diff from the installed version
        //3- the pack build is neither LATEST or RECOMMENDED & the pack build is diff from the installed version
        boolean requestInstall = false;
        if (pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED)
                && pack.getPackInfo().getRecommended() != null
                && !pack.getPackInfo().getRecommended().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;
        else if (pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST)
                && pack.getPackInfo().getLatest() != null
                && !pack.getPackInfo().getLatest().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;
        else if (!pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED)
                && !pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST)
                && !pack.getBuild().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;

        //If the user says yes, update, then force a full install
        if (requestInstall) {
            int result = JOptionPane.showConfirmDialog(this, resources.getString("launcher.install.query"),
                    resources.getString("launcher.install.query.title"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.INFORMATION_MESSAGE);

            if (result == JOptionPane.YES_OPTION) {
                forceInstall = true;
            }
        }
    }

    //If we're forcing an install, then derive the installation build from the pack build
    //otherwise, just use the installed version
    String installBuild = null;
    if (forceInstall && !pack.isLocalOnly()) {
        installBuild = pack.getBuild();

        if (installBuild.equalsIgnoreCase(InstalledPack.RECOMMENDED))
            installBuild = pack.getPackInfo().getRecommended();
        else if (installBuild.equalsIgnoreCase(InstalledPack.LATEST))
            installBuild = pack.getPackInfo().getLatest();
    } else
        installBuild = installedVersion.getVersion();

    if (requiresInstall) {
        installer.justInstall(resources, pack, installBuild, forceInstall, this, installProgress);
    } else {
        installer.installAndRun(resources, pack, installBuild, forceInstall, this, installProgress);
    }

    installProgress.setVisible(true);
    installProgressPlaceholder.setVisible(false);
    userChanged(userModel.getCurrentUser());
    invalidate();
}

From source file:net.thangbui.downloader.utils.FileUtils.java

public static File showSaveFileDialog(FileFilter FF, int FileSelectionMode) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileSelectionMode(FileSelectionMode);
    fileChooser.addChoosableFileFilter(FF);
    int returnValue = fileChooser.showSaveDialog(fileChooser);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        return fileChooser.getSelectedFile();
    } else {/*ww  w  .j a  va2s. c  o  m*/
        return null;
    }
}

From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java

private void jButtonSelectImagesFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectImagesFolderActionPerformed
    JFileChooser fc = new JFileChooser();

    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER);
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setAcceptAllFileFilterUsed(false);

    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String path = fc.getSelectedFile().getPath();
        RuntimeConfiguration.getInstance().setTestImagesFolderLocation(path);
        testImagesFolderLocation.setText(path);
    } else {//w w w .  j  a  va  2s  . c o  m
        String path = RuntimeConfiguration.getInstance().getTestImagesFolderLocation();
        if (StringUtils.isNotBlank(path)) {
            testImagesFolderLocation.setText(path);
        }
    }
}

From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java

private void jButtonSelectConfigurationFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectConfigurationFolderActionPerformed
    JFileChooser fc = new JFileChooser();

    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER);
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setAcceptAllFileFilterUsed(false);

    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String path = fc.getSelectedFile().getPath();
        RuntimeConfiguration.getInstance().setTestConfigurationsFolderLocation(path);
        configurationsFolderLocation.setText(path);
    } else {/*  w  ww. j av  a 2s  .  c  o m*/
        String path = RuntimeConfiguration.getInstance().getTestConfigurationsFolderLocation();
        if (StringUtils.isNotBlank(path)) {
            configurationsFolderLocation.setText(path);
        }
    }
}