Class JFileDataStoreChooser

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public class JFileDataStoreChooser
    extends JFileChooser
    A file chooser dialog to get user choices for data stores.

    Examples of use:

    
     // prompt the user for a shapefile
     File file = JFileDataStoreChooser.showOpenFile("shp", parentFrame);
     if (file != null) {
        ...
     }
    
     // prompt the user for a given data format
    
     
    Since:
    2.6
    Author:
    Jody Garnett
    See Also:
    Serialized Form
    • Constructor Detail

      • JFileDataStoreChooser

        public JFileDataStoreChooser​(String extension)
        Create a dialog that filters for files with the specified extension.
        Parameters:
        extension - the file extension, with or without the leading '.'
      • JFileDataStoreChooser

        public JFileDataStoreChooser​(List<String> extensions)
        Create a dialog that filters for files with the specified extensions.
        Parameters:
        extensions - the file extensions, with or without the leading '.'
      • JFileDataStoreChooser

        public JFileDataStoreChooser​(String[] extensions)
        Create a dialog that filters for files with the specified extensions.
        Parameters:
        extensions - the file extensions, with or without the leading '.'
      • JFileDataStoreChooser

        public JFileDataStoreChooser​(Map<String,​String> fileAssociations)
        Creates a dialog based on the given file associations.
        
         Map<String, String> assoc = new HashMap<>();
         assoc.put(".foo", "Foo data files (*.foo)");
         assoc.put(".bar", "Bar data files (*.bar)");
         JFileDataStoreChooser chooser = new JFileDataStoreChooser(assoc);
         
        Parameters:
        fileAssociations - a Map where keys are extensions (with or wirhout the leading dot) and values are descriptions.
      • JFileDataStoreChooser

        public JFileDataStoreChooser​(FileDataStoreFactorySpi format)
        Creates a dialog that filters for files matching the specified data format.
        Parameters:
        format - data file format
    • Method Detail

      • showOpenFile

        public static File showOpenFile​(String extension,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files with the given extension.
        Parameters:
        extension - file extension, with or without leading '.'
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • showOpenFile

        public static File showOpenFile​(String extension,
                                        File initialDir,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files with the given extension.
        Parameters:
        extension - file extension, with or without leading '.'
        initialDir - initial directory to display; if null the initial directory will be the user's default directory
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • showOpenFile

        public static File showOpenFile​(String[] extensions,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files with the given extensions.
        Parameters:
        extensions - array of file extension, with or without leading '.'
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • showOpenFile

        public static File showOpenFile​(String[] extensions,
                                        File initialDir,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files with the given extensions.
        Parameters:
        extensions - array of file extension, with or without leading '.'
        initialDir - initial directory to display; if null the initial directory will be the user's default directory
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • showOpenFile

        public static File showOpenFile​(FileDataStoreFactorySpi format,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files that match a given file data store format
        Parameters:
        format - the file data store format
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • showOpenFile

        public static File showOpenFile​(FileDataStoreFactorySpi format,
                                        File initialDir,
                                        Component parent)
                                 throws HeadlessException
        Show a file open dialog that filters for files that match a given file data store format
        Parameters:
        format - the file data store format
        initialDir - initial directory to display; if null the initial directory will be the user's default directory
        parent - parent GUI component (may be null)
        Returns:
        the selected file or null if the user cancelled the selection
        Throws:
        HeadlessException - if run in an unsupported environment
      • main

        public static void main​(String[] arg)
        Demonstrates the file data store dialog by prompting for a shapefile
        Parameters:
        arg - ignored
      • setSaveFile

        public void setSaveFile​(File file)
        Consider the provided file as a candidate for a new filename. A number will be appended to the filename if there is a conflict.
        Parameters:
        file - the candidate file name