Java JFileChooser Filter createFileFilter(final String ext, final String desc)

Here you can find the source of createFileFilter(final String ext, final String desc)

Description

create File Filter

License

Open Source License

Declaration

public static FileFilter createFileFilter(final String ext, final String desc) 

Method Source Code

//package com.java2s;
/*// ww w  .ja va  2 s.c om
 * Copyright 2011 Christian Thiemann <christian@spato.net>
 * Developed at Northwestern University <http://rocs.northwestern.edu>
 *
 * This file is part of the SPaTo Visual Explorer (SPaTo).
 *
 * SPaTo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SPaTo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SPaTo.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class Main {
    public static FileFilter createFileFilter(final String ext, final String desc) {
        return createFileFilter(new String[] { ext }, desc);
    }

    public static FileFilter createFileFilter(final String exts[], final String desc) {
        return new FileFilter() {
            public String getDescription() {
                return desc;
            }

            public boolean accept(File f) {
                if (f.isDirectory())
                    return false;
                for (String ext : exts)
                    if (f.getName().endsWith("." + ext))
                        return true;
                return false;
            }
        };
    }
}

Related

  1. accept(File f, Collection filters)
  2. completeFileExtension(File file, FileFilter filter)
  3. createFileFilter(final String description, final String[] extensions)
  4. createFileFilter(final String description, String extension)
  5. createFileFilter(final String filter)
  6. createFileFilter(final String filterName, final String... extensionPatterns)
  7. createFileFilter(String text, String[]... suffixes)
  8. fileEndsInValidExtension(File file, FileNameExtensionFilter filter)