Example usage for javax.swing JFileChooser CANCEL_OPTION

List of usage examples for javax.swing JFileChooser CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value if cancel is chosen.

Usage

From source file:cc.creativecomputing.io.CCIOUtil.java

static public String selectOutput(String prompt, final String theFolder) {
    fileChooser.setDialogTitle(prompt);/*  ww w . j  a v  a  2  s.  com*/
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (theFolder != null)
        fileChooser.setCurrentDirectory(new File(theFolder));

    int returned = fileChooser.showSaveDialog(null);
    if (returned == JFileChooser.CANCEL_OPTION) {
        selectedFile = null;
    } else {
        selectedFile = fileChooser.getSelectedFile();
    }
    return (selectedFile == null) ? null : selectedFile.getAbsolutePath();
}

From source file:cc.creativecomputing.io.CCIOUtil.java

static public String selectFolder(final String prompt, String theFolder) {

    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(prompt);// w  ww. j  ava 2 s. c o  m
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (theFolder != null)
        fileChooser.setCurrentDirectory(new File(theFolder));

    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int returned = fileChooser.showSaveDialog(null);

    if (returned == JFileChooser.CANCEL_OPTION) {
        selectedFile = null;
    } else {
        selectedFile = fileChooser.getSelectedFile();
    }
    return (selectedFile == null) ? null : selectedFile.getAbsolutePath();
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

public void actionPerformed(ActionEvent e) {
    final JFileChooser readVoter = new JFileChooser();
    readVoter.setFileFilter(new Filter("voter"));
    readVoter.setDialogTitle("Select Motifs file (in MotifVoter format)");

    final JFileChooser reader = new JFileChooser();
    reader.setDialogTitle("Select Motifs file");

    final JFileChooser readFASTA = new JFileChooser();
    readFASTA.setFileFilter(new Filter("fasta"));
    readFASTA.setDialogTitle("Select Sequence File (in FASTA format)");

    final JFileChooser readTompa = new JFileChooser();
    readTompa.setFileFilter(new Filter("tompa"));
    readTompa.setDialogTitle("Select Motifs File (in Tompa's fromat)");

    final JFileChooser readDirectory = new JFileChooser();
    readDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    readDirectory.setDialogTitle("Select Directory");

    final Dataset dataset = (Dataset) datasetComboBox.getSelectedItem();
    final DatasetType datasetType = (DatasetType) datasetTypeComboBox.getSelectedItem();
    final boolean readReverse = checkReverse.isSelected();
    final OrganismCode org = OrganismCode.getOrganism(organismType.getSelectedIndex());
    final int minPoints = (Integer) this.minPoints.getSelectedItem();
    final double epsilon = Double.parseDouble((String) this.clusteringEpsilon.getSelectedItem());
    final int numOfClusters = (Integer) this.numOfClusters.getSelectedItem();
    final boolean multipleDataSets = this.multipleDataSets.isSelected();
    try {/* w ww .jav  a  2s  .co m*/
        if (((JMenuItem) e.getSource()).getText().equals(convertMotifVoterMenuName)) {
            if (reader.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                String fileName = reader.getSelectedFile().getCanonicalPath();
                if (reader.getSelectedFile().getName().contains(".zip")) // if file is zipped, extract it
                {
                    fileName = UnZip.unZip(reader.getSelectedFile(), ".txt", ".MVW2");
                    (new File(fileName)).deleteOnExit();
                }

                if (fileName != null)
                    FileConverterTools.readMotifVoterWeb(new File(fileName), readReverse, true);
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(runPatchConverMVMenuName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] directories = readDirectory.getSelectedFile().listFiles();
                File out2 = new File(readDirectory.getSelectedFile().getParentFile() + "\\MVW2");
                File out = new File(readDirectory.getSelectedFile().getParentFile() + "\\MVW");
                out.mkdir();
                out2.mkdir();
                for (int i = 0; i < directories.length; i++) {
                    File[] files2 = directories[i].listFiles(new Filter("zip"));
                    File[] files = directories[i].listFiles(new Filter("MVW.voter"));
                    if (files2.length > 0) {
                        String fileName = UnZip.unZip(files2[0], ".txt", ".MVW2");
                        if (fileName != null) {
                            fileName = FileConverterTools.readMotifVoterWeb(new File(fileName), readReverse,
                                    true);
                            FileConverterTools.copy(new File(fileName), out2);
                        }
                    }
                    if (files.length > 0) {
                        FileConverterTools.copy(files[0], out);
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(convertAllMenuName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                controller.convertFilesAndMerge(readDirectory.getSelectedFile(), dataset, readReverse);
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(runPatchConverAllMenuName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] directories = readDirectory.getSelectedFile().listFiles();

                for (int i = 0; i < directories.length; i++) {
                    String datasetName = directories[i].getName();
                    if (datasetName.contains("_"))
                        datasetName = datasetName.substring(0, datasetName.indexOf("_"));
                    datasetName = datasetName.substring(0, datasetName.length() - 1); // remove g,m,r
                    controller.convertFilesAndMerge(directories[i], Dataset.getValue(datasetName), readReverse);
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(copyCleanInputFilesName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] directories = readDirectory.getSelectedFile().listFiles();
                File out = new File(readDirectory.getSelectedFile().getParentFile() + "\\clean");
                out.mkdir();
                for (int i = 0; i < directories.length; i++) {
                    File[] files = directories[i].listFiles(new Filter("clean.voter"));

                    if (files.length > 0) {
                        FileConverterTools.copy(files[0], out);
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(loadMenuName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                loadAnalysis(readDirectory.getSelectedFile());
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(saveMenuName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                saveAnalysis(readDirectory.getSelectedFile());
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(gibbsMenuName)) {
            readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame);
            FileConverterTools.createLengthFile(readDirectory.getSelectedFile(),
                    new File(readDirectory.getSelectedFile() + "//len.txt"));
            /*
            if (readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) 
            {                  
                  Thread t = new Thread(){ public void run() 
                  {
             SimpleGibbsAlignerDemo demo = new SimpleGibbsAlignerDemo();
             int i = Integer.parseInt(numOfTrials.getText());
             int w = Integer.parseInt(motifWidth.getText());
             demo.runDemo(readFASTA.getSelectedFile(), false, w, i);}
                  };
                  t.start();                  
                         
            }
            */
        } else if (((JMenuItem) e.getSource()).getText().equals(compareSetsName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File dir = readDirectory.getSelectedFile();
                if (multipleDataSets)
                    controller.compareSetsAllDir(dir);
                else
                    controller.compareSets(dir);
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(mergeCompareSetsName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File dir = readDirectory.getSelectedFile();
                controller.mergeComputeSets(dir);
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(infoContentMenuName)) {
            if (reader.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                List<String> sequences = null;
                if (inputTextArea.getText() != null) {
                    String temp = inputTextArea.getText();
                    sequences = new ArrayList<String>();
                    while (temp.contains("\n")) {
                        String seq = temp.substring(0, temp.indexOf('\n'));
                        temp = temp.substring(temp.indexOf('\n') + 1, temp.length() - 1);
                        if (seq.contains(">"))
                            continue;
                        sequences.add(seq);
                    }
                    sequences.add(temp);
                }

                Double[] score = MotifTools.getsequenceScore(reader.getSelectedFile(), sequences);
                StringBuffer buff = new StringBuffer();
                for (int i = 0; i < score.length; i++)
                    buff.append(score[i].doubleValue() + "\n");
                getOutputPane().setText(buff.toString());

                LinesSeriesChart linesChart = new LinesSeriesChart();

                String[] labels = new String[1];
                labels[0] = "label";
                String x[] = new String[score.length];
                Double[][] values = new Double[1][score.length];
                for (int i = 0; i < score.length; i++) {
                    values[0][i] = score[i];
                    x[i] = i + 1 + "";
                }

                //linesChart.createChartImage("e://images//chart1.jpg", labels, x, values, false);

                tabs.add("Info Content",
                        new ChartPanel(linesChart.createCategoryChart("", "", "", labels, x, values)));

            }
        } else if (((JMenuItem) e.getSource()).getText().equals(removeRedundantSitesName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    SequenceIterator seqItr;
                    if (returnVal == JFileChooser.APPROVE_OPTION)
                        seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                    else
                        seqItr = TompaDataset.getDatasetSequences(dataset);

                    List<Motif> m = controller
                            .removeRedundantSites(readVoter.getSelectedFile().getCanonicalPath(), dataset);
                    if (m != null) {
                        showMotifs(seqItr, m);
                        for (int i = 0; i < controller.numOfEvaluations; i++)
                            displayCharts(i);
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(extractSitesName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    SequenceIterator seqItr;
                    if (returnVal == JFileChooser.APPROVE_OPTION)
                        seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                    else
                        seqItr = TompaDataset.getDatasetSequences(dataset);

                    List<Motif> m = controller.extractSites(readVoter.getSelectedFile().getCanonicalPath(),
                            dataset);
                    if (m != null) {
                        showMotifs(seqItr, m);
                        for (int i = 0; i < controller.numOfEvaluations; i++)
                            displayCharts(i);
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(drawKDistanceGraphName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    String fileName = controller.drawKDistanceGraph(readVoter.getSelectedFile(), dataset,
                            minPoints);
                    displayCharts(fileName);
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(computeWeightName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    List<Double> list = controller
                            .computeSimilarity(readVoter.getSelectedFile().getCanonicalPath(), dataset);
                    double sim = list.get(0);
                    double w = list.get(1);
                    String out = String.format("Compactness=%.5f, Weight=%.5f", sim, w);
                    System.out.println(out);
                    JOptionPane.showMessageDialog(mainFrame, out, "Info", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifEachName)) {
            if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                controller.evaluateTompaMotifEach(readTompa.getSelectedFile().getCanonicalPath());
                displayCharts();
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifAccName)) {
            if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                controller.evaluateTompaMotifAcc(readTompa.getSelectedFile().getCanonicalPath());
                displayCharts();
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifTotalName)) {

            if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                controller.evaluateTompaMotifTotal(readTompa.getSelectedFile().getCanonicalPath());
                displayCharts();
            }

        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMotifVoterName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    SequenceIterator seqItr;
                    if (returnVal == JFileChooser.APPROVE_OPTION)
                        seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                    else
                        seqItr = TompaDataset.getDatasetSequences(dataset);
                    Vector<Motif> motifs = controller.evaluateMotifVoterEach(readVoter.getSelectedFile(),
                            dataset);
                    showMotifs(seqItr, motifs);
                    displayCharts();
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMotifVoterTotalName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    SequenceIterator seqItr;
                    if (returnVal == JFileChooser.APPROVE_OPTION)
                        seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                    else
                        seqItr = TompaDataset.getDatasetSequences(dataset);
                    Vector<Motif> motifs = controller.evaluateMotifVoterTotal(readVoter.getSelectedFile(),
                            dataset);
                    showMotifs(seqItr, motifs);
                    displayCharts();
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMVDirFirstEleName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter"));
                controller.evaluateMotifVoterDirFirstEle(files, org, datasetType, readReverse);
                displayCharts();
            }

        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMVDirMergedName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter"));
                controller.evaluateMotifVoterDirMerged(files, org, datasetType, readReverse);
                displayCharts();
            }

        } else if (((JMenuItem) e.getSource()).getText().equals(compareMotifVoterFirstName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    File file1 = readVoter.getSelectedFile();
                    if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                        SequenceIterator seqItr;
                        if (returnVal == JFileChooser.APPROVE_OPTION)
                            seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                        else
                            seqItr = TompaDataset.getDatasetSequences(dataset);
                        Vector<Motif> motifs = new Vector<Motif>(2);
                        motifs.add(FileConverterTools.readMotifVoter(file1, readReverse).firstElement());
                        motifs.add(FileConverterTools.readMotifVoter(readVoter.getSelectedFile(), readReverse)
                                .firstElement());
                        EvaluationController.evaluateMotifList(motifs, dataset);
                        motifs.add(TompaDataset.getAnswer(dataset));
                        showMotifs(seqItr, motifs);
                        displayCharts();
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(compareMotifVoterAllName)) {
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    File file1 = readVoter.getSelectedFile();
                    if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                        SequenceIterator seqItr;
                        if (returnVal == JFileChooser.APPROVE_OPTION)
                            seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile());
                        else
                            seqItr = TompaDataset.getDatasetSequences(dataset);
                        Vector<Motif> motifs = new Vector<Motif>(2);
                        Vector<Motif> temp = FileConverterTools.readMotifVoter(file1, readReverse);
                        for (Iterator<Motif> i = temp.iterator(); i.hasNext();)
                            temp.firstElement().merge(i.next());
                        temp.firstElement().setFinder(MotifFinder.MotifVoter);
                        motifs.add(temp.firstElement());
                        temp = FileConverterTools.readMotifVoter(readVoter.getSelectedFile(), readReverse);
                        for (Iterator<Motif> i = temp.iterator(); i.hasNext();)
                            temp.firstElement().merge(i.next());
                        motifs.add(temp.firstElement());
                        EvaluationController.evaluateMotifList(motifs, dataset);
                        motifs.add(TompaDataset.getAnswer(dataset));
                        showMotifs(seqItr, motifs);
                        displayCharts();
                    }
                }
            }
        } else if (((JMenuItem) e.getSource()).getText().equals(evaluateAllResultsName)) {
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter"));
                controller.evaluateMotifVoterDirAllDataset(files, datasetType, readReverse);
                displayCharts();
            }

        } else if (((JMenuItem) e.getSource()).getText().equals(runBioProspectorName))
            runMethod(MotifFinder.BP);
        /*else if (((JMenuItem)e.getSource()).getText().equals(runDBScanName)
              || ((JMenuItem)e.getSource()).getText().equals(runKMeansName)
              || ((JMenuItem)e.getSource()).getText().equals(runOPTICSName)
              || ((JMenuItem)e.getSource()).getText().equals(runCliqueName)
              || ((JMenuItem)e.getSource()).getText().equals(runMotifVoterName))
        {
           int type = -1;
           if (((JMenuItem)e.getSource()).getText().equals(runMotifVoterName))
              type = 0;
           else if (((JMenuItem)e.getSource()).getText().equals(runKMeansName))
              type = 1;
           else if (((JMenuItem)e.getSource()).getText().equals(runDBScanName))
              type = 2;
           else if (((JMenuItem)e.getSource()).getText().equals(runOPTICSName))
              type = 3;
           else if (((JMenuItem)e.getSource()).getText().equals(runCliqueName))
              type = 4;
           */
        else if (Method.valueOf(((JMenuItem) e.getSource()).getText()) != null) {
            final Method methodType = Method.valueOf(((JMenuItem) e.getSource()).getText());
            int returnVal = JFileChooser.CANCEL_OPTION;
            if (!multipleDataSets && datasetComboBox.getSelectedItem().equals(Dataset.unknown))
                returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame);

            if (multipleDataSets || !datasetComboBox.getSelectedItem().equals(Dataset.unknown)
                    || (returnVal == JFileChooser.APPROVE_OPTION)) {
                if (!multipleDataSets && readVoter
                        .showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    final SequenceIterator seqItr = (returnVal == JFileChooser.APPROVE_OPTION)
                            ? TompaDataset.getSequences(readFASTA.getSelectedFile())
                            : TompaDataset.getDatasetSequences(dataset);
                    Thread t = new Thread() {
                        public void run() {
                            try {
                                List<Motif> m = controller.runMotifVoter(
                                        readVoter.getSelectedFile().getCanonicalPath(), dataset,
                                        multipleDataSets, methodType, minPoints, epsilon, numOfClusters);
                                if (m != null) {
                                    showMotifs(seqItr, m);
                                    for (int i = 0; i < controller.numOfEvaluations; i++)
                                        displayCharts(i);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    };
                    t.start();
                } else if (multipleDataSets && readDirectory
                        .showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                    Thread t2 = new Thread() {
                        public void run() {
                            try {
                                controller.runMotifVoter(readDirectory.getSelectedFile().getCanonicalPath(),
                                        dataset, multipleDataSets, methodType, minPoints, epsilon,
                                        numOfClusters);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    };
                    t2.start();
                }

            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(mainFrame, "An Error occured", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:ElectionGUI.java

private void saveElectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveElectionBtnActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setApproveButtonText("Save");
    fileChooser.setCurrentDirectory(folder);
    int result = fileChooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        folder = fileChooser.getCurrentDirectory();
        File selectedFile = fileChooser.getSelectedFile();
        Store2dElection store = new Store2dElection(this, selectedFile);
        store.writeToFile();/*from w  w w  .j  a v a 2  s.c  om*/
        systemTxt.append("-Election saved successfully." + eol);
        saved = true;
    } else if (result == JFileChooser.CANCEL_OPTION) {
        systemTxt.append("-Saving cancelled" + eol);
    }
}

From source file:ElectionGUI.java

private void loadElectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadElectionBtnActionPerformed
    if (!generalPreferencesCheckBox.isSelected()) {
        //Confirmation of discarding an election2D that is not saved
        boolean discard = true;
        if (election2D != null && !saved) {
            int response = JOptionPane.showConfirmDialog(null,
                    "Current " + "election is not saved, are you sure you want to load " + "an election?" + eol
                            + "Press \"No\" to save current " + "election in a file.",
                    "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

            if (response == JOptionPane.NO_OPTION) {
                discard = false;/*from  w  w  w. j  av  a  2s.  c  om*/
            }
        }

        if (discard) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setCurrentDirectory(folder);
            int result = fileChooser.showOpenDialog(this);

            if (result == JFileChooser.APPROVE_OPTION) {
                folder = fileChooser.getCurrentDirectory();
                File selectedFile = fileChooser.getSelectedFile();
                Parse2dElection parser = new Parse2dElection();
                parser.parseFromFile(selectedFile);
                if (parser.getErr() == null) {
                    election2D = parser.getElection();
                    nTxtField.setText(String.valueOf(election2D.getNumberOfVoters()));
                    mTxtField.setText(String.valueOf(election2D.getNumberOfCandidates()));
                    kTxtField.setText(String.valueOf(election2D.getCommitteeSize()));
                    xLimit = parser.getxLimit();
                    xLimitTxtField.setText(String.valueOf(xLimit));
                    yLimit = parser.getyLimit();
                    yLimitTxtField.setText(String.valueOf(yLimit));
                    nClusters = parser.getnClusters();
                    nClusterTxtField.setText(String.valueOf(nClusters));
                    mClusters = parser.getmClusters();
                    mClusterTxtField.setText(String.valueOf(mClusters));

                    systemTxt.append("-Election loaded." + eol);
                    plotResultsBtn.setEnabled(true);
                    saveElectionBtn.setEnabled(true);
                    consistencyBtn.setEnabled(false);
                    saved = true;
                } else {
                    systemTxt.append(parser.getErr() + eol);
                }
            } else if (result == JFileChooser.CANCEL_OPTION) {
                systemTxt.append("-Loading cancelled." + eol);
            }
        }
    } else {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(folder);
        int result = fileChooser.showOpenDialog(this);

        if (result == JFileChooser.APPROVE_OPTION) {
            folder = fileChooser.getCurrentDirectory();
            File selectedFile = fileChooser.getSelectedFile();
            ParseGeneralElection parser = new ParseGeneralElection();
            parser.parseFromFile(selectedFile);

            if (parser.getErr() == null) {
                ArrayList<Voter> voters = parser.getVoters();
                ArrayList<Candidate> candidates = parser.getCandidates();
                n = voters.size();
                m = candidates.size();
                try {
                    int x = Integer.parseInt(kTxtField.getText());
                    if (x < 1 || x > 100 || x > m) {
                        throw (new Exception());
                    }
                    k = x;
                } catch (Exception e) {
                    kTxtField.setBackground(Color.cyan);
                    kTxtField.setText("1");
                    k = 1;
                    systemTxt.append("-Committee size was invalid. It has " + "been set equal to 1." + eol);
                }

                electionGP = new Election(k, voters, candidates, false);
                plotResultsBtn.setEnabled(true);
                consistencyBtn.setEnabled(false);
                systemTxt
                        .append("-Election " + selectedFile.getName() + " has been loaded successfully." + eol);
            } else {
                systemTxt.append(parser.getErr() + eol);
            }
        } else if (result == JFileChooser.CANCEL_OPTION) {
            systemTxt.append("-Loading cancelled." + eol);
        }
    }
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

public void runMethod(MotifFinder method) {
    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new Filter("fasta"));
    fc.setDialogTitle("Select Sequence File (in FASTA format)");
    int returnVal = JFileChooser.CANCEL_OPTION;
    if (datasetComboBox.getSelectedItem().equals(Dataset.unknown))
        returnVal = fc.showOpenDialog(MotifAnalyzer.this.mainFrame);

    if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown)
            || (returnVal == JFileChooser.APPROVE_OPTION)) {
        try {//w w  w .j a v a2  s .  com
            final JFileChooser readDirectory = new JFileChooser();
            readDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) {
                Dataset dataset = (Dataset) datasetComboBox.getSelectedItem();
                int type = datasetTypeComboBox.getSelectedIndex();
                String fileName = (returnVal == JFileChooser.APPROVE_OPTION)
                        ? fc.getSelectedFile().getCanonicalPath()
                        : TompaDataset.getDatasetSequenceFileName(dataset);
                int i = Integer.parseInt(numOfMotifs.getText());
                int w = Integer.parseInt(motifWidth.getText());
                int t = Integer.parseInt(numOfTrials.getText());
                OrganismCode organism = OrganismCode.getOrganism(organismType.getSelectedIndex());
                log.info("Runninf method: " + method.name());
                log.info("FileName: " + fileName);
                log.info("Outputfile: " + readDirectory.getSelectedFile().getCanonicalPath());
                log.info("Dataset: " + dataset.name());
                log.info("DatasetType: " + type);
                controller.runAndEvaluate(method, fileName, i, w, t, organism, dataset,
                        readDirectory.getSelectedFile().getCanonicalPath());
                displayCharts();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(mainFrame, "An Error occured", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:base.BasePlayer.AddGenome.java

static void downloadGenome(String urls) {
    try {/*w  w w .ja  va 2s .  com*/

        URL fastafile = AddGenome.genomeHash.get(urls)[0];
        String targetDir = "";
        //boolean writable = true;

        File test = new File(Main.genomeDir.getCanonicalPath() + "/test");

        //File f = new File(Main.genomeDir.getCanonicalPath());         

        if (test.mkdir()) {
            /*if(fastafile.getFile().contains("GRCh38")) {
                      
                  if((test.getFreeSpace()/1048576) < (60000000000L/1048576)) {
              Main.showError("Sorry, you need more than 60GB of disk space to install GRCh38.\nGRCh38 FASTA file size is ~50GB uncompressed.\nThis drive has " +test.getFreeSpace()/1048576/1000 +"GB.", "Note");
              test.delete();
              return;
                  }                                                    
               }
            else*/ if ((test.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                Main.showError("Sorry, you need more than 5GB of disk space.\nThis drive has "
                        + test.getFreeSpace() / 1048576 / 1000 + "GB.", "Note");
                test.delete();
                return;
            }
            test.delete();

            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
            File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
            URL gfffile = AddGenome.genomeHash.get(urls)[1];
            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                    + FilenameUtils.getName(gfffile.getFile()) + "/";
            File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
            AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
            genomeadd.createGenome = true;
            genomeadd.execute();
        } else {
            try {

                JFileChooser chooser = new JFileChooser();
                chooser.setAcceptAllFileFilterUsed(false);
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setDialogTitle("Select a local directory for genome files...");
                File outfile = null;

                while (true) {
                    int returnVal = chooser.showSaveDialog((Component) AddGenome.panel);

                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        outfile = chooser.getSelectedFile();
                        File genomedir = new File(outfile.getCanonicalPath() + "/genomes");
                        if (new File(outfile.getCanonicalPath() + "/genomes").mkdir()) {
                            if (fastafile.getFile().contains("GRCh38")) {
                                if ((outfile.getFreeSpace() / 1048576) < (200000000000L / 1048576)) {
                                    Main.showError(
                                            "Please, select local drive with more than 60GB of disk space.\nGRCh38 FASTA file is ~50GB uncompressed.\nThis drive has "
                                                    + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                            "Note");
                                    genomedir.delete();
                                    continue;
                                }
                            } else if ((outfile.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                                Main.showError(
                                        "Please, select local drive with more than 5GB of disk space.\nThis drive has "
                                                + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                        "Note");
                                genomedir.delete();
                                continue;
                            }
                        } else {
                            Main.showError(
                                    "No writing permissions for this directory. \nPlease, select new directory for genomes.",
                                    "Error");
                            continue;
                        }

                        /*if (!new File(outfile.getCanonicalPath() +"/genomes").mkdir()) {
                           Main.showError("Could not create genome directory in " +outfile.getCanonicalPath(), "Error");
                           continue;
                        }*/

                        break;
                    }
                    if (returnVal == JFileChooser.CANCEL_OPTION) {
                        outfile = null;
                        downloading = false;
                        break;
                    }
                }
                if (outfile != null) {
                    Main.genomeDir = new File(outfile.getCanonicalPath() + "/genomes");
                    genomedirectory.setText(Main.genomeDir.getCanonicalPath());
                    Main.writeToConfig("genomeDir=" + Main.genomeDir.getCanonicalPath());
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
                    File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
                    URL gfffile = AddGenome.genomeHash.get(urls)[1];
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                            + FilenameUtils.getName(gfffile.getFile()) + "/";
                    File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
                    AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                    genomeadd.createGenome = true;
                    genomeadd.execute();
                }
                downloading = false;
                /* new File(outfile.getCanonicalPath() +"/genomes").mkdir();
                File fasta = new File(targetDir +FilenameUtils.getName(fastafile.getFile()));                     
                        
                URL gfffile= AddGenome.genomeHash.get(urls)[1];
                targetDir = AddGenome.userDir +"/genomes/" +urls +"/annotation/" +FilenameUtils.getName(gfffile.getFile()) +"/";
                File gff = new File(targetDir +FilenameUtils.getName(gfffile.getFile()));
                        
                AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                genomeadd.createGenome = true;
                genomeadd.execute();
                */
            } catch (Exception ex) {
                downloading = false;
                ex.printStackTrace();
            }

        }

    } catch (Exception e) {
        downloading = false;
        e.printStackTrace();
    }

}

From source file:Form.Principal.java

private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
    // TODO add your handling code here:
    if (editando == false) {
        File Ruta = new File("Imagenes/Fotos Perfil/");
        JFileChooser Examinar = new JFileChooser();
        FileNameExtensionFilter Filtro = new FileNameExtensionFilter("Image", "png", "jpg");
        Examinar.addChoosableFileFilter(Filtro);
        Examinar.setAcceptAllFileFilterUsed(false);
        Examinar.setFileFilter(Filtro);//from www.j ava2 s  . c  o m
        int Estatus = Examinar.showOpenDialog(this);
        if (Estatus == JFileChooser.APPROVE_OPTION) {
            File Origen = Examinar.getSelectedFile();
            String Extension = FilenameUtils.getExtension(Origen.getPath());
            File Copia = new File(Variables.getIdUsuario() + "." + Extension);
            try {
                FileUtils.copyFile(Origen, Copia);
                FileUtils.copyFileToDirectory(Copia, Ruta);
                if (Extension.equals("png")) {
                    File jpg = new File("Imagenes/Fotos Perfil/" + Variables.idUsuario + ".jpg");
                    if (jpg.exists()) {
                        jpg.delete();
                    }
                }
                if (Extension.equals("jpg")) {
                    File png = new File("Imagenes/Fotos Perfil/" + Variables.idUsuario + ".png");
                    if (png.exists()) {
                        png.delete();
                    }
                }
                Copia.delete();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (Estatus == JFileChooser.CANCEL_OPTION) {
            System.out.println("Cancelar");
        }
        PerfilUsuario(Variables.idUsuario);
    }
}

From source file:edu.harvard.i2b2.patientMapping.ui.PatientMappingJPanel.java

private String getKey() {
    String path = null;//from  w ww . j  a v  a  2  s  .  c o m
    key = UserInfoBean.getInstance().getKey();
    if (key == null) {
        if ((path = getNoteKeyDrive()) == null) {
            Object[] possibleValues = { "Type in the key", "Browse to find the file containing the key" };
            String selectedValue = (String) JOptionPane.showInputDialog(this,

                    "The data you have selected to view contains protected \n"
                            + "health information and has been encrypted.\n"
                            + "In order to view this information you must enter \n"
                            + "the decryption key for this project. \n"
                            + "The key can be entered by either manually entering \n"
                            + "the key or selecting the file that contains the key.",
                    "Decryption Key", JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]);
            if (selectedValue == null) {
                return "canceled";
            }
            if (selectedValue.equalsIgnoreCase("Type in the key")) {
                key = JOptionPane.showInputDialog(this, "Please input the decryption key");
                if (key == null) {
                    return "canceled";
                }
            } else {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showOpenDialog(this);
                if (returnVal == JFileChooser.CANCEL_OPTION) {
                    return "canceled";
                }

                File f = null;
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    f = chooser.getSelectedFile();
                    System.out.println("Open this file: " + f.getAbsolutePath());

                    BufferedReader in = null;
                    try {
                        in = new BufferedReader(new FileReader(f.getAbsolutePath()));
                        String line = null;
                        while ((line = in.readLine()) != null) {
                            if (line.length() > 0) {
                                key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        } else {
            System.out.println("Found key file: " + path);
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(path));
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.length() > 0) {
                        key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    if (key == null) {
        return null;
    } else {
        UserInfoBean.getInstance().setKey(key);
    }
    return key;
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * /*from   w ww .j a  va  2  s .  com*/
 */
protected void importPrefs() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String title = getResourceString("Specify.SELECT_FILE_OR_DIR");//$NON-NLS-1$
    if (chooser.showDialog(null, title) != JFileChooser.CANCEL_OPTION) {
        File destFile = chooser.getSelectedFile();

        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(destFile));
            AppPreferences remotePrefs = AppPreferences.getRemote();

            for (Object key : properties.keySet()) {
                String keyStr = (String) key;
                remotePrefs.getProperties().put(keyStr, properties.get(key));
            }

        } catch (Exception ex) {
            log.error(ex); // XXX Error Dialog
        }

    } else {
        throw new NoSuchElementException("The External File Repository needs a valid directory."); //$NON-NLS-1$
    }
}