Example usage for javax.swing JFileChooser FILES_ONLY

List of usage examples for javax.swing JFileChooser FILES_ONLY

Introduction

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

Prototype

int FILES_ONLY

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

Click Source Link

Document

Instruction to display only files.

Usage

From source file:MyFormApp.java

private void AddbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddbuttonMouseClicked
    // TODO add your handling code here:
    //? ?//  w  w  w .  j  av  a 2s. c  om
    JFileChooser fileChooser = new JFileChooser(); //?
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf"));//?pdf
    fileChooser.setAcceptAllFileFilterUsed(false);
    int returnValue = fileChooser.showOpenDialog(null);
    if (returnValue == JFileChooser.APPROVE_OPTION) {//????
        File selectedFile = fileChooser.getSelectedFile();
        try {
            pdfToimage(selectedFile); //???
        } catch (IOException ex) {
            Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println(selectedFile.getName()); //??
        File source = new File("" + selectedFile);
        File dest = new File(PATH + selectedFile.getName());
        //copy file conventional way using Stream
        long start = System.nanoTime();
        //copy files using apache commons io
        start = System.nanoTime();
        int a = i + 1;
        String imagename = FilenameUtils.removeExtension(selectedFile.getName());
        model.addElement(new Book(selectedFile.getName(), "" + a, imagename, PATH)); //list
        i = i + 1;
        jList2.setModel(model);
        jList2.setCellRenderer(new BookRenderer());
        try {
            copyFileUsingApacheCommonsIO(source, dest); //?
        } catch (IOException ex) {
            Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println("Time taken by Apache Commons IO Copy = " + (System.nanoTime() - start));
    }
}

From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalGUI.java

private void initButtonSaveResults() {
    btnSaveResults = new JButton("Save as ...");
    btnSaveResults.setEnabled(false); // can't save right away, need a first search
    btnSaveResults.addActionListener(new ActionListener() {
        @Override/*from w ww .j  ava 2s  . c om*/
        public void actionPerformed(ActionEvent e) {
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (fileChooser.getSelectedFile() != null) { // reusing the dialog
                fileChooser.setSelectedFile(null);
            }

            int returnVal = fileChooser.showDialog(SimilarityRetrievalGUI.this, "Save results to file ...");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    PrintWriter w = FileUtils.openFileForWriting("Results file",
                            fileChooser.getSelectedFile().getAbsolutePath());
                    TableModel model = resultsTable.getModel();

                    // column headers
                    for (int col = 0; col < model.getColumnCount(); col++) {
                        w.print(model.getColumnName(col) + "\t");
                    }
                    w.println();

                    // write each data row
                    for (int row = 0; row < model.getRowCount(); row++) {
                        for (int col = 0; col < model.getColumnCount(); col++) {
                            w.print(model.getValueAt(row, col) + "\t");
                        }
                        w.println();
                    }
                    w.flush();
                    w.close();
                    JOptionPane.showMessageDialog(SimilarityRetrievalGUI.this,
                            "Successfully wrote to file " + fileChooser.getSelectedFile().getAbsolutePath(),
                            "Results stored", JOptionPane.INFORMATION_MESSAGE);

                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });
}

From source file:networkanalyzer.NetworkAnalyzer.java

private void browseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browseMouseClicked
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("Browse the folder to process");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(true);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        String fileName = chooser.getSelectedFile().toString();
        saveLoc.setText(fileName);// www  . j  a  v  a2s. co  m
    }

}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public SpinCADBank fileOpenBank() {
    loadRecentBankFileList();/*ww w .  j a va2  s .c  o m*/
    SpinCADBank b = null;
    File file = null;

    final String newline = "\n";
    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Bank Files", "spbk");
    fc.setFileFilter(filter);
    fc.setAccessory(recentBankFileList);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int returnVal = fc.showOpenDialog(new JFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fc.getSelectedFile();
        // This is where a real application would open the file.
        System.out.println("Opening: " + file.getName() + "." + newline);
        try {
            // first, open bank, then open patch 0
            b = fileReadBank(file);
        } catch (Exception e) { // thrown over in SpinCADFile.java
            e.printStackTrace();
            //            MessageBox("File open failed!", "This spbk file may be from\nan incompatible version of \nSpinCAD Designer.");
        }
    } else {
        System.out.println("Open command cancelled by user." + newline);
    }
    String filePath = file.getPath();
    String fileName = file.getName();
    saveMRUBankFolder(filePath);
    recentBankFileList.add(file);
    // XXX debug looks like we kinda have the same info in 2 places
    b.bankFileName = fileName;
    b.cb.setFileName(fileName);
    b.changed = false;
    saveRecentBankFileList();
    return b;
}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

