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:plugin.notes.gui.NotesView.java

/**
 *  {@literal handle File->Open.} Will open any .gmn files, and import them into your
 *  notes structure/*  w  w  w.j a va 2 s.  c o  m*/
 */
public void handleOpen() {
    // TODO fix
    String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, System.getProperty("user.dir"));
    File defaultFile = new File(sFile);
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(defaultFile);
    chooser.addChoosableFileFilter(getFileType());
    chooser.setFileFilter(getFileType());
    chooser.setMultiSelectionEnabled(true);
    Component component = GMGenSystem.inst;
    Cursor originalCursor = component.getCursor();
    component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    int option = chooser.showOpenDialog(GMGenSystem.inst);

    if (option == JFileChooser.APPROVE_OPTION) {
        for (File noteFile : chooser.getSelectedFiles()) {
            SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, noteFile.toString());

            if (noteFile.toString().endsWith(EXTENSION)) {
                openGMN(noteFile);
            }
        }
    }

    GMGenSystem.inst.setCursor(originalCursor);
    refreshTree();
}

From source file:psidev.psi.mi.tab.client.gui.DragAndDropConverter.java

public static void addFileMenu(final JFrame frame, JMenuBar menuBar) {

    // Create a menu
    JMenu menu = new JMenu("File");
    menuBar.add(menu);//w  w  w.  jav a2 s  .  co  m

    // Create a file open iten
    JMenuItem openFileItem = new JMenuItem("Open files...");
    openFileItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            JFileChooser chooser = new JFileChooser();

            chooser.setApproveButtonText("Convert to MITAB25");

            // Enable multiple selections
            chooser.setMultiSelectionEnabled(true);

            // Show the dialog; wait until dialog is closed
            chooser.showOpenDialog(frame);

            // Retrieve the selected files. This method returns empty
            // if multiple-selection mode is not enabled.
            File[] files = chooser.getSelectedFiles();

            if (files != null && files.length > 0) {
                FilesProcessor processor = new FilesProcessor();
                processor.process(frame, files, expansionStrategy, postProcessorStrategy,
                        aggregateSelectedFiles);
            }
        }
    });
    menu.add(openFileItem);

    // Create an exit
    final JMenuItem mergeItem = new JCheckBoxMenuItem("Aggregate all selected files", aggregateSelectedFiles);
    mergeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // If selected, all files dropped or selected at once are aggregated into a single MITAB file
            aggregateSelectedFiles = mergeItem.isSelected();
            log.debug("Aggregate is " + aggregateSelectedFiles);
        }
    });
    menu.add(mergeItem);

    // Create an exit
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(exitItem);
}

From source file:rmeteorj.GUI.GUI.java

/**
 * Open file for detection or analysis/*from   w w  w.  jav  a2  s  .c  om*/
 */
public static void openFile() {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Open file");
    fc.setMultiSelectionEnabled(true);

    int response = fc.showOpenDialog(MainWindow.getInstance());

    if (response == JFileChooser.APPROVE_OPTION) {
        String[] options = ArrayUtils.addAll(ModuleManager.getManager().getEnabledDetectModulesNames(),
                ModuleManager.getManager().getEnabledAnalyzeModulesNames());
        if (options.length == 0) {
            JOptionPane.showMessageDialog(MainWindow.getInstance(), "Enable detect or analyze module first.");
            return;
        }
        options[options.length] = "Cancel";

        String moduleName = (String) JOptionPane.showInputDialog(MainWindow.getInstance(),
                "Send opened files to: ", "Open file", JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

        if (!moduleName.equals("Cancel")) {
            ModuleManager.getManager().openFilesAnalyzeOrDetect(fc.getSelectedFiles(), moduleName);
        }
    }
}

From source file:ropes.MainWindow.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    //TODO display loader animation while liberys are loading
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.setMultiSelectionEnabled(true);

    int returnVal = fc.showOpenDialog(MainWindow.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] files = fc.getSelectedFiles();
        for (File file : files) {

            if (file.isFile()) {
                addFileToList(file);/*from ww w  .j  a  v  a 2s.c  o m*/
            } else if (file.isDirectory()) {
                //adds the parent to tree
                root.add(new DefaultMutableTreeNode(file));
                //adds all the subfolders and files to the parent
                addFileRecursive(file.toString());

            }

        }

    }

}

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   ww  w .  j  av a2  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:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java

