Example usage for javax.swing JFileChooser FILES_AND_DIRECTORIES

List of usage examples for javax.swing JFileChooser FILES_AND_DIRECTORIES

Introduction

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

Prototype

int FILES_AND_DIRECTORIES

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

Click Source Link

Document

Instruction to display both files and directories.

Usage

From source file:smlm.util.SRutil.java

public static String[][] getFiles(String title, String initialRoot, String initialFile) {
    if (title == null || title == "")
        title = "Choose files";
    if (initialRoot == null || initialRoot == "")
        initialRoot = "E:\\Data";

    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Tiff files", "tif", "tiff");
    chooser.setFileFilter(filter);//from   w ww.  j  a va  2  s  .  c o m
    chooser.setDialogTitle(title);
    chooser.setCurrentDirectory(new File(initialRoot));
    chooser.setMultiSelectionEnabled(true);

    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String[][] files = new String[chooser.getSelectedFiles().length][2];
        for (int i = 0; i < files.length; i++) {
            files[i][0] = chooser.getSelectedFiles()[i].getParent();
            files[i][1] = chooser.getSelectedFiles()[i].getName();
        }
        return files;
    } else
        return null;
}

From source file:tvbrowser.ui.settings.WebbrowserSettingsTab.java

/**
 * Creates the settings panel for this tab.
 *//*w w w .j  ava 2s .co  m*/
public JPanel createSettingsPanel() {
    mSettingsPn = new JPanel(new FormLayout("5dlu, 10dlu, pref, 3dlu, pref, 3dlu, pref, fill:3dlu:grow, 3dlu",
            "pref, 5dlu, pref, 5dlu, pref, 5dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref"));
    mSettingsPn.setBorder(Borders.DIALOG_BORDER);

    CellConstraints cc = new CellConstraints();

    mSettingsPn.add(
            DefaultComponentFactory.getInstance().createSeparator(mLocalizer.msg("browser", "Web browser")),
            cc.xyw(1, 1, 9));

    JButton testButton = new LinkButton(mLocalizer.msg("testBrowser", "Test Webbrowser"),
            "http://www.tvbrowser.org", SwingConstants.LEFT, false);
    testButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String buffer = Settings.propUserDefinedWebbrowser.getString();
            String bufferParams = Settings.propUserDefinedWebbrowserParams.getString();
            saveSettings();
            Launch.openURL("http://www.tvbrowser.org");
            Settings.propUserDefinedWebbrowser.setString(buffer);
            Settings.propUserDefinedWebbrowserParams.setString(bufferParams);
        }
    });

    mSettingsPn.add(UiUtilities.createHelpTextArea(mLocalizer.msg("help", "Help Text")), cc.xyw(2, 3, 7));

    mSettingsPn.add(testButton, cc.xyw(2, 5, 7));

    mSettingsPn.add(new JLabel(mLocalizer.msg("whichBrowser", "which browser")), cc.xyw(2, 7, 7));

    JRadioButton useDefault = new JRadioButton(mLocalizer.msg("defaultWebbrowser", "Default Webbrowser"));
    useDefault.setSelected(Settings.propUserDefinedWebbrowser.getString() == null);
    useDefault.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateInputFields();
        }
    });

    mSettingsPn.add(useDefault, cc.xyw(2, 9, 4));

    mUseWebbrowser = new JRadioButton(mLocalizer.msg("userDefinedWebbrowser", "user defined webbrowser"));
    mUseWebbrowser.setSelected(Settings.propUserDefinedWebbrowser.getString() != null);

    mUseWebbrowser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateInputFields();
        }
    });

    ButtonGroup group = new ButtonGroup();
    group.add(useDefault);
    group.add(mUseWebbrowser);

    mSettingsPn.add(mUseWebbrowser, cc.xyw(2, 11, 7));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserExecutable", "Executable") + ":"), cc.xy(3, 13));

    mFileTextField = new JTextField(30);
    mFileTextField.setText(Settings.propUserDefinedWebbrowser.getString());
    mSettingsPn.add(mFileTextField, cc.xy(5, 13));

    mChooseButton = new JButton(Localizer.getLocalization(Localizer.I18N_SELECT));
    mChooseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (mFileChooser == null) {
                mFileChooser = new JFileChooser();

                if (OperatingSystem.isMacOs()) {
                    mFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                } else {
                    mFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                }
            }

            int retVal = mFileChooser.showOpenDialog(mSettingsPn.getParent());
            if (retVal == JFileChooser.APPROVE_OPTION) {
                File f = mFileChooser.getSelectedFile();
                if (f != null) {
                    mFileTextField.setText(f.getAbsolutePath());
                }
            }
        }
    });
    mSettingsPn.add(mChooseButton, cc.xy(7, 13));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserParameter", "Parameter") + ":"), cc.xy(3, 15));

    mParams = new JTextField();
    mParams.setText(Settings.propUserDefinedWebbrowserParams.getString());
    mSettingsPn.add(mParams, cc.xy(5, 15));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserParameterHelp", "{0} will be replaced by the url.")),
            cc.xyw(5, 17, 4));

    updateInputFields();

    return mSettingsPn;
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

