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.martin.ftp.gui.GUIClient.java

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

    dialogUploadOptions.hide();/*  www.  j  a va2 s .c o  m*/
    FileFilter filter = FilterSelector.getFilter(FilterSelector.TypeFilter.ZIP);
    fileChoos.addChoosableFileFilter(filter);
    fileChoos.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChoos.setFileFilter(filter);
    int selection = fileChoos.showOpenDialog(formManagement);
    File[] selectedFiles = fileChoos.getSelectedFiles();

    if (selectedFiles != null) {
        Thread tUploader = new Thread(() -> {

            for (File file : selectedFiles) {
                if (file.getName().endsWith(".zip")) {
                    try {
                        linker.uploadZipFile(file);
                    } catch (IOException ex) {
                        Logger.getLogger(GUIClient.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        tUploader.start();
        threadsUploaders.add(tUploader);
    }

}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void pickScanReportFile() {
    JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int returnVal = fileChooser.showDialog(frame, "Select scan report file");
    if (returnVal == JFileChooser.APPROVE_OPTION)
        scanReportFileField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void pickTables() {
    DbSettings sourceDbSettings = getSourceDbSettings();
    if (sourceDbSettings != null) {
        if (sourceDbSettings.dataType == DbSettings.CSVFILES) {
            JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
            fileChooser.setMultiSelectionEnabled(true);
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Delimited text files", "csv", "txt");
            fileChooser.setFileFilter(filter);

            int returnVal = fileChooser.showDialog(frame, "Select tables");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                for (File table : fileChooser.getSelectedFiles()) {
                    String tableName = DirectoryUtilities.getRelativePath(new File(folderField.getText()),
                            table);/*from   ww  w.  ja v  a  2  s .c o m*/
                    if (!tables.contains(tableName))
                        tables.add(tableName);
                    tableList.setListData(tables);
                }

            }
        } else if (sourceDbSettings.dataType == DbSettings.DATABASE) {
            RichConnection connection = new RichConnection(sourceDbSettings.server, sourceDbSettings.domain,
                    sourceDbSettings.user, sourceDbSettings.password, sourceDbSettings.dbType);
            String tableNames = StringUtilities.join(connection.getTableNames(sourceDbSettings.database), "\t");
            if (tableNames.length() == 0) {
                JOptionPane.showMessageDialog(frame, "No tables found in database " + sourceDbSettings.database,
                        "Error fetching table names", JOptionPane.ERROR_MESSAGE);
            } else {
                DBTableSelectionDialog selectionDialog = new DBTableSelectionDialog(frame, true, tableNames);
                if (selectionDialog.getAnswer()) {
                    for (Object item : selectionDialog.getSelectedItems()) {
                        if (!tables.contains(item))
                            tables.add((String) item);
                        tableList.setListData(tables);
                    }
                }
            }
            connection.close();
        }
    }
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Slectionner un fichier PUML//from   w  ww. ja v  a 2 s .c o m
 *
 * @param jTextFieldFichier le composant contenant le nom du fichier PUML en
 * cours d'utilisation
 */
public void selectInputFile(JTextField jTextFieldFichier) {
    final File fichier = new File(jTextFieldFichier.getText());
    if (fichier.exists()) {
        fileChooser.setCurrentDirectory(fichier.getParentFile());
    }
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileFilter(pumlFilter);
    fileChooser.addChoosableFileFilter(pumlFilter);
    fileChooser.setDialogTitle("Choisir un fichier PUML ...");

    final int returnVal = fileChooser.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fileChooser.getSelectedFile();
        if (file.exists()) {
            jTextFieldFichier.setText(file.getPath());
            myProperties.setProperty(nomFichierPropertie, jTextFieldFichier.getText());
        }
    }
}

From source file:org.panbox.desktop.common.gui.RestoreRevisionDialog.java

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser(PANBOX_DIR + "/" + shareName);
    fileChooser.setFileView(new FileView() {
        @Override/*from w w w  .jav a 2s . c o m*/
        public Boolean isTraversable(File f) {
            try {
                return f.isDirectory()
                        && FilenameUtils.directoryContains(PANBOX_DIR.getAbsolutePath(), f.getAbsolutePath());
            } catch (IOException e) {
                logger.error("Error determining folder parent status!");
                return true;
            }
        }
    });
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int ret = fileChooser.showOpenDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFile().getParentFile().getAbsolutePath()
            .startsWith(PANBOX_DIR.getAbsolutePath())) {
        String path = getCSPSupportedPath(fileChooser.getSelectedFile().getPath());
        fileTextField.setText(path);
        fillRevisionsForFileName(path);
    }
}

From source file:org.parosproxy.paros.extension.beanshell.BeanShellConsoleDialog.java

private JButton getBtnLoad() {
    if (btnLoad == null) {
        btnLoad = new JButton();
        btnLoad.setText("Load...");

        btnLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                if (getBeanShellPanel().isSaved() == false) {
                    int confirm = view.showConfirmDialog("Script is not saved, discard?");
                    if (confirm == JOptionPane.CANCEL_OPTION)
                        return;
                }/*from w w w . j  a v a  2 s  . c  om*/
                JFileChooser fc = new JFileChooser(scriptsDir);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int result = fc.showOpenDialog(getBeanShellPanel());

                if (result == JFileChooser.APPROVE_OPTION) {
                    try {
                        String temp = loadScript(fc.getSelectedFile());
                        getBeanShellPanel().getTxtEditor().setText(temp);
                        getBeanShellPanel().setSaved(true);
                        currentScriptFile = fc.getSelectedFile();
                    } catch (IOException ee) {
                        ee.printStackTrace();
                    }

                }
            }
        });
    }
    return btnLoad;
}

