Java JFileChooser Filter makeFileNameExtensionFilter(String[] extensions)

Here you can find the source of makeFileNameExtensionFilter(String[] extensions)

Description

make File Name Extension Filter

License

Open Source License

Declaration

public static FileNameExtensionFilter makeFileNameExtensionFilter(String[] extensions) 

Method Source Code

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

import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
    public static FileNameExtensionFilter makeFileNameExtensionFilter(String[] extensions) {
        if (extensions == null)
            return null;
        int numExtensions = 0;
        for (int ii = 0; ii < extensions.length; ++ii)
            if (extensions[ii] != null)
                numExtensions = numExtensions + 1;
        String[] nne = new String[numExtensions];
        int iext = 0;
        String extensionDesc = "";
        for (int ii = 0; ii < extensions.length; ++ii) {
            if (extensions[ii] != null) {
                nne[iext] = extensions[ii];
                if (iext == 0)
                    extensionDesc = extensionDesc + "*." + extensions[ii];
                if (iext > 0)
                    extensionDesc = extensionDesc + ", *." + extensions[ii];
                iext = iext + 1;// w  w  w.  ja  v a  2 s  .c  om
            }
        }
        if (numExtensions == 1)
            return new FileNameExtensionFilter(extensionDesc, nne[0]);
        if (numExtensions == 2)
            return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1]);
        if (numExtensions == 3)
            return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1], nne[2]);
        if (numExtensions >= 4)
            return new FileNameExtensionFilter(extensionDesc, nne[0], nne[1], nne[2], nne[3]);
        return null;
    }
}

Related

  1. getWavFileFilter()
  2. list(ArrayList list, File file, javax.swing.filechooser.FileFilter filter)
  3. listAll(File file, javax.swing.filechooser.FileFilter filter)
  4. listAll(File file, javax.swing.filechooser.FileFilter filter)
  5. makeFileFilter(final String desc, final String... types)
  6. newFileFilter(final String desc, final String[] allowed_extensions)
  7. validateFileName(final File file, final javax.swing.filechooser.FileFilter filter)
  8. wrapFilter(final javax.swing.filechooser.FileFilter filter)