Optional<SelectedPathAndFile> selectFileOrDirectory(final Optional<String> initialPathInput) {

    String initialPath;//  w ww  .  j  av a 2s. c  o m
    if (initialPathInput.isPresent() && StringUtils.isNotBlank(initialPathInput.get())) {
        initialPath = initialPathInput.get();
    } else {
        initialPath = "/";
    }

    // need to do the file choosing on the main event thread, since Swing is not thread safe, so do it here, instead of delegating to MediaImporter in ImportWorker
    SafeFileChooser chooser = new SafeFileChooser(initialPath);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    if (chooser.showOpenDialog(mainFrame.getContainer()) == JFileChooser.APPROVE_OPTION) {
        return Optional.of(new SelectedPathAndFile(chooser));
    } else {
        return Optional.empty();
    }
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

Optional<SelectedPathAndFiles> selectMultipleFilesOrDirectors(final Optional<String> initialPathInput) {

    String initialPath;// w w  w  .j  a  v a 2s  . co m
    if (initialPathInput.isPresent() && StringUtils.isNotBlank(initialPathInput.get())) {
        initialPath = initialPathInput.get();
    } else {
        initialPath = "/";
    }

    // need to do the file choosing on the main event thread, since Swing is not thread safe, so do it here, instead of delegating to MediaImporter in ImportWorker
    SafeFileChooser chooser = new SafeFileChooser(initialPath);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setMultiSelectionEnabled(true);

    if (chooser.showOpenDialog(mainFrame.getContainer()) == JFileChooser.APPROVE_OPTION) {
        return Optional.of(new SelectedPathAndFiles(chooser));
    } else {
        return Optional.empty();
    }
}

From source file:uk.sipperfly.ui.Exactly.java

private void chooseDestDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseDestDirActionPerformed
    // TODO add your handling code here:
    fileChooser = new javax.swing.JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        targetPath = file.getAbsolutePath();
        destDirLocation.setText(targetPath);
    }// w ww. j a  v a  2s.c  om
}

From source file:uk.sipperfly.ui.Exactly.java