private JButton createSaveButton() {
    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PersistentLayout pl = (PersistentLayout) vv.getGraphLayout();
            try {
                JFileChooser chooser = new JFileChooser(currentDir);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileFilter(new LayoutFileFilter());
                int result = chooser.showSaveDialog(GraphViewerPanel.this);
                if (result == JFileChooser.APPROVE_OPTION) {
                    currentDir = chooser.getCurrentDirectory();
                    String absolutePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!absolutePath.endsWith(".layout")) {
                        absolutePath += ".layout";
                    }/* ww w .  ja v a  2 s. c  om*/
                    pl.persist(absolutePath);
                }
            } catch (IOException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error saving layout: " + e1.getMessage());
            }
        }
    });
    return save;
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showImportDialog() {
    String path = null;//from  ww  w  .  j a  v a  2  s .c o  m
    if (resourcesDir != null) {
        path = resourcesDir.toString();
    }
    JFileChooser fc = new JFileChooser(path);
    fc.setDialogTitle(MessageBundle.get("dialogs.import.title"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(new FileNameExtensionFilter("json i18n file", "json"));
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        importResources(Paths.get(fc.getSelectedFile().getPath()));
    }
}

From source file:com.stacksync.desktop.util.FileUtil.java

public static File showBrowseFileDialog() {
    switch (env.getOperatingSystem()) {
    case Linux:/*from  w  w  w  .  j  ava  2s  . c o m*/
        return showBrowseDialogLinux(BrowseType.FILES_ONLY);

    case Mac:
        return showBrowseDialogMac(BrowseType.FILES_ONLY);

    case Windows:
    default:
        return showBrowseDialogDefault(JFileChooser.FILES_ONLY);
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void loadReference() throws Exception {
    JFileChooser chooser = new JFileChooser("Please choose a reference file or directory.");

    chooser.setCurrentDirectory(frame.defaultDirectory);
    // TODO: detect if all directory formats are not readable and in this case dont allow directory opening
    chooser.setFileSelectionMode(/*from  ww w .j  av  a  2  s  .co m*/
            ReferenceFormats.REFERENCE_FORMATS.directoryFormats.isEmpty() ? JFileChooser.FILES_ONLY
                    : JFileChooser.FILES_AND_DIRECTORIES);
    for (ReferenceFormat format : ReferenceFormats.REFERENCE_FORMATS.readableFormats) {
        chooser.addChoosableFileFilter(
                new FilesystemFilter(format.getFileExtension(), format.getDescription()));
    }
    chooser.setAcceptAllFileFilterUsed(true);

    int returnVal = chooser.showOpenDialog(frame);
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }

    ReferenceFormat format = null;
    System.out.print("Loading...");
    frame.setTitle("Loading...");
    File f = chooser.getSelectedFile();
    Collection<ReferenceFormat> formats;

    if (f.isDirectory()) {
        formats = ReferenceFormats.REFERENCE_FORMATS.directoryFormats;
    } else {
        formats = ReferenceFormats.REFERENCE_FORMATS.extensionToFormats
                .get(f.getName().substring(f.getName().lastIndexOf(".") + 1));
    }

    if (formats == null || formats.isEmpty()) {
        throw new Exception("No format available that can read files with the "
                + f.getName().substring(f.getName().lastIndexOf(".") + 1) + " extension.");
    }
    if (formats.size() == 1) {
        format = formats.iterator().next();
    } else {
        format = formatChooser(formats);
    }

    if (format == null) {
        return;
    }
    Reference reference = format.readReference(chooser.getSelectedFile(), true, frame.loadLimit);
    if (!reference.links.isEmpty()) {
        Link firstLink = reference.links.iterator().next();
        frame.dataSourceName1 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.first);
        frame.dataSourceName2 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.second);
    }
    frame.setReference(reference);

    //frame.loadPositiveNegativeNT(chooser.getSelectedFile());
    System.out.println("loading finished, " + reference.links.size() + " links loaded.");

}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

