Example usage for javax.swing.filechooser FileFilter FileFilter

List of usage examples for javax.swing.filechooser FileFilter FileFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileFilter FileFilter.

Prototype

FileFilter

Source Link

Usage

From source file:org.eclim.installer.step.VimStep.java

/**
 * {@inheritDoc}/*from w  w  w . jav a 2 s .  c o  m*/
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    GuiForm form = createForm();

    String files = fieldName("files");
    fileChooser = new FileChooser(JFileChooser.DIRECTORIES_ONLY);

    // allow just .vim dirs to not be hidden
    fileChooser.getFileChooser().setFileHidingEnabled(false);
    fileChooser.getFileChooser().addChoosableFileFilter(new FileFilter() {
        public boolean accept(java.io.File f) {
            String path = f.getAbsolutePath();
            return f.isDirectory() && (path.matches(".*/\\.vim(/.*|$)") || !path.matches(".*/\\..*"));
        }

        public String getDescription() {
            return null;
        }
    });

    String skip = fieldName("skip");
    skipCheckBox = new JCheckBox(Installer.getString(skip));
    skipCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean selected = ((JCheckBox) e.getSource()).isSelected();
            JTextField fileField = fileChooser.getTextField();
            fileField.setEnabled(!selected);
            fileChooser.getButton().setEnabled(!selected);

            if (dirList != null) {
                dirList.setEnabled(!selected);
            }

            // hacky
            Validator validator = (Validator) fileField.getClientProperty("validator");
            setValid(selected || validator.isValid(fileField.getText()));
        }
    });

    panel = new JPanel(new MigLayout("wrap 2", "[fill]", "[] [] [] [fill, grow]"));
    panel.add(form.createMessagePanel(), "span");
    panel.add(new JLabel(Installer.getString(files)), "split");
    panel.add(fileChooser, "skip");
    panel.add(skipCheckBox, "span");

    form.bind(files, fileChooser.getTextField(),
            new ValidatorBuilder().required().isDirectory().fileExists().isWritable().validator());

    return panel;
}

From source file:org.iobserve.mobile.instrument.start.InstrumenterTest.java

/**
 * Executes the instrumentation./* w  w w.j a  v  a2s  . c om*/
 * 
 * @param argv
 *            not needed
 * @throws KeyStoreException
 *             caused by the instrumentation
 * @throws NoSuchAlgorithmException
 *             caused by the instrumentation
 * @throws CertificateException
 *             caused by the instrumentation
 * @throws IOException
 *             caused by the instrumentation
 * @throws ZipException
 *             caused by the instrumentation
 * @throws URISyntaxException
 *             caused by the instrumentation
 */
public static void main(final String[] argv) throws KeyStoreException, NoSuchAlgorithmException,
        CertificateException, IOException, ZipException, URISyntaxException {
    final File toInstrument;
    if (SELECTAPK) {
        final JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(new FileFilter() {
            @Override
            public String getDescription() {
                return null;
            }

            @Override
            public boolean accept(final File f) {
                if (f.isDirectory()) {
                    return true;
                }

                if (FilenameUtils.getExtension(f.getAbsolutePath()).equals("apk")) {
                    return true;
                }
                return false;
            }
        });
        fc.setAcceptAllFileFilterUsed(false);
        final int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            toInstrument = fc.getSelectedFile();
        } else {
            return;
        }
    } else {
        toInstrument = new File("app-debug.apk");
    }

    if (toInstrument.exists()) {
        final APKInstrumenter instr = new APKInstrumenter(true, new File("lib/release.keystore"),
                "androiddebugkey", "android");
        instr.instrumentAPK(toInstrument, new File("instr-output.apk"));
    } else {
        System.err.println("APK doesn't exist.");
    }
}

From source file:org.jcurl.core.jnlp.FileDialogSwing.java

private static JFileChooser createFileChooser(final String pathHint, final String[] extensions,
        final boolean showDir) {
    final JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);//from w  w w .  j  av  a  2 s  . c  o  m
    fc.setAcceptAllFileFilterUsed(true);
    fc.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(final File f) {
            if (f == null)
                return false;
            if (showDir && f.isDirectory())
                return true;
            for (final String element : extensions)
                if (f.getName().endsWith("." + element))
                    return true;
            return false;
        }

        @Override
        public String getDescription() {
            final StringBuilder b = new StringBuilder();
            for (final String element : extensions)
                b.append("*.").append(element).append(", ");
            if (b.length() > 0)
                b.setLength(b.length() - 2);
            return b.toString();
        }
    });
    return fc;
}

From source file:org.jtrfp.trcl.gui.ConfigWindow.java