public void actionPerformed(ActionEvent ae) {

    /*   if (ae.getActionCommand().equals("plot")) {
            /*from  www  . j a v  a 2s.  c om*/
          drawScatterPlot();         
       }
    */
    if (ae.getActionCommand().equals("save_image")) {
        ImageSaver.saveImage(scatterPlotPanel);
    }

    else if (ae.getActionCommand().equals("swap_plot")) {

        if (storesQuantitated()) {

            plotPanel.remove(scatterPlotPanel);

            if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
                scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes,
                        currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display standard scatterplot");
            } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
                scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList,
                        currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues,
                        simpleRegression);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display z-score plot");
            }
        }
    }

    else if (ae.getActionCommand().equals("close")) {

        /*   if(currentSelectedProbeList != null){
              currentSelectedProbeList[0].delete();
              //currentSelectedProbeList = null;
                      
           }
        */ this.dispose();

    } else if (ae.getActionCommand().equals("select_all")) {

        if (selectAllButton.isSelected()) {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = true;

                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("deselect all");
        } else {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = false;
                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("select all");
        }

    }

    else if (ae.getActionCommand().equals("save_selected_probelists")) {

        boolean[] selectedListsBoolean = tableModel.selected;

        if (selectedListsBoolean.length != filterResultsPVals.length) {
            System.err.println("not adding up here");
        }

        else {

            ArrayList<MappedGeneSetTTestValue> selectedListsArrayList = new ArrayList<MappedGeneSetTTestValue>();

            for (int i = 0; i < selectedListsBoolean.length; i++) {

                if (selectedListsBoolean[i] == true) {
                    selectedListsArrayList.add(filterResultsPVals[i]);
                }
            }

            MappedGeneSetTTestValue[] selectedLists = selectedListsArrayList
                    .toArray(new MappedGeneSetTTestValue[0]);

            if (selectedLists.length == 0) {

                JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No probe lists were selected",
                        "No probe lists selected", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            saveProbeLists(selectedLists);

            if (currentSelectedProbeList != null) {
                currentSelectedProbeList[0].delete();
                currentSelectedProbeList = null;
            }
        }
    }

    else if (ae.getActionCommand().equals("save_table")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

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

            public boolean accept(File f) {
                if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) {
                    return true;
                } else {
                    return false;
                }
            }

        });

        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;

        File file = chooser.getSelectedFile();
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }

        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);

        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(this,
                    file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?",
                    0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" },
                    "Overwrite and Save");

            if (answer > 0) {
                return;
            }
        }

        try {
            PrintWriter p = new PrintWriter(new FileWriter(file));

            TableModel model = table.getModel();

            int rowCount = model.getRowCount();
            int colCount = model.getColumnCount();

            // Do the headers first
            StringBuffer b = new StringBuffer();
            for (int c = 1; c < colCount; c++) {
                b.append(model.getColumnName(c));
                if (c + 1 != colCount) {
                    b.append("\t");
                }
            }

            p.println(b);

            for (int r = 0; r < rowCount; r++) {
                b = new StringBuffer();
                for (int c = 1; c < colCount; c++) {
                    b.append(model.getValueAt(r, c));
                    if (c + 1 != colCount) {
                        b.append("\t");
                    }
                }
                p.println(b);

            }
            p.close();

        }

        catch (FileNotFoundException e) {
            new CrashReporter(e);
        } catch (IOException e) {
            new CrashReporter(e);
        }

    }

    else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}

From source file:uk.ac.liverpool.narrative.SolutionGraphics.java

