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:org.scify.talkandplay.gui.users.UserFormPanel.java

private void uploadImageLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uploadImageLabelMouseClicked
    userImage = "";
    JFileChooser chooser = new JFileChooser();

    chooser.setDialogTitle(" ");
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(/*from w  ww.j  a  v  a  2  s.  co  m*/
            new FileNameExtensionFilter("Image Files", "png", "jpg", "jpeg", "JPG", "JPEG", "gif"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        userImage = chooser.getSelectedFile().getAbsolutePath();
        uploadImageLabel.setIcon(guiHelper.getIcon(userImage));
    }
}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed
    final JFileChooser chooser = new JFileChooser();
    final File baseDir = SignServerAdminGUIApplication.getBaseDir();
    final String basedirPath = baseDir.getAbsolutePath();
    final File sampleDir = new File(basedirPath + File.separator + "doc" + File.separator + "sample-configs");

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(sampleDir.isDirectory() ? sampleDir : baseDir);
    chooser.setFileFilter(new FileNameExtensionFilter("Properties files", "properties"));

    final int res = chooser.showOpenDialog(this);

    if (res == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        filePathTextField.setText(file.getAbsolutePath());
        fileSelected = true;//from w  w  w .  ja va  2 s  .com
    }

    updateControls();
}

