Class FileFilterExtensions

  • All Implemented Interfaces:
    INameFilter

    public final class FileFilterExtensions
    extends javax.swing.filechooser.FileFilter
    implements INameFilter

    Configureable implementation of FileFilter that filters files by their extension (e.g.: ".txt").

    The extension Strings are provided to the constructor (no configuration of initialized instance provided yet) and have to be the sole extension without the dot.

    This class is most often used to configure JFileChooser dialogs. Therefore it accepts all directories to allow browsing.

    Example usage:

    ... JFileChooser fileChooser = new JFileChooser(); FileFilter soundFileFilter = new FileFilterExtensions(new String[]{"wav","mp3"}); fileChooser.setFileFilter(soundFileFilter); ...

    Author:
      • Constructor Summary

        Constructors 
        Constructor Description
        FileFilterExtensions​(java.lang.String[] extensionsWithoutDot)
        Creates an instance that will accept files with the given extensions.
      • Method Summary

        All Methods Instance Methods Concrete Methods 
        Modifier and Type Method Description
        boolean accept​(java.io.File pathname)  
        boolean accept​(java.lang.String urlstring)
        Accept the file denoted by the given url String.
        java.lang.String getDescription()  
        • Methods inherited from class java.lang.Object

          clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileFilterExtensions

        public FileFilterExtensions​(java.lang.String[] extensionsWithoutDot)
                             throws java.lang.IllegalArgumentException
        Creates an instance that will accept files with the given extensions.

        Parameters:
        extensionsWithoutDot - A String[] containing extension strings without the dot like: new String[]{"bat","txt","dict"} .
        Throws:
        java.lang.IllegalArgumentException - if the given extensions are inivalid.
    • Method Detail

      • accept

        public boolean accept​(java.io.File pathname)
        Specified by:
        accept in class javax.swing.filechooser.FileFilter
        See Also:
        FileFilter.accept(java.io.File)
      • accept

        public boolean accept​(java.lang.String urlstring)
        Description copied from interface: INameFilter
        Accept the file denoted by the given url String.

        Specified by:
        accept in interface INameFilter
        Parameters:
        urlstring - a String in url format denoting a file.
        Returns:
        true if the file denoted by the given url String is accepted.
        See Also:
        INameFilter.accept(String)
      • getDescription

        public java.lang.String getDescription()
        Specified by:
        getDescription in class javax.swing.filechooser.FileFilter
        See Also:
        FileFilter.getDescription()