Class NativeFileDialog



  • public class NativeFileDialog
    extends java.lang.Object
    Bindings to Native File Dialog, a tiny, neat C library that portably invokes native file open and save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms.

    Usage

    File Filter Syntax

    There is a form of file filtering in every file dialog, but no consistent means of supporting it. NFD provides support for filtering files by groups of extensions, providing its own descriptions (where applicable) for the extensions.

    A wildcard filter is always added to every dialog.

    Separators:

    • ; Begin a new filter.
    • , Add a separate type to the filter.

    Examples:

    • txt The default filter is for text files. There is a wildcard option in a dropdown.
    • png,jpg;psd The default filter is for png and jpg files. A second filter is available for psd files. There is a wildcard option in a dropdown.
    • NULL Wildcard only.

    Known Limitations

    • No support for Windows XP's legacy dialogs such as GetOpenFileName.
    • No support for file filter names -- ex: "Image Files" (*.png, *.jpg). Nameless filters are supported, though.
    • No support for selecting folders instead of files.
    • On Linux, GTK+ cannot be uninitialized to save memory. Launching a file dialog costs memory.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int NFD_CANCEL
      User pressed cancel.
      static int NFD_ERROR
      Programmatic error.
      static int NFD_OKAY
      User pressed okay, or successful return.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void NFD_Free(java.nio.ByteBuffer outPath)
      Frees memory allocated by NativeFileDialog.
      static java.lang.String NFD_GetError()
      Returns the last error.
      static int NFD_OpenDialog(java.nio.ByteBuffer filterList, java.nio.ByteBuffer defaultPath, PointerBuffer outPath)
      Launches a single file open dialog.
      static int NFD_OpenDialog(java.lang.CharSequence filterList, java.lang.CharSequence defaultPath, PointerBuffer outPath)
      Launches a single file open dialog.
      static int NFD_OpenDialogMultiple(java.nio.ByteBuffer filterList, java.nio.ByteBuffer defaultPath, NFDPathSet outPaths)
      Launches a multiple file open dialog.
      static int NFD_OpenDialogMultiple(java.lang.CharSequence filterList, java.lang.CharSequence defaultPath, NFDPathSet outPaths)
      Launches a multiple file open dialog.
      static void NFD_PathSet_Free(NFDPathSet pathSet)
      Frees the contents of the specified path set.
      static long NFD_PathSet_GetCount(NFDPathSet pathSet)
      Returns the number of entries stored in pathSet.
      static java.lang.String NFD_PathSet_GetPath(NFDPathSet pathSet, long index)
      Returns the UTF-8 path at offset index.
      static int NFD_SaveDialog(java.nio.ByteBuffer filterList, java.nio.ByteBuffer defaultPath, PointerBuffer outPath)
      Launches a save dialog.
      static int NFD_SaveDialog(java.lang.CharSequence filterList, java.lang.CharSequence defaultPath, PointerBuffer outPath)
      Launches a save dialog.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • NFD_OpenDialog

        public static int NFD_OpenDialog(java.nio.ByteBuffer filterList,
                                         java.nio.ByteBuffer defaultPath,
                                         PointerBuffer outPath)
        Launches a single file open dialog.

        If OKAY is returned, outPath will contain a pointer to a UTF-8 encoded string. The user must free the string with Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPath - returns the selected file path
      • NFD_OpenDialog

        public static int NFD_OpenDialog(java.lang.CharSequence filterList,
                                         java.lang.CharSequence defaultPath,
                                         PointerBuffer outPath)
        Launches a single file open dialog.

        If OKAY is returned, outPath will contain a pointer to a UTF-8 encoded string. The user must free the string with Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPath - returns the selected file path
      • NFD_OpenDialogMultiple

        public static int NFD_OpenDialogMultiple(java.nio.ByteBuffer filterList,
                                                 java.nio.ByteBuffer defaultPath,
                                                 NFDPathSet outPaths)
        Launches a multiple file open dialog.

        If OKAY is returned, outPaths will be filled with information about the selected file or files. The user must free that information with PathSet_Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPaths - a path set that will be filled with the selected files
      • NFD_OpenDialogMultiple

        public static int NFD_OpenDialogMultiple(java.lang.CharSequence filterList,
                                                 java.lang.CharSequence defaultPath,
                                                 NFDPathSet outPaths)
        Launches a multiple file open dialog.

        If OKAY is returned, outPaths will be filled with information about the selected file or files. The user must free that information with PathSet_Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPaths - a path set that will be filled with the selected files
      • NFD_SaveDialog

        public static int NFD_SaveDialog(java.nio.ByteBuffer filterList,
                                         java.nio.ByteBuffer defaultPath,
                                         PointerBuffer outPath)
        Launches a save dialog.

        If OKAY is returned, outPath will contain a pointer to a UTF-8 encoded string. The user must free the string with Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPath - returns the selected file path
      • NFD_SaveDialog

        public static int NFD_SaveDialog(java.lang.CharSequence filterList,
                                         java.lang.CharSequence defaultPath,
                                         PointerBuffer outPath)
        Launches a save dialog.

        If OKAY is returned, outPath will contain a pointer to a UTF-8 encoded string. The user must free the string with Free when it is no longer needed.

        Parameters:
        filterList - an optional filter list
        defaultPath - an optional default path
        outPath - returns the selected file path
      • NFD_GetError

        public static java.lang.String NFD_GetError()
        Returns the last error.
      • NFD_PathSet_GetCount

        public static long NFD_PathSet_GetCount(NFDPathSet pathSet)
        Returns the number of entries stored in pathSet.
        Parameters:
        pathSet - the path set to query
      • NFD_PathSet_GetPath

        public static java.lang.String NFD_PathSet_GetPath(NFDPathSet pathSet,
                                                           long index)
        Returns the UTF-8 path at offset index.
        Parameters:
        pathSet - the path set to query
        index - the path offset
      • NFD_PathSet_Free

        public static void NFD_PathSet_Free(NFDPathSet pathSet)
        Frees the contents of the specified path set.
        Parameters:
        pathSet - the path set
      • NFD_Free

        public static void NFD_Free(java.nio.ByteBuffer outPath)
        Frees memory allocated by NativeFileDialog.
        Parameters:
        outPath - the string to free