private void chooseDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseDirActionPerformed
    fileChooser = new javax.swing.JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    int returnVal = fileChooser.showOpenDialog(this);
    List<String> validDirs = new ArrayList<String>();
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File file = fileChooser.getSelectedFile();
        inputDirPath = file.getAbsolutePath();
        String msg = "Working on directory ".concat(inputDirPath);
        Logger.getLogger(GACOM).log(Level.INFO, msg);
        UpdateResult(msg, 1);// w w w  .  jav  a  2s  . c  o m
        inputLocationDir.setText(inputDirPath);
        if (!inputDirPath.isEmpty() && inputDirPath != null) {
            validDirs.add(inputDirPath);
            try {
                bgw = new BackgroundWorker(validDirs, this, 2);
                bgw.execute();
            } catch (IOException ex) {
                Logger.getLogger(GACOM).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:uk.sipperfly.ui.Exactly.java

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

    fileChooser = new javax.swing.JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setApproveButtonText("Export");
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        String exportPath = file.getAbsolutePath().toString();
        try {//  ww w . ja v a  2 s  .  c  om
            UpdateResult("Exporting Info", 1);
            this.uIManager.exportInfo(exportPath);
            UpdateResult("Done exporting...", 0);
        } catch (IOException ex) {
            Logger.getLogger(Exactly.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(Exactly.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Exactly.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:uk.sipperfly.ui.Exactly.java

private void btnDirChooseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDirChooseActionPerformed
    // TODO add your handling code here:
    fileChooser = new javax.swing.JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(true);
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] files = fileChooser.getSelectedFiles();
        if (files.length >= 1) {
            inputDirPath = files[0].getAbsolutePath();
            editInputDir.setText(inputDirPath);
            for (int i = 1; i < files.length; i++) {
                this.list.addEntry(files[i].getAbsolutePath().toString());
            }/*from w  w w.  j  a va 2  s.com*/
        }

    }
}

From source file:uk.sipperfly.ui.Exactly.java

private void btnDirChoose1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDirChoose1ActionPerformed
    // TODO add your handling code here:
    fileChooser = new javax.swing.JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        inputDirPath = file.getAbsolutePath();
        editInputDir1.setText(inputDirPath);
    }//ww w . ja  v  a 2 s .c o  m
}

From source file:volker.streaming.music.gui.FormatPanel.java

private void initComponents() {
    formatLabel = new JLabel("How should your track info be displayed:");
    formatArea = new JTextArea(config.getFormat());
    formatLighter = new DefaultHighlighter();
    // TODO allow configuration of this color
    formatPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(200, 200, 255));
    formatArea.setHighlighter(formatLighter);
    formatArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override//from  w  w  w.j  a  v a2  s .com
        public void removeUpdate(DocumentEvent e) {
            formatUpdated();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            formatUpdated();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            formatUpdated();
        }
    });

    ImageIcon infoIcon = null;
    try {
        InputStream is = getClass().getResourceAsStream("info.png");
        if (is == null) {
            LOG.error("Couldn't find the info image.");
        } else {
            infoIcon = new ImageIcon(ImageIO.read(is));
            is.close();
        }
    } catch (IOException e1) {
        LOG.error("Couldn't find the info image.", e1);
    }
    if (infoIcon == null) {
        formatInfoButton = new JButton("?");
    } else {
        formatInfoButton = new JButton(infoIcon);
        formatInfoButton.setBorder(BorderFactory.createEmptyBorder());
    }

    formatInfoButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showFormatHelp();
        }
    });

    templateLabel = new JLabel("Your template:");

    tagLabel = new JLabel("Available tags:");
    tagList = new JList<String>(new AbstractListModel<String>() {
        private static final long serialVersionUID = -8886588605378873151L;

        @Override
        public int getSize() {
            return properTags.size();
        }

        @Override
        public String getElementAt(int index) {
            return properTags.get(index);
        }
    });
    tagScrollPane = new JScrollPane(tagList);

    previewLabel = new JLabel("Preview:");
    previewField = new JTextField();
    previewField.setEditable(false);
    previewField.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    previewField.setBackground(new Color(255, 255, 150));

    formatUpdated();
    highlightTags();

    nullMessageLabel = new JLabel("Message to display when no song is found:");
    nullMessageField = new JTextField(config.getNoTrackMessage() == null ? "" : config.getNoTrackMessage());
    nullMessageField.getDocument().addDocumentListener(new DocumentListener() {
        public void action() {
            config.setNoTrackMessage(nullMessageField.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            action();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            action();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            action();
        }
    });

    hline = new JSeparator(SwingConstants.HORIZONTAL);
    fileLabel = new JLabel("Location of text file:");
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileField = new JTextField(15);
    if (config.getOutputFile() != null) {
        fileField.setText(config.getOutputFile().getAbsolutePath());
    }
    fileField.getDocument().addDocumentListener(new DocumentListener() {
        public void action() {
            config.setOutputFile(new File(fileField.getText()));
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            action();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            action();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            action();
        }
    });
    fileButton = new JButton("Browse");
    fileButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browseFile();
        }
    });
}