private void addPOD() {
    fileChooser.setFileFilter(new FileFilter() {
        @Override//ww w .ja v a2s.c  om
        public boolean accept(File file) {
            return file.getName().toUpperCase().endsWith(".POD") || file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "Terminal Reality .POD files";
        }
    });
    if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
        return;
    final File file = fileChooser.getSelectedFile();
    if (!checkPOD(file))
        return;
    podLM.addElement(file.getAbsolutePath());
}

From source file:org.jtrfp.trcl.gui.ConfigWindow.java

private void addVOX() {
    fileChooser.setFileFilter(new FileFilter() {
        @Override/*from   w w w.  j  av a 2  s  . c o m*/
        public boolean accept(File file) {
            return file.getName().toUpperCase().endsWith(".VOX") || file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "Terminal Reality .POD files";
        }
    });
    if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
        return;
    final File file = fileChooser.getSelectedFile();
    if (file != null)
        missionLM.addElement(file.getAbsolutePath());
}

From source file:org.jtrfp.trcl.gui.ConfigWindow.java

private void exportSettings() {
    fileChooser.setFileFilter(new FileFilter() {
        @Override/*from   w  ww.ja  v a  2s. c  o m*/
        public boolean accept(File file) {
            return file.getName().toLowerCase().endsWith(".config.trcl.xml") || file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "Terminal Recall Config Files";
        }
    });
    fileChooser.showSaveDialog(this);
    File f = fileChooser.getSelectedFile();
    if (f == null)
        return;
    writeSettingsTo(f);
}

From source file:org.jtrfp.trcl.gui.ConfigWindow.java

private void importSettings() {
    fileChooser.setFileFilter(new FileFilter() {
        @Override/*ww  w .  ja va2s  . c o  m*/
        public boolean accept(File file) {
            return file.getName().toLowerCase().endsWith(".config.trcl.xml") || file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "Terminal Recall Config Files";
        }
    });
    fileChooser.showOpenDialog(this);
    File f = fileChooser.getSelectedFile();
    if (f == null)
        return;
    readSettingsFromFile(f);
    readSettingsToPanel();
}

From source file:org.kuali.test.ui.components.panels.FileTestPanel.java

/**
 *
 * @param e/* ww  w  .ja va 2 s.com*/
 */
@Override
protected void handleUnprocessedActionEvent(ActionEvent e) {
    if (Constants.FILE_SEARCH_ACTION.equals(e.getActionCommand())) {
        Preferences proot = Preferences.userRoot();
        Preferences node = proot.node(Constants.PREFS_FILES_NODE);

        String lastDir = node.get(Constants.PREFS_LAST_FILE_TEST_DIR, System.getProperty("user.home"));

        JFileChooser chooser = new JFileChooser(lastDir);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return (f.isDirectory() && f.exists());
            }

            @Override
            public String getDescription() {
                return "file inquiry directory";
            }
        });

        int returnVal = chooser.showOpenDialog(getMainframe());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = chooser.getSelectedFile();
            fileDirectory.setText(f.getPath());
            node.put(Constants.PREFS_LAST_FILE_TEST_DIR, f.getPath());
        }
    } else if (Constants.FILE_EXISTS.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_DOES_NOT_EXIST).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(true);
        containingText.setEnabled(true);
    } else if (Constants.FILE_DOES_NOT_EXIST.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_EXISTS).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(false);
        containingText.setText("");
        containingText.setEnabled(false);
    } else if (Constants.FILE_CREATED_TODAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
    } else if (Constants.FILE_CREATED_YESTERDAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
    }
}

From source file:org.lnicholls.galleon.apps.iTunes.iTunesOptionsPanel.java

public void actionPerformed(ActionEvent e) {

    if ("pick".equals(e.getActionCommand())) {

        final JFileChooser fc = new JFileChooser();

        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        fc.addChoosableFileFilter(new FileFilter() {

            public boolean accept(File f) {

                if (f.isDirectory()) {

                    return true;

                } else if (f.isFile() && f.getName().toLowerCase().endsWith("xml")) {

                    return true;

                }//w  ww  . j a  v  a 2s  .  co m

                return false;

            }

            //The description of this filter

            public String getDescription() {

                return "Playlist Library";

            }

        });

        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {

            File file = fc.getSelectedFile();

            mPlaylistPathField.setText(file.getAbsolutePath());

        }

    }

}

From source file:org.martin.ftp.gui.GUIClient.java

private FileFilter getDirectoryFilter() {

    return new FileFilter() {
        @Override/*from w  ww  .  j av  a  2  s.c om*/
        public boolean accept(File f) {
            return f.isDirectory();
        }

        @Override
        public String getDescription() {
            return "Solo directorios";
        }
    };
}