/**
  * Initialize the GUI and show the first transition
  * @param mzXMLFile//from  w  w  w  . j  ava  2s .  c  om
  */

public MRMDialog(File mzXMLFile, float precDiscTol, float daughterTol, float chromTol, Class ECurveStrat,
        boolean traceAllFragments, boolean synclh, float minP, float minA) {
    super();
    this.setTitle(TextProvider.getText("MRMer") + " v. " + TextProvider.getText("MRMER_VERSION") + " (build "
            + (String) ApplicationContext.getProperty("REVISION") + ")");
    //frameInit();
    _precursorDiscoveryMzTolerance = precDiscTol;
    _daughterMzTolerance = daughterTol;
    _precursorChromatogramWindow = chromTol;
    _mzXMLFile = mzXMLFile;
    _ecurveclass = ECurveStrat;
    currentTransitionIndex = 0;
    _traceAllFragments = traceAllFragments;
    _synclh = synclh;
    _minPeakCutoff = minP;
    _minAreaCutoff = minA;
    //graphical stuff
    contentPanel = null;
    helper = new ListenerHelper(this);
    try {
        contentPanel = Localizer.renderSwixml("org/fhcrc/cpl/viewer/gui/MRMDialog.xml", this);
        contentPanel.setBackground(new Color(255, 255, 153));

        menuBarInitializations();
        _mzXMLFileChooser = new JFileChooser();
        _mzXMLFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        _mzXMLFileChooser.setMultiSelectionEnabled(false);
        _mzXMLFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                if (f.isDirectory())
                    return true;
                String fname = f.getName();
                String parts[] = fname.split("\\.");
                if (parts.length != 2)
                    return false;
                return parts[1].equalsIgnoreCase("mzXML");
            }

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

        _outputFileChooser = new JFileChooser();
        _outputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        _outputFileChooser.setMultiSelectionEnabled(false);
        _outputFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.toString().endsWith(".tsv") || f.isDirectory();
            }

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

        _imageOutputFileChooser = new JFileChooser();
        _imageOutputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        _imageOutputFileChooser.setMultiSelectionEnabled(false);
        _imageOutputFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.toString().endsWith(".png") || f.isDirectory();
            }

            public String getDescription() {
                return "PNG graphics files";
            }
        });

        _inputTSVFileChooser = new JFileChooser();
        _inputTSVFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        _inputTSVFileChooser.setMultiSelectionEnabled(false);
        _inputTSVFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.toString().endsWith(".tsv") || f.isDirectory();
            }

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

        this.add(contentPanel);
        setResizable(true);
    } catch (Exception x) {
        System.err.println("Failed in MRMDialog initializer: " + x);
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_CREATING_DIALOG"), x);
        throw new RuntimeException(x);
    }

    initStuff();
    listenerHelperInitializations();

}

From source file:com.stacksync.desktop.util.FileUtil.java

private static File showBrowseDialogLinux(BrowseType type) {
    LinuxNativeClient nativeClient = LinuxNativeClient.getInstance();

    try {// w  w w.  j  a  v  a  2 s  .c om
        nativeClient.init("Everything is up to date.");
        Object responseObj = nativeClient.send(new BrowseFileRequest(type));

        // If responseObj returns null means that there is a problem
        // trying to connect with native linux socket.
        if (responseObj == null) {
            //return null;
            // Throw the exception to show the java native browser.
            throw new Exception();
        }

        return (File) responseObj;
    } catch (Exception e) {
        if (type == BrowseType.FILES_ONLY) {
            return showBrowseDialogDefault(JFileChooser.FILES_ONLY);
        } else if (type == BrowseType.DIRECTORIES_ONLY) {
            return showBrowseDialogDefault(JFileChooser.DIRECTORIES_ONLY);
        }

        throw new RuntimeException("Unknown browse type!");
    }
}