Example usage for javax.swing JFileChooser setAcceptAllFileFilterUsed

List of usage examples for javax.swing JFileChooser setAcceptAllFileFilterUsed

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.")
public void setAcceptAllFileFilterUsed(boolean b) 

Source Link

Document

Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.

Usage

From source file:com.igormaznitsa.zxpoly.MainForm.java

private File chooseFileForOpen(final String title, final File initial,
        final AtomicReference<FileFilter> selectedFilter, final FileFilter... filter) {
    final JFileChooser chooser = new JFileChooser(initial);
    for (final FileFilter f : filter) {
        chooser.addChoosableFileFilter(f);
    }//  w ww.  jav  a 2 s .  c  o m
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle(title);
    chooser.setFileFilter(filter[0]);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    final File result;
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        result = chooser.getSelectedFile();
        if (selectedFilter != null) {
            selectedFilter.set(chooser.getFileFilter());
        }
    } else {
        result = null;
    }
    return result;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java

/**
 * Private methods//from   www .j  a  v  a  2s  .  c o  m
 */
//init view
private void initDataLoadingPanel() {
    dataLoadingPanel = new DRDataLoadingPanel();
    /**
     * Action Listeners.
     */
    //Popup file selector and import and parse the file
    dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Open a JFile Chooser
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle(
                    "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment");
            // to select only appropriate files
            fileChooser.setFileFilter(new FileFilter() {
                @Override
                public boolean accept(File f) {
                    if (f.isDirectory()) {
                        return true;
                    }
                    int index = f.getName().lastIndexOf(".");
                    String extension = f.getName().substring(index + 1);
                    return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv")
                            || extension.equals("tsv");
                }

                @Override
                public String getDescription() {
                    return (".xls, .xlsx, .csv and .tsv files");
                }
            });
            fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            fileChooser.setAcceptAllFileFilterUsed(false);
            // in response to the button click, show open dialog
            int returnVal = fileChooser.showOpenDialog(dataLoadingPanel);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File chosenFile = fileChooser.getSelectedFile();
                //                    // create and execute a new swing worker with the selected file for the import
                //                    ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile);
                //                    importExperimentSwingWorker.execute();
                parseDRFile(chosenFile);
                if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) {
                    dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath());
                    doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true);
                }
            } else {
                JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "",
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });

    dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                doseResponseController.setLogTransform(true);
            } else {
                doseResponseController.setLogTransform(false);
            }
        }
    });
}

From source file:gdt.jgui.entity.folder.JFolderPanel.java

