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:ca.canucksoftware.ipkpackager.IpkPackagerView.java

private File loadFileChooser(boolean dir, FileFilter filter, String text) {
    File result = null;/* w  w  w  .  ja  v a 2  s  . c o  m*/
    JFileChooser fc = new JFileChooser(); //Create a file chooser
    disableNewFolderButton(fc);
    if (text != null) {
        fc.setSelectedFile(new File(text));
    }
    if (dir) {
        fc.setDialogTitle("");
        File lastDir = new File(
                Preferences.userRoot().get("lastDir", fc.getCurrentDirectory().getAbsolutePath()));
        fc.setCurrentDirectory(lastDir);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
            jTextField1.setText(result.getAbsolutePath());
            Preferences.userRoot().put("lastDir", result.getParentFile().getAbsolutePath());
        }
    } else {
        File lastSaved = null;
        File lastSelected = null;
        if (filter != null) {
            fc.setDialogTitle("Save As...");
            lastSaved = new File(
                    Preferences.userRoot().get("lastSaved", fc.getCurrentDirectory().getAbsolutePath()));
            fc.setCurrentDirectory(lastSaved);
            fc.setFileFilter(filter);
        } else {
            fc.setDialogTitle("");
            lastSelected = new File(
                    Preferences.userRoot().get("lastSelected", fc.getCurrentDirectory().getAbsolutePath()));
            fc.setCurrentDirectory(lastSelected);
            fc.setAcceptAllFileFilterUsed(true);
        }
        if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
            if (lastSaved != null) {
                Preferences.userRoot().put("lastSaved", result.getParentFile().getAbsolutePath());
            }
            if (lastSelected != null) {
                Preferences.userRoot().put("lastSelected", result.getParentFile().getAbsolutePath());
            }
        }
    }
    return result;
}

From source file:marytts.tools.redstart.AdminWindow.java

private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_OpenActionPerformed

    // Allow user to choose a different voice (prompt set) without exiting the tool

    // Create a file chooser
    final JFileChooser openDialog = new JFileChooser();

    // Set the current directory to the voice currently in use
    openDialog.setCurrentDirectory(getVoiceFolderPath());
    openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = openDialog.showDialog(AdminWindow.this, "Open Voice");

    if (result == JFileChooser.APPROVE_OPTION) {
        File voice = openDialog.getSelectedFile();
        setVoiceFolderPath(voice); // Set to the selected the voice folder path
        Test.output("Open voice: " + voice);
        setupVoice();/*from   www  .  j a v a2  s  .co  m*/
    } else {
        Test.output("Open command cancelled.");
    }

}

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 {/*from w  w w  .  java  2  s.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:br.com.jinsync.view.FrmJInSync.java

public void openDirFile() {

    JFileChooser dir = new JFileChooser();
    // String path = "C:\\";
    String path = System.getProperty("user.dir").substring(0, 3);

    if (!txtFile.getText().equals("") && (!txtFile.getText().contains("("))) {
        path = txtFile.getText();/*  w  w w  .j  a  v a 2  s  .c  om*/
    }

    dir.setFileSelectionMode(JFileChooser.FILES_ONLY);
    dir.setCurrentDirectory(new File(path));

    int res = dir.showOpenDialog(null);

    if (res == JFileChooser.APPROVE_OPTION) {
        txtFile.setText(dir.getSelectedFile().toString());
        String nameFile = dir.getSelectedFile().toString();

        ParameterFile parFile = new ParameterFile();
        parFile.setFile(nameFile);

        tableFile = new JTable();
        scrFile.setViewportView(tableFile);

    }

}

From source file:br.com.jinsync.view.FrmJInSync.java

public void openDirectory() {

    JFileChooser dir = new JFileChooser();
    // String path = "C:\\";
    String path = System.getProperty("user.dir").substring(0, 3);

    if (!txtPath.getText().equals("") && (!txtPath.getText().contains("("))) {
        path = txtPath.getText();// w  ww .  j a v  a2 s .c  o m
    }

    dir.setFileSelectionMode(JFileChooser.FILES_ONLY);
    dir.setCurrentDirectory(new File(path));

    int res = dir.showOpenDialog(null);

    if (res == JFileChooser.APPROVE_OPTION) {
        txtPath.setText(dir.getSelectedFile().toString());
        String nomeDir = dir.getSelectedFile().toString();

        ParameterDir parDir = new ParameterDir();
        parDir.setDir(nomeDir);

        arquivo = dir.getSelectedFile();
        nameCopy = arquivo.getName();
        tableCopy = new JTable();
        scrCopy.setViewportView(tableCopy);

        tableFile = new JTable();
        scrFile.setViewportView(tableFile);

    }

}