From source file:org.signserver.admin.gui.ViewCertificateFrame.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
    if (certificate != null) {
        final JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        final FileFilter pemFilter = new FileNameExtensionFilter("X.509 Certificate (PEM)", "pem");
        final FileFilter pemChainFilter = new FileNameExtensionFilter("X.509 Certificate with chain (PEM)",
                "pem");
        final FileFilter derFilter = new FileNameExtensionFilter("X.509 Certificate (DER)", "cer", "crt",
                "der");
        chooser.addChoosableFileFilter(pemFilter);
        chooser.addChoosableFileFilter(derFilter);
        chooser.addChoosableFileFilter(pemChainFilter);
        chooser.setDialogTitle("Save certificate as file");

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

            try {
                if (chooser.getFileFilter() == derFilter) {
                    // DER file
                    FileUtils.writeByteArrayToFile(file, certificate.getEncoded());
                } else {
                    // PEM file
                    BufferedOutputStream out = null;
                    try {
                        out = new BufferedOutputStream(new FileOutputStream(file));
                        PEMWriter pemWriter = new PEMWriter(new OutputStreamWriter(out));
                        if (chooser.getFileFilter() == pemFilter) {
                            pemWriter.writeObject(certificate);
                        } else {
                            for (X509Certificate cert : certificates) {
                                pemWriter.writeObject(cert);
                            }//from  w w  w  .  j a  va 2s. co m
                        }
                        pemWriter.close();
                    } finally {
                        IOUtils.closeQuietly(out);
                    }
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,
                        "Exporting certificate failed:\n" + ex.getLocalizedMessage(), "Export",
                        JOptionPane.ERROR_MESSAGE);
            } catch (CertificateEncodingException ex) {
                JOptionPane.showMessageDialog(this,
                        "Unable to encode certificate:\n" + ex.getLocalizedMessage(), "Export",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

From source file:org.sleeksnap.ScreenSnapper.java

/**
 * Upload a file to the file service by selecting in another window
 */// w  w  w  . ja  va 2 s .  com
public void selectFile() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    final int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        final int confirm = JOptionPane.showConfirmDialog(null,
                Language.getString("uploadConfirm", file.getName()), Language.getString("uploadConfirmTitle"),
                JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (confirm == JOptionPane.YES_OPTION) {
            JOptionPane.showMessageDialog(null, Language.getString("fileUploading"),
                    Language.getString("fileUploadTitle"), JOptionPane.INFORMATION_MESSAGE);
            upload(new FileUpload(file.getAbsoluteFile()));
        } else {
            JOptionPane.showMessageDialog(null, Language.getString("fileUploadCanceled"),
                    Language.getString("fileUploadTitle"), JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

From source file:org.sleuthkit.autopsy.modules.hashdatabase.HashDbCreateDatabaseDialog.java

private void initFileChooser() {
    fileChooser = new JFileChooser() {
        @Override/*from  w w w .jav  a  2 s .  co  m*/
        public void approveSelection() {
            File selectedFile = getSelectedFile();
            if (!FilenameUtils.getExtension(selectedFile.getName())
                    .equalsIgnoreCase(HashDbManager.getHashDatabaseFileExtension())) {
                if (JOptionPane.showConfirmDialog(this,
                        NbBundle.getMessage(this.getClass(),
                                "HashDbCreateDatabaseDialog.hashDbMustHaveFileExtensionMsg",
                                HashDbManager.getHashDatabaseFileExtension()),
                        NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.fileNameErr"),
                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
                    cancelSelection();
                }
                return;
            }
            if (selectedFile.exists()) {
                if (JOptionPane.showConfirmDialog(this,
                        NbBundle.getMessage(this.getClass(),
                                "HashDbCreateDatabaseDialog.fileNameAlreadyExistsMsg"),
                        NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.fileExistsErr"),
                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
                    cancelSelection();
                }
                return;
            }
            super.approveSelection();
        }
    };
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDragEnabled(false);
    fileChooser.setMultiSelectionEnabled(false);
}

From source file:org.sleuthkit.autopsy.modules.hashdatabase.HashDbImportDatabaseDialog.java

private void initFileChooser() {
    fileChooser.setDragEnabled(false);//from  w  w w.ja v a 2  s .com
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String[] EXTENSION = new String[] { "txt", "kdb", "idx", "hash", "Hash", "hsh" }; //NON-NLS
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
            NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"),
            EXTENSION);
    fileChooser.setFileFilter(filter);
    fileChooser.setMultiSelectionEnabled(false);
}

From source file:org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.java

private String searchForFile() {
    String filePath = null;/*from   w  w w .j  a v  a 2s .c  o  m*/
    JFileChooser fc = new JFileChooser();
    fc.setDragEnabled(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String[] EXTENSION = new String[] { "txt", "idx", "hash", "Hash", "kdb" }; //NON-NLS
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
            NbBundle.getMessage(this.getClass(), "HashDbManager.fileNameExtensionFilter.title"), EXTENSION);
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        try {
            filePath = f.getCanonicalPath();
        } catch (IOException ex) {
            Logger.getLogger(HashDbManager.class.getName()).log(Level.WARNING,
                    "Couldn't get selected file path", ex); //NON-NLS
        }
    }
    return filePath;
}

From source file:org.stanwood.nwn2.gui.MainWindow.java

private void addNewGUIFile() {
    File dir = settings.getGUIXMLBrowseDirLastDir(
            new File(settings.getNWN2Dir(NWN2GuiSettings.DEFAULT_NWN2_DIR), "UI" + File.separator + "default"));
    JFileChooser fc = new JFileChooser(dir);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(new FileFilter() {
        @Override//from  www  . j  a  va 2s. c  om
        public String getDescription() {
            return "NWN2 GUI (*.xml)";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
        }
    });
    fc.showOpenDialog(MainWindow.this);
    File selFile = fc.getSelectedFile();
    if (selFile != null) {
        guiFileListModel.addElement(selFile);
        guiFileList.setSelectedIndex(guiFileListModel.getSize() - 1);
        settings.setGUIXMLBrowseDirLastDir(selFile.getParentFile());
        updateEnabledState();
        saveChanges();
    }
}

From source file:org.surmon.pattern.importer.ImportAction.java

/**
 * Creates and shows import dialog. Also handles user interaction with the
 * dialog.//from w  w w  . jav a2  s  . co  m
 */
public static void createAndShowDialog() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Import data");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(true);

    Collection<? extends PDataImporter> importers = Lookup.getDefault().lookupAll(PDataImporter.class);

    // find all importers and set the filters for open dialog
    for (PDataImporter importer : importers) {
        chooser.addChoosableFileFilter(importer.getExtensionFilter());
    }

    // open and wait for result
    int returnVal = chooser.showOpenDialog(null);

    // process the result from open dialog
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();

        if (file.exists()) {
            final String extension = FilenameUtils.getExtension(file.getName());
            final PDataImporter importer = selectImporter(importers, extension);
            if (importer != null) {
                executeImport(importer, file);
            } else {
                NotifyDescriptor nd = new NotifyDescriptor.Message(
                        "File " + extension + " doesn't contain image data or is not supported.");
                DialogDisplayer.getDefault().notify(nd);
            }
        }
    }
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

public static Path selectFile(String title) {
    // try to open AWT dialog on OSX
    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        try {//from  w  w w  .java2 s  .co  m
            // open file chooser
            return openFileDialog(title, FileDialog.LOAD, null);
        } catch (Exception e) {
            LOGGER.warn("cannot open AWT filechooser" + e.getMessage());
        } catch (Error e) {
            LOGGER.warn("cannot open AWT filechooser" + e.getMessage());
        }
    }

    // open JFileChooser
    return openJFileChooser(JFileChooser.FILES_ONLY, title, true, null, null);
}