From source file:org.parosproxy.paros.extension.beanshell.BeanShellConsoleDialog.java

private JButton getBtnSave() {
    if (btnSave == null) {
        btnSave = new JButton();
        btnSave.setText("Save...");

        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                if (currentScriptFile != null) {
                    try {
                        saveScript(getBeanShellPanel().getTxtEditor().getText(), currentScriptFile);
                        getBeanShellPanel().setSaved(true);
                    } catch (IOException ee) {
                        ee.printStackTrace();
                    }/*from  w  w w .  j a  v a2s . c  o  m*/

                } else {
                    JFileChooser fc = new JFileChooser(scriptsDir);
                    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    int result = fc.showSaveDialog(getBeanShellPanel());

                    if (result == JFileChooser.APPROVE_OPTION) {
                        try {
                            saveScript(getBeanShellPanel().getTxtEditor().getText(), fc.getSelectedFile());
                            getBeanShellPanel().setSaved(true);
                            currentScriptFile = fc.getSelectedFile();
                        } catch (IOException ee) {
                            ee.printStackTrace();
                        }
                    }
                }
            }
        });
    }
    return btnSave;
}

From source file:org.parosproxy.paros.extension.beanshell.BeanShellConsoleDialog.java

private JButton getBtnSaveAs() {
    if (btnSaveAs == null) {
        btnSaveAs = new JButton();
        btnSaveAs.setText("Save as...");

        btnSaveAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                JFileChooser fc = new JFileChooser(scriptsDir);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int result = fc.showSaveDialog(getBeanShellPanel());
                if (result == JFileChooser.APPROVE_OPTION) {
                    try {
                        saveScript(getBeanShellPanel().getTxtEditor().getText(), fc.getSelectedFile());
                        getBeanShellPanel().setSaved(true);
                        currentScriptFile = fc.getSelectedFile();
                    } catch (IOException ee) {
                        ee.printStackTrace();
                    }/*  w  ww . ja va  2s  .co  m*/
                }

            }
        });
    }
    return btnSaveAs;
}

From source file:org.pdfsam.plugin.merge.actions.SaveListAsXmlAction.java

public void actionPerformed(ActionEvent e) {
    PdfSelectionTableItem[] rows = selectionPanel.getTableRows();
    if (!ArrayUtils.isEmpty(rows)) {
        try {/*from  w  w  w  .j  av  a  2 s  .co  m*/
            JFileChooser fileChooser = SharedJFileChooser.getInstance(SharedJFileChooserType.XML_FILE,
                    JFileChooser.FILES_ONLY);
            if (fileChooser.showSaveDialog(selectionPanel) == JFileChooser.APPROVE_OPTION) {
                File selectedFile = FileExtensionUtility.ensureExtension(fileChooser.getSelectedFile(),
                        FileExtensionUtility.XML_EXTENSION);
                writeXmlFile(rows, selectedFile);
            }
        } catch (Exception ex) {
            LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                    "Unable to save xml file."), ex);
        }
    }
}

From source file:org.p_vcd.ui.VcdDialog.java

private void selectFileButton() {
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);//from w ww  .  j  ava 2s.co m
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(
            new FileNameExtensionFilter("images and videos", Parameters.get().getImageAndVideoExtensions()));
    File def = Parameters.get().getDefaultDir_QuerySelection();
    if (def != null)
        fc.setCurrentDirectory(def);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Parameters.get().updateDefaultDir_QuerySelection(fc.getCurrentDirectory());
        queryFile = fc.getSelectedFile();
        lbl_queryFile.setText(queryFile.getAbsolutePath());
        radio_queryFile.setSelected(true);
    }
}