From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java

private void initFilemenu() {
    final EditorMainWindow parentWinRef = this;

    exitMenuItem.addActionListener(new ActionListener() {
        @Override//from  w w w.  j ava2s. c  o m
        public void actionPerformed(ActionEvent e) {
            parentWinRef.dispose();
        }
    });

    openOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);

            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);

            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());

            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();

                openFile(f, SCAPDocumentClassEnum.OVAL);
            }
        }
    });

    saveMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;

                Document dom = null;
                String filename = null;

                if (selectedWin instanceof OvalEditorForm) {
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                }

                if (dom != null) {
                    // since this is a save operation, not save as, we won't
                    // prompt the user for where to store the file

                    try {
                        scapDoc.save();
                        ((EditorForm) selectedWin).setDirty(false);
                    } catch (Exception e) {
                        String message = "An error occured trying to save to file " + filename + ": "
                                + e.getMessage();
                        EditorUtil.showMessageDialog(parentWinRef, message,
                                EditorMessages.SAVE_ERROR_DIALOG_TITLE, JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        }
    });

    saveAsMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;
                Document dom = null;
                String filename = null;
                String windowTitle = null;

                if (selectedWin instanceof OvalEditorForm) {
                    windowTitle = OvalEditorForm.WINDOW_TITLE_BASE;
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    windowTitle = CPEDictionaryEditorForm.WINDOW_TITLE_BASE;
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else {
                    return;
                }

                if (dom != null) {
                    String newFilename = null;
                    SCAPDocumentTypeEnum docType = scapDoc.getDocumentType();

                    FileSaveAsWizard saveAsWiz = new FileSaveAsWizard(EditorMainWindow.getInstance(), true,
                            docType);

                    //saveAsWiz.pack();
                    saveAsWiz.setLocationRelativeTo(EditorMainWindow.getInstance());
                    saveAsWiz.setVisible(true);

                    if (saveAsWiz.wasCancelled()) {
                        return;
                    }

                    newFilename = saveAsWiz.getFilename();

                    try {
                        scapDoc.setFilename(newFilename);
                        scapDoc.saveAs(newFilename);

                        EditorUtil.markActiveWindowDirty(EditorMainWindow.getInstance(), false);
                        ((EditorForm) selectedWin).refreshRootNode();

                    } catch (Exception e) {
                        LOG.error(e.getMessage(), e);

                        EditorUtil.showMessageDialog(parentWinRef, "An error occured trying to save to file "
                                + newFilename + ": " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    SCAPContentManager scm = SCAPContentManager.getInstance();

                    if (scm != null) {
                        scm.removeDocument(filename);
                        scm.addDocument(newFilename, scapDoc);
                        selectedWin.setTitle(windowTitle + (new File(newFilename)).getAbsolutePath());
                    } else {
                        LOG.error("SCM instance is null here!");
                    }
                }
            }
        }
    });

    newXCCDFFromOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            //generateXccdfFromOvalOrOcil("OVAL");
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);
            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());
            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();
                try {
                    InputStream is = this.getClass().getClassLoader().getResourceAsStream("oval-to-xccdf.xsl");
                    File xsltfile = new File("oval-to-xccdf.xsl");
                    OutputStream outputStream = new FileOutputStream(xsltfile);
                    IOUtils.copy(is, outputStream);
                    outputStream.close();
                    OvalToXCCDF1.ovalToXccdf(f, xsltfile);
                    xsltfile.delete();
                    String reverseDNS = JOptionPane.showInputDialog("reverse_DNS:");
                    if (reverseDNS == null || reverseDNS.length() == 0) {
                        JOptionPane.showMessageDialog(null, "Enter the reverse_DNS", "alert",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        JFileChooser fc1 = new JFileChooser();
                        fc1.setCurrentDirectory(f);
                        int ret1 = fc1.showSaveDialog(EditorMainWindow.getInstance());
                        if (ret1 == JFileChooser.APPROVE_OPTION) {
                            File savefile = fc1.getSelectedFile();
                            is = this.getClass().getClassLoader().getResourceAsStream("xccdf_1.1_to_1.2.xsl");
                            xsltfile = new File("oval-to-xccdf.xsl");
                            outputStream = new FileOutputStream(xsltfile);
                            IOUtils.copy(is, outputStream);
                            outputStream.close();
                            File temp = new File("temp.xml");
                            XCCDF1to2.xccdf12(savefile, reverseDNS, xsltfile, temp);
                            JOptionPane.showMessageDialog(null,
                                    "XCCDF File Created: " + savefile.getAbsolutePath(), "XCCDF Created",
                                    JOptionPane.PLAIN_MESSAGE);
                            xsltfile.delete();
                            temp.delete();
                            temp = null;
                        }

                    }

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (TransformerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //  openFile(f, SCAPDocumentClassEnum.OVAL);
            }

        }

    });

    newOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            CreateOvalWizard wiz = new CreateOvalWizard(true);
            wiz.setName("create_oval_wizard");
            wiz.pack();
            wiz.setVisible(true);

            if (!wiz.wasCancelled()) {
                // User has been through the wizard to select
                // 1. an Oval schema version (eg, OVAL55)
                // 2. one or more platforms (eg, "windows", "solaris", etc)
                // 3. a file name for the new Oval file
                // Now we are ready to actually create the file
                String createdFilename = createNewOvalDocument(wiz);

                if (createdFilename == null) {
                    LOG.error("newOvalMenuItem.actionlistener: Created filename was null!");
                    return;
                }

                File f = new File(createdFilename);

                guiProps.setLastOpenedFromFile(f.getParentFile());
                guiProps.save();

                SCAPContentManager scm = SCAPContentManager.getInstance();

                if (scm != null) {
                    OvalDefinitionsDocument dd = (OvalDefinitionsDocument) scm.getDocument(f.getAbsolutePath());

                    openFile(dd);
                }
            }
            wiz.setVisible(false);
            wiz.dispose();
        }
    });

    /* wizModeMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        WizardModeWindow wizModeWin = new WizardModeWindow();
            
        EditorMainWindow emw = EditorMainWindow.getInstance();
        JDesktopPane emwDesktopPane = emw.getDesktopPane();
            
        wizModeWin.setTitle("Wizard Mode");
        wizModeWin.pack();
            
        wizModeWin.addInternalFrameListener(new WeakInternalFrameListener(EditorMainWindow.getInstance()));
            
        Dimension dpDim = emwDesktopPane.getSize();
        int x = (dpDim.width - wizModeWin.getWidth()) / 2;
        int y = (dpDim.height - wizModeWin.getHeight()) / 2;
            
        wizModeWin.setLocation(x, y);
        emwDesktopPane.add(wizModeWin);
        wizModeWin.setVisible(true);
            
        setWizMode(true);
    }
     });*/

    ugMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                InputStream resource = this.getClass().getResourceAsStream("/User_Guide.pdf");
                try {
                    File userGuideFile = File.createTempFile("UserGuide", ".pdf");
                    userGuideFile.deleteOnExit();
                    OutputStream out = new FileOutputStream(userGuideFile);
                    try {
                        // copy contents from resource to out
                        IOUtils.copy(resource, out);
                    } catch (IOException ex) {
                        JOptionPane.showMessageDialog(null, "Couldn't copy between streams.");
                    } finally {
                        out.close();
                    }
                    desktop.open(userGuideFile);
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(null, "Could not call Open on desktop object.");
                } finally {
                    try {
                        if (resource != null) {
                            resource.close();
                        }
                    } catch (IOException ex) {
                        LOG.error("Error displaying user guide", ex);
                        JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
            }
        }
    });

}