@Override
public void run() {
    // set up action cost filter
    if (actionCostsFilePath != null && (new File(actionCostsFilePath)).exists()) {
        CharacterActionSolutionFilter tc = new CharacterActionSolutionFilter();
        if (actionCostsFilePath != null && (new File(actionCostsFilePath)).exists()) {
            tc.setActionCosts(BranchingStoryGenerator.readCosts(actionCostsFilePath,
                    BranchingStoryGenerator.actionCostType));
        }/*from   w  w w  .  j  a  va  2  s.co  m*/
        if (characterCostsFilePath != null && (new File(characterCostsFilePath)).exists()) {
            tc.setCharacterCosts(BranchingStoryGenerator.readCosts(characterCostsFilePath,
                    BranchingStoryGenerator.characterCostType));
        }
        if (authorDirection != null && (new File(authorDirection)).exists()) {
            tc.setAuthorDirection(
                    BranchingStoryGenerator.readCosts(authorDirection, BranchingStoryGenerator.authorCostType)
                            .get(BranchingStoryGenerator.authorCostType));
        }
        sg.filters.add(tc);
        tc.setThreshold(threshold);
    }
    if (character != null) {
        charFilter = new CharacterFilter(character);
    }

    if (fc) {
        JFileChooser fc = new JFileChooser(BranchingStoryGenerator.DestinationFolder);
        fc.setAccessory(new SolutionPreview(fc));
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Solution files", "sol");
        fc.setFileFilter(filter);
        fc.setMultiSelectionEnabled(true);
        fc.showOpenDialog(vvv);
        File[] files = fc.getSelectedFiles();
        for (File f : files) {
            try {
                sg.readSolutionFile(f);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    } else {
        for (File f : BranchingStoryGenerator.DestinationFolder.listFiles()) {
            if (!f.isFile() || !f.getName().endsWith(".sol")) {
                continue;
            }
            try {
                sg.readSolutionFile(f);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    System.out.println("done");

}

From source file:umich.ms.batmass.filesupport.core.actions.importing.ImportFileByCategory.java

/**
 * //from w ww . j  a v  a 2 s .  co m
 * @param fcBuilder
 * @return 
 */
protected File[] showMultiOpenDialog(FileChooserBuilder fcBuilder) {
    JFileChooser chooser = fcBuilder.createFileChooser();
    BMFileView bmFileView = new BMFileView(getFileCategory());
    chooser.setFileView(bmFileView);
    chooser.setMultiSelectionEnabled(true);
    int result = chooser.showOpenDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == result) {
        File[] files = chooser.getSelectedFiles();
        return files == null ? new File[0] : files;
    } else {
        return null;
    }
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Open or create a SQL statement file.//from www . ja  v a2  s  .c o m
 */
private void openSQLFile() {
    JFileChooser fileMenu;
    FileFilter defaultFileFilter = null;
    FileFilter preferredFileFilter = null;
    File chosenSQLFile;
    int returnVal;

    chosenSQLFile = null;

    // Save current information, including SQL Statements
    saveConfig();

    // Allow user to choose/create new file for SQL Statements
    fileMenu = new JFileChooser(new File(queryFilename));

    for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) {
        if (filterDefinition.name().startsWith("QUERY")) {
            final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(),
                    filterDefinition.acceptedSuffixes());
            if (filterDefinition.isPreferredOption()) {
                preferredFileFilter = fileFilter;
            }
            fileMenu.addChoosableFileFilter(fileFilter);
            if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) {
                defaultFileFilter = fileFilter;
            }
        }
    }

    if (defaultFileFilter != null) {
        fileMenu.setFileFilter(defaultFileFilter);
    } else if (latestChosenQueryFileFilterDescription != null
            && latestChosenQueryFileFilterDescription.startsWith("All")) {
        fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter());
    } else if (preferredFileFilter != null) {
        fileMenu.setFileFilter(preferredFileFilter);
    }

    fileMenu.setSelectedFile(new File(queryFilename));
    fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle"));
    fileMenu.setDialogType(JFileChooser.OPEN_DIALOG);
    fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileMenu.setMultiSelectionEnabled(false);

    if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        chosenSQLFile = fileMenu.getSelectedFile();

        // Adjust file suffix if necessary
        final FileFilter fileFilter = fileMenu.getFileFilter();
        if (fileFilter != null && fileFilter instanceof SuffixFileFilter
                && !fileMenu.getFileFilter().accept(chosenSQLFile)) {
            chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile);
        }

        if (!chosenSQLFile.exists()) {
            returnVal = JOptionPane.showConfirmDialog(this,
                    Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()),
                    Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (returnVal == JOptionPane.NO_OPTION) {
                querySelection.removeAllItems();
                queryText.setText("");
                QueryHistory.getInstance().clearAllQueries();

                // Update GUI
                setPrevNextIndication();
            } else if (returnVal == JOptionPane.CANCEL_OPTION) {
                chosenSQLFile = null;
            }
        } else {
            setQueryFilename(chosenSQLFile.getAbsolutePath());
            querySelection.removeAllItems();
            queryText.setText("");
            loadCombo(querySelection, queryFilename);
            QueryHistory.getInstance().clearAllQueries();

            // Update GUI
            setPrevNextIndication();
        }
    }

    try {
        latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription();
    } catch (Throwable throwable) {
        LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable);
    }

    if (chosenSQLFile != null) {
        setQueryFilename(chosenSQLFile.getAbsolutePath());
        saveConfig();
    }
}

From source file:verdandi.ui.action.ImportPluginAction.java

/**
 * Ask the import file from the user/*from   ww w.j a v  a  2s.  co  m*/
 */
private File getFile() {
    File res = null;
    Preferences prefs = Preferences.userNodeForPackage(getClass());
    File importDir = new File(prefs.get(KEY_CWD, System.getProperty("user.home")));

    JFileChooser chooser = new JFileChooser(importDir);
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".jar") || f.isDirectory();
        }

        @Override
        public String getDescription() {
            return RC.getString("pluginimportaction.filechooser.jarfilter.description");
        }
    });

    chooser.setDialogTitle(RC.getString("pluginimportaction.filechooser.title"));
    chooser.setMultiSelectionEnabled(false);

    if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) {
        LOG.debug("User cancelled");
        return null;
    }
    res = chooser.getSelectedFile();

    prefs.put("import.dir", res.getParent());
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Cannot write export file preference", e);
    }

    return res;
}