/**
 * Get the context menu.//  w ww. j  a v a  2  s .c  om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    mia = null;
    int cnt = menu.getItemCount();
    if (cnt > 0) {
        mia = new JMenuItem[cnt];
        for (int i = 0; i < cnt; i++)
            mia[i] = menu.getItem(i);
    }
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("EntitiesPanel:getConextMenu:menu selected");
            menu.removeAll();
            if (mia != null) {
                for (JMenuItem mi : mia)
                    menu.add(mi);
                menu.addSeparator();
            }
            JMenuItem refreshItem = new JMenuItem("Refresh");
            refreshItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JConsoleHandler.execute(console, locator$);
                }
            });
            menu.add(refreshItem);
            JMenuItem openItem = new JMenuItem("Open folder");
            openItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File folder = new File(entihome$ + "/" + entityKey$);
                        if (!folder.exists())
                            folder.mkdir();
                        Desktop.getDesktop().open(folder);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });
            menu.add(openItem);
            JMenuItem importItem = new JMenuItem("Import");
            importItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File home = new File(System.getProperty("user.home"));
                        Desktop.getDesktop().open(home);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });

            menu.add(importItem);
            JMenuItem newItem = new JMenuItem("New text");
            newItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        JTextEditor textEditor = new JTextEditor();
                        String teLocator$ = textEditor.getLocator();
                        teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$);
                        String text$ = "New" + Identity.key().substring(0, 4) + ".txt";
                        teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$);
                        JFolderPanel fp = new JFolderPanel();
                        String fpLocator$ = fp.getLocator();
                        fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$);
                        fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        fpLocator$ = Locator.append(fpLocator$, BaseHandler.HANDLER_METHOD, "response");
                        fpLocator$ = Locator.append(fpLocator$, JRequester.REQUESTER_ACTION,
                                ACTION_CREATE_FILE);
                        String requesterResponseLocator$ = Locator.compressText(fpLocator$);
                        teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                                requesterResponseLocator$);
                        JConsoleHandler.execute(console, teLocator$);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });

            menu.add(newItem);
            //menu.addSeparator();
            if (hasToInsert()) {
                menu.addSeparator();
                JMenuItem insertItem = new JMenuItem("Insert");
                insertItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                            Transferable clipboardContents = systemClipboard.getContents(null);
                            if (clipboardContents == null)
                                return;
                            Object transferData = clipboardContents
                                    .getTransferData(DataFlavor.javaFileListFlavor);
                            List<File> files = (List<File>) transferData;
                            for (int i = 0; i < files.size(); i++) {
                                File file = (File) files.get(i);
                                if (file.exists() && file.isFile()) {
                                    System.out.println("FolderPanel:insert:in=" + file.getPath());
                                    File dir = new File(entihome$ + "/" + entityKey$);
                                    if (!dir.exists())
                                        dir.mkdir();
                                    File out = new File(entihome$ + "/" + entityKey$ + "/" + file.getName());
                                    if (!out.exists())
                                        out.createNewFile();
                                    System.out.println("FolderPanel:insert:out=" + out.getPath());
                                    FileExpert.copyFile(file, out);
                                    JConsoleHandler.execute(console, getLocator());
                                }

                                //      System.out.println("FolderPanel:import:file="+file.getPath());
                            }
                        } catch (Exception ee) {
                            LOGGER.severe(ee.toString());

                        }

                    }
                });
                menu.add(insertItem);
            }
            if (hasToPaste()) {
                menu.addSeparator();
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String[] sa = console.clipboard.getContent();
                        Properties locator;
                        String file$;
                        File file;
                        File target;
                        String dir$ = entihome$ + "/" + entityKey$;
                        File dir = new File(dir$);
                        if (!dir.exists())
                            dir.mkdir();
                        for (String aSa : sa) {
                            try {
                                locator = Locator.toProperties(aSa);
                                if (LOCATOR_TYPE_FILE.equals(locator.getProperty(Locator.LOCATOR_TYPE))) {
                                    file$ = locator.getProperty(FILE_PATH);
                                    file = new File(file$);
                                    target = new File(dir$ + "/" + file.getName());
                                    if (!target.exists())
                                        target.createNewFile();
                                    FileExpert.copyFile(file, target);
                                }
                            } catch (Exception ee) {
                                LOGGER.info(ee.toString());
                            }
                        }
                        JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(pasteItem);
            }
            if (hasSelectedItems()) {
                menu.addSeparator();
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            String[] sa = JFolderPanel.this.listSelectedItems();
                            if (sa == null)
                                return;
                            Properties locator;
                            String file$;
                            File file;
                            for (String aSa : sa) {
                                locator = Locator.toProperties(aSa);
                                file$ = locator.getProperty(FILE_PATH);
                                file = new File(file$);
                                try {
                                    if (file.isDirectory())
                                        FileExpert.clear(file$);
                                    file.delete();
                                } catch (Exception ee) {
                                    LOGGER.info(ee.toString());
                                }
                            }
                        }
                        JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(deleteItem);
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String[] sa = JFolderPanel.this.listSelectedItems();
                        console.clipboard.clear();
                        if (sa != null)
                            for (String aSa : sa)
                                console.clipboard.putString(aSa);
                    }
                });
                menu.add(copyItem);
                JMenuItem exportItem = new JMenuItem("Export");
                exportItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            String[] sa = JFolderPanel.this.listSelectedItems();
                            Properties locator;
                            String file$;
                            File file;
                            ArrayList<File> fileList = new ArrayList<File>();
                            for (String aSa : sa) {
                                try {
                                    locator = Locator.toProperties(aSa);
                                    file$ = locator.getProperty(FILE_PATH);
                                    file = new File(file$);
                                    fileList.add(file);
                                } catch (Exception ee) {
                                    LOGGER.severe(ee.toString());
                                }
                            }
                            File[] fa = fileList.toArray(new File[0]);
                            if (fa.length < 1)
                                return;
                            //                             System.out.println("Folderpanel:finish:list="+fa.length);
                            JFileChooser chooser = new JFileChooser();
                            chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
                            chooser.setDialogTitle("Export files");
                            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                            chooser.setAcceptAllFileFilterUsed(false);
                            if (chooser.showSaveDialog(JFolderPanel.this) == JFileChooser.APPROVE_OPTION) {
                                String dir$ = chooser.getSelectedFile().getPath();
                                File target;
                                for (File f : fa) {
                                    target = new File(dir$ + "/" + f.getName());
                                    if (!target.exists())
                                        target.createNewFile();
                                    FileExpert.copyFile(f, target);
                                }
                            } else {
                                Logger.getLogger(JMainConsole.class.getName()).info(" no selection");
                            }
                            //                            System.out.println("Folderpanel:finish:list="+fileList.size());  
                        } catch (Exception eee) {
                            LOGGER.severe(eee.toString());
                        }
                    }
                });
                menu.add(exportItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:ffx.ui.KeywordPanel.java

/**
 * Give the user a File Dialog Box so they can select a key file.
 *///from  ww  w .j a v a 2s.co  m