From source file:net.rptools.maptool.launcher.MapToolLauncher.java

private JPanel buildAdvancedPanel() {
    final JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.setBorder(new LineBorder(Color.BLACK));

    final JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new BorderLayout());

    final JPanel argPanel = new JPanel();
    argPanel.setLayout(new BorderLayout());

    jtfArgs.setInfo(CopiedFromOtherJars.getText("msg.info.javaArgumentsHere")); //$NON-NLS-1$
    jtfArgs.setText(extraArgs);/*from  www  . ja  va 2  s  .  co m*/
    jtfArgs.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaArgumentsHere")); //$NON-NLS-1$
    jtfArgs.setCaretPosition(0);
    jtfArgs.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                jbLaunch.requestFocusInWindow();
            }
        }
    });
    jtfArgs.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent arg0) {
            jtfArgs.selectAll();
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            jtfArgs.setCaretPosition(0);
            if (!jtfArgs.getText().trim().equals(extraArgs)) {
                extraArgs = jtfArgs.getText();
                jcbEnableAssertions.setSelected(extraArgs.contains(ASSERTIONS_OPTION));
                if (extraArgs.contains(DATADIR_OPTION)) {
                    extraArgs = cleanExtraArgs(extraArgs);
                }
                updateCommand();
            }
        }
    });

    argPanel.add(jtfArgs, BorderLayout.CENTER);
    controlPanel.add(argPanel, BorderLayout.NORTH);

    final JPanel holdPanel = new JPanel();
    holdPanel.setLayout(new GridLayout(0, 1));

    jcbRelativePath.setText(CopiedFromOtherJars.getText("msg.info.useRelativePathnames")); //$NON-NLS-1$
    jcbRelativePath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.useRelativePathnames")); //$NON-NLS-1$
    jcbRelativePath.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            updateCommand();
        }
    });
    //      jcbRelativePath.setSelected(false); // since initComponents() is called after reading the config, don't do this here

    jcbConsole.setText(CopiedFromOtherJars.getText("msg.info.launchWithConsole")); //$NON-NLS-1$
    jcbConsole.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.launchWithConsole")); //$NON-NLS-1$
    jcbConsole.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            startConsole = jcbConsole.isSelected();
            updateCommand();
        }
    });
    jcbConsole.setSelected(startConsole);

    jbPath.setText(jbPathText);
    jbPath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.dirForAltJava")); //$NON-NLS-1$
    jbPath.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (jbPath.getText().equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.setJavaVersion"))) { //$NON-NLS-1$
                final JFileChooser jfc = new JFileChooser();
                if (!javaDir.isEmpty()) {
                    jfc.setCurrentDirectory(new File(javaDir));
                } else {
                    jfc.setCurrentDirectory(new File(".")); //$NON-NLS-1$
                }
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                final int returnVal = jfc.showOpenDialog(jbPath);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    final File f = jfc.getSelectedFile();
                    final String test = f.getPath() + File.separator;

                    // Lee: naive search for java command. will improve in the future
                    final List<String> fileList = Arrays.asList(f.list());
                    boolean javaFound = false;

                    for (final String fileName : fileList) {
                        final File check = new File(f, fileName);
                        final String lc = check.getName().toLowerCase();
                        if (lc.equals("java") || (IS_WINDOWS && lc.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ 
                            javaFound = true;
                            break;
                        }
                    }
                    if (javaFound) {
                        jbPath.setText(CopiedFromOtherJars.getText("msg.info.resetToDefaultJava")); //$NON-NLS-1$
                        javaDir = test;
                        updateCommand();
                    } else {
                        logMsg(Level.SEVERE, "Java executable not found in {0}", //$NON-NLS-1$
                                "msg.error.javaCommandNotFound", f); //$NON-NLS-2$
                    }
                }
            } else {
                jbPath.setText(CopiedFromOtherJars.getText("msg.info.setJavaVersion")); //$NON-NLS-1$
                javaDir = EMPTY;
            }
        }
    });

    holdPanel.add(jcbRelativePath);
    holdPanel.add(jcbConsole);
    holdPanel.add(jbPath);
    controlPanel.add(holdPanel, BorderLayout.SOUTH);

    final JPanel logPanel = new JPanel();
    logPanel.setLayout(new GridLayout(0, 1));
    logPanel.setBorder(
            new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logPanel.border"))); //$NON-NLS-1$
    for (final LoggingConfig config : logConfigs) {
        config.chkbox.setText(config.getProperty("desc")); //$NON-NLS-1$
        config.chkbox.setToolTipText(config.getProperty("ttip")); //$NON-NLS-1$
        logPanel.add(config.chkbox);
    }
    p.add(logPanel, BorderLayout.CENTER);
    p.add(controlPanel, BorderLayout.SOUTH);
    return p;
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Handles GUI actions.//from   w  w  w.  j  a  va 2 s  .c o  m
 */
public void actionPerformed(ActionEvent actionEvent) {
    if ("Next".equals(actionEvent.getActionCommand())) {
        wizardStepForward();
    } else if ("Back".equals(actionEvent.getActionCommand())) {
        wizardStepBackward();
    } else if ("ChooseFile".equals(actionEvent.getActionCommand())) {
        JFileChooser fileChooser = new JFileChooser();

        if (validFileExtensions.size() > 0) {
            UploaderFileExtensionFilter filter = new UploaderFileExtensionFilter("Allowed files",
                    validFileExtensions);
            fileChooser.setFileFilter(filter);
        }

        fileChooser.setMultiSelectionEnabled(fileMaxCount > 1);
        fileChooser.setDialogTitle("Choose file" + (fileMaxCount > 1 ? "s" : "") + " to upload");
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setApproveButtonText("Choose file" + (fileMaxCount > 1 ? "s" : ""));

        int returnVal = fileChooser.showOpenDialog(ownerFrame);
        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return;
        }

        List fileList = new ArrayList();
        if (fileChooser.getSelectedFiles().length > 0) {
            fileList.addAll(Arrays.asList(fileChooser.getSelectedFiles()));
        } else {
            fileList.add(fileChooser.getSelectedFile());
        }
        if (checkProposedUploadFiles(fileList)) {
            wizardStepForward();
        }
    } else if ("CancelUpload".equals(actionEvent.getActionCommand())) {
        if (uploadCancelEventTrigger != null) {
            uploadCancelEventTrigger.cancelTask(this);
            progressBar.setValue(0);
        } else {
            log.warn("Ignoring attempt to cancel file upload when cancel trigger is not available");
        }
    } else {
        log.warn("Unrecognised action command, ignoring: " + actionEvent.getActionCommand());
    }
}

