Example usage for javax.swing JFileChooser setMultiSelectionEnabled

List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled

Introduction

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

Prototype

@BeanProperty(description = "Sets multiple file selection mode.")
public void setMultiSelectionEnabled(boolean b) 

Source Link

Document

Sets the file chooser to allow multiple file selections.

Usage

From source file:ObjectLabEnterpriseSoftware.FileManager.java

public String browseForFile() {
    JFileChooser fileopen = new JFileChooser(); //in brackets, add Syncthing directory or new Drive's address for default location
    //Limits selected files to the following types. TODO fix list
    fileopen.setAcceptAllFileFilterUsed(false);
    fileopen.setMultiSelectionEnabled(false);
    /* PLEASE NOTE THIS IS NOT DYNAMIC!!!! WILL NEED TO GET ALLOWED FILE TYPES BASED ON PRINTER */
    //fileopen.setFileFilter(new FileNameExtensionFilter("Object Files", "obj", "zpr", "stl"));
    int ret = fileopen.showDialog(null, "Open file");

    if (ret == JFileChooser.APPROVE_OPTION) {
        File file = fileopen.getSelectedFile();
        //Inputs the file location into the textbox "fileName"
        return file.toString().replaceAll("'", "");
    }/*from ww  w .ja  v a  2  s.  com*/

    return null;

}

From source file:op.controlling.PnlControlling.java

private JPanel createContentPanel4Hygiene() {
    JPanel pnlContent = new JPanel(new VerticalLayout());

    JPanel pnlPrevalence = new JPanel(new BorderLayout());
    final JButton btnPrevalence = GUITools.createHyperlinkButton("opde.controlling.hygiene.prevalence", null,
            null);/*w ww. ja v  a2 s. c o  m*/
    final JDateChooser jdc = new JDateChooser(new Date());
    final JCheckBox cbAnonymous = new JCheckBox(SYSTools.xx("misc.msg.anon"));
    cbAnonymous.setSelected(true);

    jdc.setMaxSelectableDate(new Date());

    btnPrevalence.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    MREPrevalenceSheets mre = new MREPrevalenceSheets(new LocalDate(), cbAnonymous.isSelected(),
                            progressClosure);
                    return mre.createSheet();
                }

                @Override
                protected void done() {
                    try {
                        File source = (File) get();

                        Object[] options = { SYSTools.xx("prevalence.optiondialog.option1"),
                                SYSTools.xx("prevalence.optiondialog.option2"),
                                SYSTools.xx("opde.wizards.buttontext.cancel") };

                        int n = JOptionPane.showOptionDialog(OPDE.getMainframe(),
                                SYSTools.xx("prevalence.optiondialog.question"),
                                SYSTools.xx("prevalence.optiondialog.title"), JOptionPane.YES_NO_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                        File copyTargetDirectory = null;

                        if (n == 1) {
                            JFileChooser chooser = new JFileChooser();
                            chooser.setDialogTitle("title");
                            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                            chooser.setMultiSelectionEnabled(false);
                            chooser.setAcceptAllFileFilterUsed(false);

                            if (chooser.showOpenDialog(pnlPrevalence) == JFileChooser.APPROVE_OPTION) {
                                copyTargetDirectory = chooser.getSelectedFile();
                            }
                        }

                        if (copyTargetDirectory != null) {
                            FileUtils.copyFile(source, copyTargetDirectory);
                        } else {
                            if (n == 0) {
                                SYSFilesTools.handleFile((File) get(), Desktop.Action.OPEN);
                            }
                        }

                    } catch (Exception e) {
                        OPDE.fatal(e);
                    }

                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    pnlPrevalence.add(btnPrevalence, BorderLayout.WEST);

    JPanel optionPanel = new JPanel();
    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.LINE_AXIS));

    optionPanel.add(cbAnonymous);
    optionPanel.add(jdc);

    pnlPrevalence.add(optionPanel, BorderLayout.EAST);
    pnlContent.add(pnlPrevalence);

    return pnlContent;
}

From source file:op.tools.SYSTools.java

public static File[] chooseFile(Component parent, boolean multiselection) {
    File[] result = null;//from   w w  w  .ja v  a2s.  c om
    String cname = parent.getClass().getName();
    String startdir = System.getProperty("user.home");
    if (OPDE.getProps().containsKey("DIR." + cname)) {
        startdir = OPDE.getProps().getProperty("DIR." + cname);
    }
    JFileChooser jfc = new JFileChooser(startdir);
    jfc.setMultiSelectionEnabled(multiselection);
    int response = jfc.showOpenDialog(parent);
    if (response == JFileChooser.APPROVE_OPTION) {
        if (multiselection) {
            result = jfc.getSelectedFiles();
        } else {
            result = new File[] { jfc.getSelectedFile() };
        }

        //String newPath = result[0].getAbsolutePath();
        String myPath = result[0].getParent();
        SYSPropsTools.storeProp("DIR." + cname, myPath, OPDE.getLogin().getUser());

    }
    return result;
}