public void keyOpen() {
    if (fileOpen && KeywordComponent.isKeywordModified()) {
        int option = JOptionPane.showConfirmDialog(this, "Save Changes First", "Opening New File",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (option == JOptionPane.CANCEL_OPTION) {
            return;
        } else if (option == JOptionPane.YES_OPTION) {
            keySave(currentKeyFile);
        }
        keyClear();
    }
    JFileChooser d = MainPanel.resetFileChooser();
    if (currentSystem != null) {
        File cwd = currentSystem.getFile();
        if (cwd != null && cwd.getParentFile() != null) {
            d.setCurrentDirectory(cwd.getParentFile());
        }
    }
    d.setAcceptAllFileFilterUsed(false);
    d.setFileFilter(MainPanel.keyFileFilter);
    d.setDialogTitle("Open KEY File");
    int result = d.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File newKeyFile = d.getSelectedFile();
        if (newKeyFile != null && newKeyFile.exists() && newKeyFile.canRead()) {
            keyOpen(newKeyFile);
        }
    }
}

From source file:ctPrincipal.Principal.java

private File openImagem(String Dir, boolean lista) {
    JFileChooser fileChooser = new JFileChooser();
    BufferedImage buff = null;//from  ww  w . ja  va2s . c o m
    String caminho = null;
    try {
        caminho = new File(".").getCanonicalPath() + Dir;
    } catch (IOException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    fileChooser.setCurrentDirectory(new File(caminho));
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Images", "jpg", "png", "gif", "bmp"));
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setMultiSelectionEnabled(true);
    int result = fileChooser.showOpenDialog(getComponent(0));
    if (result == JFileChooser.APPROVE_OPTION) {
        if (lista) {
            File[] selectedFile = fileChooser.getSelectedFiles();
            arquivos = new String[selectedFile.length];
            for (int i = 0; i < selectedFile.length; i++) {
                selectedFile[i].setReadable(Boolean.TRUE);
                arquivos[i] = selectedFile[i].getAbsolutePath();
            }
            jLTotal.setText("Total de Imagens : " + arquivos.length);
        } else {
            File selectedFile = fileChooser.getSelectedFile();
            return selectedFile;
        }

    }
    return null;
}

From source file:configuration.Util.java

public static String[] simpleSearchBox(String type, boolean multi, boolean hide) {
    JFrame f = createSearchFrame();
    JFileChooser jf;
    jf = new JFileChooser(config.getExplorerPath());
    if (type.contains("d") || type.contains("D"))
        jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    else if (type.contains("f") || type.contains("F"))
        jf.setFileSelectionMode(JFileChooser.FILES_ONLY);
    else//w w w .  j a va 2  s.co  m
        jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    jf.setAcceptAllFileFilterUsed(false);
    jf.setMultiSelectionEnabled(multi);
    jf.setFileHidingEnabled(hide);
    int result = jf.showOpenDialog(f);
    f.dispose();

    if (result == JFileChooser.APPROVE_OPTION) {
        if (multi) {
            //--Save new filepath and files
            File[] files = jf.getSelectedFiles();
            String[] path = new String[files.length];
            for (int i = 0; i < files.length; i++) {
                path[i] = getCanonicalPath(files[i].getPath());
            }
            return path;
        } else {
            File file = jf.getSelectedFile();
            String[] path = new String[1];
            path[0] = getCanonicalPath(file.getPath());
            return path;
        }
    }
    String[] empty = new String[0];
    return empty;
}

From source file:com.jug.MotherMachine.java

/**
 * Shows a JFileChooser set up to accept the selection of folders.
 * If 'cancel' is pressed this method terminates the MotherMachine app.
 *
 * @param guiFrame//from www  .  ja  va 2s . c  o  m
 *            parent frame
 * @param path
 *            path to the folder to open initially
 * @return an instance of {@link File} pointing at the selected folder.
 */
private File showFolderChooser(final JFrame guiFrame, final String path) {
    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(path));
    chooser.setDialogTitle("Select folder containing image sequence...");
    chooser.setFileFilter(new FileFilter() {

        @Override
        public final boolean accept(final File file) {
            return file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "We only take directories";
        }
    });
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    } else {
        System.exit(0);
        return null;
    }
}