From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java

public PanelsPanel(JFrame frame, final PanelSave ps) {
    this.ps = ps;
    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du panneau"));

    JPanel content = new JPanel();
    JScrollPane scroll = new JScrollPane(content);
    scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    scroll.setBorder(null);/*from   ww w .j  ava 2  s .co  m*/
    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
    scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20));

    JPanel namePanel = new JPanel();
    name.setPreferredSize(new Dimension(this.getWidth() - 280, 30));
    name.setEditable(false);
    namePanel.add(new JLabel("Nom :"));
    namePanel.add(name);
    namePanel.add(Box.createRigidArea(new Dimension(10, 1)));
    layout.addItem("Basique");
    layout.addItem("Bordures");
    layout.addItem("Ligne");
    layout.addItem("Colonne");
    layout.addItem("Grille");
    layout.addItem("Empil");
    layout.setPreferredSize(new Dimension(110, 30));
    layout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            cl.show(advanced, listContent[combo.getSelectedIndex()]);
            ps.set("layout", combo.getSelectedIndex());
            ActionPanel.updateLists();
        }

    });
    namePanel.add(new JLabel("Disposition :"));
    namePanel.add(layout);
    namePanel.setPreferredSize(new Dimension(365, 50));
    namePanel.setMaximumSize(new Dimension(365, 50));
    content.add(namePanel);

    advanced.setPreferredSize(new Dimension(365, 300));
    advanced.setMaximumSize(new Dimension(365, 300));
    advanced.add(ble, listContent[0]);
    advanced.add(brdle, listContent[1]);
    advanced.add(lle, listContent[2]);
    advanced.add(rle, listContent[3]);
    advanced.add(gle, listContent[4]);
    advanced.add(cle, listContent[5]);

    content.add(advanced);

    topBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.top", combo.getSelectedItem());
        }

    });
    leftBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.left", combo.getSelectedItem());
        }

    });
    centerBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.center", combo.getSelectedItem());
        }

    });
    rightBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.right", combo.getSelectedItem());
        }

    });
    bottomBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.bottom", combo.getSelectedItem());
        }

    });

    JPanel prefSize = new JPanel();
    prefSize.setPreferredSize(new Dimension(365, 110));
    prefSize.setMaximumSize(new Dimension(365, 110));
    prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre"));
    JPanel prefSizePanel = new JPanel();
    prefSizePanel.setLayout(new GridLayout(2, 4));
    prefSizePanel.setPreferredSize(new Dimension(300, 55));
    prefSizePanel.setMaximumSize(new Dimension(300, 55));
    prefSizePanel.add(prefSizeEnabled);
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel("(en pixels)"));
    prefSizePanel.add(new JLabel("Largeur :"));
    prefSizePanel.add(prefWidth);
    prefSizePanel.add(new JLabel("Hauteur :"));
    prefSizePanel.add(prefHeight);
    prefWidth.setEnabled(false);
    prefHeight.setEnabled(false);
    prefSizeEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            ps.set("preferredSize", check.isSelected());
            prefWidth.setEnabled(check.isSelected());
            prefHeight.setEnabled(check.isSelected());
        }
    });
    prefWidth.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredWidth", spinner.getValue());
        }
    });
    prefHeight.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredHeight", spinner.getValue());
        }
    });
    prefSize.add(prefSizePanel);

    content.add(prefSize);

    JPanel insetsPanel = new JPanel();
    insetsPanel.setBorder(BorderFactory.createTitledBorder("carts"));
    insetsPanel.setPreferredSize(new Dimension(365, 100));
    insetsPanel.setMaximumSize(new Dimension(365, 100));

    JPanel insetsContent = new JPanel();
    insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS));

    JPanel insetInput = new JPanel();
    insetInput.setLayout(new GridLayout(2, 4));
    insetInput.add(insetsEnabled);
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel("(en pixels)"));
    insetInput.add(new JLabel("Horizontaux :"));
    insetInput.add(insetHz);
    insetInput.add(new JLabel("Verticaux :"));
    insetInput.add(insetVt);

    insetsEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            if (check.isSelected()) {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", true);
            } else {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", false);
            }
        }

    });

    insetHz.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.horizontal", spinner.getValue());
        }
    });
    insetVt.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.vertical", spinner.getValue());
        }
    });

    insetsContent.add(insetInput);
    insetsPanel.add(insetsContent);

    content.add(insetsPanel);

    JPanel web = new JPanel();
    web.setPreferredSize(new Dimension(365, 100));
    web.setMaximumSize(new Dimension(365, 100));
    web.setBorder(BorderFactory.createTitledBorder("Page Web"));

    JPanel webContent = new JPanel();
    webContent.setLayout(new BorderLayout());
    webContent.add(webEnabled, BorderLayout.NORTH);
    webEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("web", check.isSelected());
            if (check.isSelected() == true) {
                layout.setSelectedIndex(0);
                layout.setEnabled(false);
                ble.removeAllComponents();
                ble.disableComponents();
                adress.setEnabled(true);
            } else {
                ble.enableComponents();
                layout.setEnabled(true);
                adress.setEnabled(false);
            }
        }
    });
    JPanel webInput = new JPanel();
    webInput.add(new JLabel("Adresse :"));
    adress.setPreferredSize(new Dimension(250, 30));
    CaretListener caretUpdate = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            ps.set("web.adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdate);
    webInput.add(adress);
    webContent.add(webInput, BorderLayout.CENTER);

    web.add(webContent);

    JPanel background = new JPanel();
    BorderLayout bLayout = new BorderLayout();
    bLayout.setVgap(12);
    background.setLayout(bLayout);
    background.setBorder(BorderFactory.createTitledBorder("Couleur de fond"));
    background.setPreferredSize(new Dimension(365, 210));
    background.setMaximumSize(new Dimension(365, 210));
    cp.setPreferredSize(new Dimension(347, 145));
    cp.setMaximumSize(new Dimension(347, 145));
    opaque.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("background.opaque", check.isSelected());
            cp.enableComponents(check.isSelected());
        }
    });
    background.add(opaque, BorderLayout.NORTH);
    background.add(cp, BorderLayout.CENTER);

    JPanel image = new JPanel();
    image.setBorder(BorderFactory.createTitledBorder("Image de fond"));
    image.setPreferredSize(new Dimension(365, 125));
    image.setMaximumSize(new Dimension(365, 125));
    image.setLayout(new BorderLayout());
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.setEnabled(false);
    remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            File img = new File(
                    "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png");
            if (img.exists()) {
                img.delete();
            }
            browseImage.setEnabled(true);
        }

    });
    JPanel top = new JPanel();
    browseImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "background.png");
                nameBackground.setText(new File(path).getName());
                ps.set("background.image", new File(path).getName());
                button.setEnabled(false);
                size.setEnabled(true);
                size2.setEnabled(true);
                remove.setEnabled(true);
            }
        }

    });
    bg.add(size);
    bg.add(size2);
    JPanel sizePanel = new JPanel();
    sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS));
    size.setEnabled(false);
    size2.setEnabled(false);
    sizePanel.add(size);
    sizePanel.add(size2);
    size.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 0);
        }

    });
    size2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 1);
        }

    });
    top.add(browseImage);
    top.add(sizePanel);

    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png")
                    .delete();
            nameBackground.setText("");
            ps.set("background.image", "");
            button.setEnabled(false);
        }

    });
    nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15));
    JPanel center = new JPanel(new BorderLayout());
    center.add(nameBackground, BorderLayout.CENTER);
    center.add(remove, BorderLayout.EAST);

    image.add(top, BorderLayout.NORTH);
    image.add(center, BorderLayout.CENTER);

    content.add(web);
    content.add(background);
    content.add(image);

    this.add(scroll);
}