From source file:org.domainmath.gui.MainFrame.java

/**
 * Save script as another name.//from   w ww  .j  a  v a2s .c  om
 */
public void saveScriptAs() {
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);
    fc.setDialogTitle("Save As");

    int returnVal = fc.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String oldfile = fileTab.getToolTipTextAt(fileTab.getSelectedIndex());
        save(fc.getSelectedFile(), fileTab.getSelectedIndex());
        this.removeFileNameFromList(oldfile);
        fileTab.setToolTipTextAt(fileTab.getSelectedIndex(), fc.getSelectedFile().getAbsolutePath());
        this.addFileNameToList(fc.getSelectedFile().getAbsolutePath());
    }

}

From source file:org.domainmath.gui.MainFrame.java

/**
 * Creates file chooser dialog box and allows the user to select files
 * and importData selected files in fileTab.
 *///from   ww  w. j ava  2s.  c  o  m
public void open() {
    JFileChooser fc = new JFileChooser();

    // set current directory.
    if (fileTab.getTabCount() > 0) {
        File f = new File(fileTab.getToolTipTextAt(fileTab.getSelectedIndex()));
        fc.setCurrentDirectory(f.getParentFile());
    } else {
        fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    }

    FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files  (*.m)", "m");

    fc.setAcceptAllFileFilterUsed(false);

    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(true);
    fc.setFileView(new ScriptFileView());
    File file1[];
    int returnVal = fc.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file1 = fc.getSelectedFiles();

        this.setCurrentDirFileTab(fc.getCurrentDirectory().getAbsolutePath());
        for (int i = 0; i < file1.length; i++) {
            if (!fileNameList.contains(file1[i].getAbsolutePath())) {
                open(file1[i], i);

            } else {
                System.out.println(file1[i].getAbsolutePath() + " already open!");
            }
        }
    }
}

From source file:org.domainmath.gui.MainFrame.java

public void browse() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setMultiSelectionEnabled(false);

    File _file;/*w  w  w .  j  a  va  2  s .  c  o m*/
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        _file = fc.getSelectedFile();
        setDir(_file.getAbsolutePath());

    }
}

From source file:org.domainmath.gui.MainFrame.java

public void saveHistoryAs() {
    JFileChooser fc = new JFileChooser();

    FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files  (*.m)", "m");
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileFilter(filter);//from   w ww .  j  a va2  s .  c  o  m
    fc.setMultiSelectionEnabled(false);

    fc.setDialogTitle("Save As");
    File file_save;
    int returnVal = fc.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String path = fc.getSelectedFile().getAbsolutePath();
        if (!path.endsWith(".m")) {
            file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m");
            saveHistory(file_save);
        } else {
            file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m");
            saveHistory(file_save);
        }

    }
}

From source file:org.domainmath.gui.MainFrame.java

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setMultiSelectionEnabled(false);

    Path browse_file;//from   w  w  w  .j  a  v  a 2 s.  co  m
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        browse_file = fc.getSelectedFile().toPath();
        setDir(browse_file.toString());
        requestToChangeDir(browse_file.toString());
        fileTreePanel.updateFileTree(fc.getSelectedFile());

    }

}

From source file:org.domainmath.gui.MainFrame.java

public void saveplot() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileFilter(DomainMathFileFilter.SAVE_PLOT_FILE_FILTER);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);

    File file_plot;/*from w w w .  ja  v a  2s  .  c  o m*/
    String name;
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        System.err.println(fc.getFileFilter().getDescription());
        file_plot = fc.getSelectedFile();
        name = file_plot.getName();
        evaluateWithOutput("saveas(1," + "'" + file_plot.getAbsolutePath() + "');");

    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Event handler for this application, handles all menu items.
 *//*from   w  ww.  j  av  a2s. co m*/