From source file:lu.fisch.moenagade.model.Project.java

public void openImage(Frame frame) {
    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(lastOpenedImage));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {
        @Override//from   ww w . ja v a  2s  .c  o m
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("png") || extension.equals("jpg") || extension.equals("jpeg")) {
                    return true;
                } else {
                    return false;
                }
            }

            return false;
        }

        @Override
        public String getDescription() {
            return "Supported image files (*.jpg, *.png)";
        }
    });
    int returnVal = fc.showDialog(frame, "Add image");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        loadImage(fc.getSelectedFile());
    }

}

From source file:lu.fisch.moenagade.model.Project.java

public void openSound(Frame frame) {
    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(lastOpenedSound));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {
        @Override// ww  w.j  a v  a 2  s .com
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("wav")) {
                    return true;
                } else {
                    return false;
                }
            }

            return false;
        }

        @Override
        public String getDescription() {
            return "Supported sound files (*.wav)";
        }
    });
    int returnVal = fc.showDialog(frame, "Add sound");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        loadSound(fc.getSelectedFile());
    }

}

From source file:org.fhaes.jsea.JSEAFrame.java

@Override
public void actionPerformed(ActionEvent event) {

    if (event.getActionCommand().equals("SegmentationMode")) {
        Boolean $success = this.validateDataFiles();

        if ($success == null) {
            log.debug("Files not set yet");
            return;
        } else if ($success == false) {
            log.debug("Invalid file ranges");
            return;
        }// w  w w  .  j a va2s .  com

        if (segmentationPanel.chkSegmentation.isSelected() && chronologyYears.size() > 1) {
            segmentationPanel.table.setEarliestYear(Integer.parseInt(this.firstPossibleYear.toString()));
            segmentationPanel.table.setLatestYear(Integer.parseInt(this.lastPossibleYear.toString()));
        } else {
            // cannot perform segmentation if there are less than 2 years in the chronology
            segmentationPanel.chkSegmentation.setSelected(false);
        }
    } else if (event.getActionCommand().equals("AllYearsCheckbox")) {
        setYearRangeGUI();
    } else if (event.getActionCommand().equals("TimeSeriesFileBrowse")) {
        String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER,
                App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null));
        JFileChooser fc;

        if (lastVisitedFolder != null) {
            fc = new JFileChooser(lastVisitedFolder);
        } else {
            fc = new JFileChooser();
        }

        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle("Open file");

        fc.addChoosableFileFilter(new TXTFileFilter());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileFilter(new CSVFileFilter());

        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            txtTimeSeriesFile.setText(fc.getSelectedFile().getAbsolutePath());
            txtwrapper.updatePref();

            App.prefs.setPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER, fc.getSelectedFile().getPath());

            if (parseTimeSeriesFile()) {
                setYearRangeGUI();
            } else {
                txtTimeSeriesFile.setText("");
            }

            validateForm();
        }
    } else if (event.getActionCommand().equals("EventListFileBrowse")) {
        String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER,
                App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null));
        JFileChooser fc;

        if (lastVisitedFolder != null) {
            fc = new JFileChooser(lastVisitedFolder);
        } else {
            fc = new JFileChooser();
        }

        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle("Open file");

        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            txtEventListFile.setText(fc.getSelectedFile().getAbsolutePath());
            App.prefs.setPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER, fc.getSelectedFile().getPath());
            parseEventListFile();

            validateForm();
        }
    }
}