From source file:base.BasePlayer.AddGenome.java

@Override
public void mousePressed(MouseEvent e) {

    if (e.getSource() == tree) {

        if (selectedNode != null && selectedNode.toString().contains("Add new refe")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select reference fasta-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);/* w  ww .  ja va2  s  .  c  o  m*/
                String filename = fs.getFile();
                fs.setFile("*.fasta;*.fa");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".fasta") || name.toLowerCase().contains(".fa");
                    }
                });
                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {

                        genomeFile = addfile;
                        Main.downloadDir = genomeFile.getParent();
                        Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                        OutputRunner runner = new OutputRunner(genomeFile.getName().replace(".fasta", "")
                                .replace(".fa", "").replace(".gz", ""), genomeFile, null);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterFasta fastaFilter = new MyFilterFasta();

                chooser.addChoosableFileFilter(fastaFilter);
                chooser.setDialogTitle("Select reference fasta-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }

                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    genomeFile = chooser.getSelectedFile();
                    Main.downloadDir = genomeFile.getParent();
                    Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                    OutputRunner runner = new OutputRunner(
                            genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, null);
                    runner.createGenome = true;
                    runner.execute();

                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (selectedNode != null && selectedNode.isLeaf()
                && selectedNode.toString().contains("Add new anno")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select annotation gff3/gtf-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);
                String filename = fs.getFile();
                fs.setFile("*.gff3;*.gtf");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".gff3") || name.toLowerCase().contains(".gtf");
                    }
                });

                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {
                        annotationFile = addfile;
                        Main.downloadDir = annotationFile.getParent();
                        Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                        OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                                annotationFile);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterGFF gffFilter = new MyFilterGFF();

                chooser.addChoosableFileFilter(gffFilter);
                chooser.setDialogTitle("Select annotation gff3-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }
                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    annotationFile = chooser.getSelectedFile();
                    Main.downloadDir = annotationFile.getParent();

                    Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                    OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                            annotationFile);
                    runner.createGenome = true;
                    runner.execute();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    if (e.getSource() == genometable) {

        if (new File(".").getFreeSpace()
                / 1048576 < sizeHash.get(genometable.getValueAt(genometable.getSelectedRow(), 0))[0]
                        / 1048576) {
            sizeError.setVisible(true);
            download.setEnabled(false);
            AddGenome.getLinks.setEnabled(false);
        } else {
            sizeError.setVisible(false);
            download.setEnabled(true);
            AddGenome.getLinks.setEnabled(true);
        }
        tree.clearSelection();
        remove.setEnabled(false);
        checkUpdates.setEnabled(false);
    }

}