Java JFileChooser Filter createFileFilter(String text, String[]... suffixes)

Here you can find the source of createFileFilter(String text, String[]... suffixes)

Description

create File Filter

License

Open Source License

Declaration

public static FileNameExtensionFilter createFileFilter(String text, String[]... suffixes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.SortedSet;
import java.util.TreeSet;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
    public static FileNameExtensionFilter createFileFilter(String text, String[]... suffixes) {
        SortedSet<String> sortedSuffixes = new TreeSet<>();
        if (suffixes != null) {
            for (String[] a : suffixes) {
                if (a != null) {
                    for (String s : a) {
                        if (s != null) {
                            sortedSuffixes.add(s.toLowerCase());
                        }//  w ww .  j  a  v  a2s.  co m
                    }
                }
            }
        }
        if (!sortedSuffixes.isEmpty()) {
            StringBuilder buf = new StringBuilder(256);
            buf.append(text);
            boolean isFirst = true;
            for (String s : sortedSuffixes) {
                if (isFirst) {
                    buf.append(" (");
                    isFirst = false;
                } else {
                    buf.append("; ");
                }
                buf.append("*.");
                buf.append(s);
            }
            if (!isFirst) {
                buf.append((char) ')');
            }
            text = buf.toString();
        }
        return new FileNameExtensionFilter(text, sortedSuffixes.toArray(new String[sortedSuffixes.size()]));
    }
}

Related

  1. createFileFilter(final String description, final String[] extensions)
  2. createFileFilter(final String description, String extension)
  3. createFileFilter(final String ext, final String desc)
  4. createFileFilter(final String filter)
  5. createFileFilter(final String filterName, final String... extensionPatterns)
  6. fileEndsInValidExtension(File file, FileNameExtensionFilter filter)
  7. fileNameAutoExtend(FileFilter filter, File file)
  8. getBinaryFileFilter()
  9. getCustomFileFilter(String desc, String[] validExtensions)