public void actionPerformed(ActionEvent event) {
    // Service Menu Events
    if ("LoginEvent".equals(event.getActionCommand())) {
        loginEvent(null);
    } else if ("LogoutEvent".equals(event.getActionCommand())) {
        logoutEvent();
    } else if (event.getActionCommand() != null && event.getActionCommand().startsWith("LoginSwitch")) {
        String loginName = event.getActionCommand().substring("LoginSwitch:".length());
        AWSCredentials awsCredentials = (AWSCredentials) loginAwsCredentialsMap.get(loginName);
        loginEvent(awsCredentials);
    } else if ("QuitEvent".equals(event.getActionCommand())) {
        System.exit(0);
    }

    // Bucket Events.
    else if ("ViewBucketProperties".equals(event.getActionCommand())) {
        listBucketProperties();
    } else if ("RefreshBuckets".equals(event.getActionCommand())) {
        listAllBuckets();
    } else if ("CreateBucket".equals(event.getActionCommand())) {
        createBucketAction();
    } else if ("DeleteBucket".equals(event.getActionCommand())) {
        deleteSelectedBucket();
    } else if ("ManageDistributions".equals(event.getActionCommand())) {
        S3Bucket[] buckets = bucketTableModel.getBuckets();
        String[] bucketNames = new String[buckets.length];
        for (int i = 0; i < buckets.length; i++) {
            bucketNames[i] = buckets[i].getName();
        }
        ManageDistributionsDialog.showDialog(ownerFrame, cloudFrontService, bucketNames, this);
    } else if ("AddThirdPartyBucket".equals(event.getActionCommand())) {
        addThirdPartyBucket();
    } else if ("UpdateBucketACL".equals(event.getActionCommand())) {
        updateBucketAccessControlList();
    } else if ("UpdateBucketRequesterPaysStatus".equals(event.getActionCommand())) {
        updateBucketRequesterPaysSetting();
    }

    // Object Events
    else if ("ViewOrModifyObjectAttributes".equals(event.getActionCommand())) {
        displayObjectsAttributesDialog();
    } else if ("CopyObjects".equals(event.getActionCommand())) {
        copyObjects();
    } else if ("RefreshObjects".equals(event.getActionCommand())) {
        listObjects();
    } else if ("UpdateObjectACL".equals(event.getActionCommand())) {
        displayAclModificationDialog();
    } else if ("GeneratePublicGetURLs".equals(event.getActionCommand())) {
        generatePublicGetUrls();
    } else if ("GenerateTorrentURL".equals(event.getActionCommand())) {
        generateTorrentUrl();
    } else if ("DeleteObjects".equals(event.getActionCommand())) {
        deleteSelectedObjects();
    } else if ("DownloadObjects".equals(event.getActionCommand())) {
        downloadSelectedObjects();
    } else if ("UploadFiles".equals(event.getActionCommand())) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setDialogTitle("Choose files to upload");
        fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fileChooser.setApproveButtonText("Upload files");
        fileChooser.setCurrentDirectory(fileChoosersLastUploadDirectory);

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

        final File[] uploadFiles = fileChooser.getSelectedFiles();
        if (uploadFiles.length == 0) {
            return;
        }

        // Save the chosen directory location for next time.
        fileChoosersLastUploadDirectory = uploadFiles[0].getParentFile();

        uploadFiles(uploadFiles);
    } else if (event.getSource().equals(filterObjectsCheckBox)) {
        if (filterObjectsCheckBox.isSelected()) {
            filterObjectsPanel.setVisible(true);
        } else {
            filterObjectsPanel.setVisible(false);
            filterObjectsPrefix.setText("");
            if (filterObjectsDelimiter.getSelectedIndex() != 0) {
                filterObjectsDelimiter.setSelectedIndex(0);
            }
        }
    }

    // Tools events
    else if ("BucketLogging".equals(event.getActionCommand())) {
        S3Bucket[] buckets = bucketTableModel.getBuckets();
        BucketLoggingDialog.showDialog(ownerFrame, s3ServiceMulti.getS3Service(), buckets, this);
    }

    // Preference Events
    else if ("PreferencesDialog".equals(event.getActionCommand())) {
        PreferencesDialog.showDialog(cockpitPreferences, ownerFrame, this);

        // Save a user's preferences if requested, otherwise wipe any existing preferences file.
        File cockpitPreferencesPropertiesFile = new File(cockpitHomeDirectory,
                Constants.COCKPIT_PROPERTIES_FILENAME);
        if (cockpitPreferences.isRememberPreferences()) {
            try {
                Properties properties = cockpitPreferences.toProperties();
                if (!cockpitHomeDirectory.exists()) {
                    cockpitHomeDirectory.mkdir();
                }
                properties.list(new PrintStream(new FileOutputStream(cockpitPreferencesPropertiesFile)));
            } catch (IOException e) {
                String message = "Unable to save your preferences";
                log.error(message, e);
                ErrorDialog.showDialog(ownerFrame, this, message, e);
            }
        } else if (cockpitPreferencesPropertiesFile.exists()) {
            // User elected not to store preferences, delete the existing preferences file.
            cockpitPreferencesPropertiesFile.delete();
        }

        if (cockpitPreferences.isEncryptionPasswordSet()) {
            try {
                encryptionUtil = new EncryptionUtil(cockpitPreferences.getEncryptionPassword(),
                        cockpitPreferences.getEncryptionAlgorithm(), EncryptionUtil.DEFAULT_VERSION);
            } catch (Exception e) {
                String message = "Unable to start encryption utility";
                log.error(message, e);
                ErrorDialog.showDialog(ownerFrame, this, message, e);
            }
        } else {
            encryptionUtil = null;
        }
    }

    // Ooops...
    else {
        log.debug("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event);
    }
}