Package ptolemy.gui

Class ExtensionFilenameFilter

  • All Implemented Interfaces:
    java.io.FilenameFilter

    public class ExtensionFilenameFilter
    extends PtFilenameFilter
    An implementation of both javax.swing.filechooser.FileFilter and java.io.FilenameFilter that only accepts files that have one of the registered extensions.

    This class is provided in Ptolemy II to support usage with both java.awt.FileDialog and javax.swing.JFileChooser. As it appears that on MacOSX the FileDialog implementation is better than the JFileChooser, Ptolemy II has some logic in ptolemy.gui.PtGUIUtilities.useFileDialog() to decide which "file-picker"-component to use. Several Ptolemy II classes use this utility while still passing a common filter instance to the selected component. (e.g. ptolemy.gui.Query, ptolemy.gui.Top ...)

    The javax.swing.filechooser.FileNameExtensionFilter in the JDK can only be used with JFileChooser.

    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Erwin De Ley
    • Constructor Summary

      Constructors 
      Constructor Description
      ExtensionFilenameFilter​(java.lang.String[] extensions)
      Construct a file filter that filters out all files that do not have one of the extensions in the given list.
      ExtensionFilenameFilter​(java.lang.String[] extensions, java.lang.String description)
      Creates a filter that accepts the given file type, specified by a number of extensions and a meaningful description of the file types involved.
      ExtensionFilenameFilter​(java.lang.String description, java.lang.String... extensions)
      Creates a filter that accepts the given file type, specified by a number of extensions and a meaningful description of the file types involved.
      ExtensionFilenameFilter​(java.util.List<java.lang.String> extensions)
      Construct a file filter that filters out all files that do not have one of the extensions in the given list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(java.io.File file)
      Return true if the given file has one of the registered extensions, or is a directory.
      boolean accept​(java.io.File directory, java.lang.String name)
      Return true if the given file name has one of the registered extensions, or is a directory.
      java.lang.String getDescription()
      A description of this FilenameFilter.
      protected void registerExtension​(java.lang.String extension)
      Register an additional extension to accept.
      void setDescription​(java.lang.String description)
      Set the human readable description of the types of files accepted by this filter.
      java.lang.String toString()
      Get the description and the registered extensions.
      • Methods inherited from class java.lang.Object

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

      • ExtensionFilenameFilter

        public ExtensionFilenameFilter​(java.util.List<java.lang.String> extensions)
        Construct a file filter that filters out all files that do not have one of the extensions in the given list.
        Parameters:
        extensions - the file extensions to use
      • ExtensionFilenameFilter

        public ExtensionFilenameFilter​(java.lang.String[] extensions)
        Construct a file filter that filters out all files that do not have one of the extensions in the given list.
        Parameters:
        extensions - the file extensions to use
      • ExtensionFilenameFilter

        public ExtensionFilenameFilter​(java.lang.String description,
                                       java.lang.String... extensions)
        Creates a filter that accepts the given file type, specified by a number of extensions and a meaningful description of the file types involved.
        Parameters:
        description - a description of the types of files with one of the given extensions.
        extensions - the file extensions to use
      • ExtensionFilenameFilter

        public ExtensionFilenameFilter​(java.lang.String[] extensions,
                                       java.lang.String description)
        Creates a filter that accepts the given file type, specified by a number of extensions and a meaningful description of the file types involved.
        Parameters:
        extensions - the file extensions to use
        description - a description of the types of files with one of the given extensions
    • Method Detail

      • accept

        public boolean accept​(java.io.File file)
        Return true if the given file has one of the registered extensions, or is a directory. Otherwise, or if the file is null, return false.

        Files whose name begins with "." are not accepted.

        Overrides:
        accept in class PtFilenameFilter
        Parameters:
        file - The file to be checked.
        Returns:
        true if the given file has one of the registered extensions, or is a directory.
      • accept

        public boolean accept​(java.io.File directory,
                              java.lang.String name)
        Return true if the given file name has one of the registered extensions, or is a directory. Otherwise, or if the directory or name is null, return false.

        Files whose name begins with "." are not accepted.

        Specified by:
        accept in interface java.io.FilenameFilter
        Overrides:
        accept in class PtFilenameFilter
        Parameters:
        directory - the parent directory of the file
        name - the name of the file.
        Returns:
        true if the given file has one of the registered extensions, or is a directory.
      • setDescription

        public void setDescription​(java.lang.String description)
        Set the human readable description of the types of files accepted by this filter.
        Parameters:
        description - the human readable description of the types of files accepted by this filter.
        See Also:
        getDescription()
      • toString

        public java.lang.String toString()
        Get the description and the registered extensions.
        Overrides:
        toString in class java.lang.Object
        Returns:
        description + registered extensions
      • registerExtension

        protected void registerExtension​(java.lang.String extension)
        Register an additional extension to accept.
        Parameters:
        extension - The extension to be added.