Class FileManager

java.lang.Object
ucar.unidata.util.FileManager
Direct Known Subclasses:
FileManager

public class FileManager extends Object
Wrapper cover for JFileChooser.
Version:
$Id: FileManager.java,v 1.22 2007/08/13 18:38:39 jeffmc Exp $
Author:
Unidata development staff
  • Field Details

  • Constructor Details

    • FileManager

      public FileManager(Component parent)
      Create a FileManager and use parent as the parent for the dialog.
      Parameters:
      parent - parent component for the dialog.
    • FileManager

      public FileManager(Component parent, String defDir, String file_extension, String desc)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      file_extension - file_extention to use for a filter
      desc - description of files of type file_extension
    • FileManager

      public FileManager(Component parent, String defDir, FileFilter filter)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      filter - default FileFilter
    • FileManager

      public FileManager(Component parent, String defDir, FileFilter filter, String title)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      filter - default FileFilter
      title - title for the dialog window
    • FileManager

      public FileManager(Component parent, String defDir, List filters)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      filters - List of default FileFilter's
    • FileManager

      public FileManager(Component parent, String defDir, List filters, String title)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      filters - List of default FileFilter's
      title - title for the dialog window
    • FileManager

      public FileManager(Component parent, String defDir, List filters, String title, boolean includeAllFilter)
      Create a FileManager and use the specified params to configure its behavior.
      Parameters:
      parent - parent component for the dialog.
      defDir - default directory to open up
      filters - List of default FileFilter's
      title - title for the dialog window
      includeAllFilter - true to include the "All files" filter.
  • Method Details

    • getChooser

      public JFileChooser getChooser()
      Get the chooser that this FileManager wraps.
      Returns:
      the chooser
    • setFixFileLockup

      public static void setFixFileLockup(boolean b)
      Do we set the FileChooser.useShellFolder=false This fixes the occasional problemo of a system lockup running under windows
      Parameters:
      b - value
    • getFileHidingEnabled

      public static boolean getFileHidingEnabled()
      _more_
      Returns:
      _more_
    • setFileHidingEnabled

      public static void setFileHidingEnabled(boolean value)
      _more_
      Parameters:
      value - _more_
    • setSelectedFile

      public void setSelectedFile(String file)
      Set the selected file for the chooser.
      Parameters:
      file - name of the file
    • chooseFilename

      public String chooseFilename()
      Choose a filename.
      Returns:
      name of the file.
    • chooseFilename

      public String chooseFilename(String title)
      Choose a filename and set the title in the dialog.
      Parameters:
      title - for dialog
      Returns:
      name of the file.
    • chooseFilename

      public String chooseFilename(String title, String approveButtonText)
      Choose a filename, set the title in the dialog, and set the text of the approve button on the chooser.
      Parameters:
      title - title for the dialog window
      approveButtonText - text for the approve button in the dialog
      Returns:
      name of the file.
    • chooseFilename

      public String chooseFilename(String title, String approveButtonText, boolean includeUrl)
      Choose a filename, set the title in the dialog, and set the text of the approve button on the chooser.
      Parameters:
      title - title for the dialog window
      approveButtonText - text for the approve button in the dialog
      includeUrl - inclues a URL
      Returns:
      name of the file.
    • getHistoryList

      public static List getHistoryList(ActionListener listener)
      Get the history list. Add the listener to the list of listeners.
      Parameters:
      listener - Listener to notify
      Returns:
      List of (String) directories from the user's past use
    • getHistoryList

      public static List getHistoryList()
      Get the history list.
      Returns:
      List of (String) directories from the user's past use
    • addToHistory

      public static void addToHistory(File file)
      Add the file (or its parent directory if it is not a directory) to the history list.
      Parameters:
      file - File to add
    • setAccessory

      public void setAccessory(JComponent comp)
      Set the accessory for the file chooser to comp.
      Parameters:
      comp - component to use for the accessory.
    • getDirectoryName

      public String getDirectoryName()
      Get the current directory name.
      Returns:
      name of the current directory.
    • setApproveButtonText

      public void setApproveButtonText(String approveButtonText)
      Set the approve button text for the chooser.
      Parameters:
      approveButtonText - text for the button.
    • setStore

      public static void setStore(PersistentStore store, String writeProperty, String readProperty)
      Set the persistent store for this FileManager.
      Parameters:
      store - store for persistence
      writeProperty - write property
      readProperty - read property
    • getDirectory

      public static File getDirectory(String dfltDir)
      Return a directory selection.
      Parameters:
      dfltDir -
      Returns:
      A directory or nulll if none selected.
    • getDirectory

      public static File getDirectory(String dfltDir, String title)
      Have the user select a directory
      Parameters:
      dfltDir - Default dir
      title - Window title
      Returns:
      The selected directory or null if none selected
    • getDirectory

      public static File getDirectory(String dfltDir, String title, JComponent accessory)
      _more_
      Parameters:
      dfltDir - _more_
      title - _more_
      accessory - _more_
      Returns:
      _more_
    • getWriteFile

      public static String getWriteFile(String filename)
      Get the file that this FileManager will write to using the defaults.
      Parameters:
      filename - default file name
      Returns:
      the requested file name
    • getWriteFile

      public static String getWriteFile()
      Get the file that this FileManager will write to using the defaults.
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(List filters, String suffix)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      filters - List of file filters
      suffix - default suffix
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(FileFilter filter, String suffix)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      filter - file filter
      suffix - default suffix
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(FileFilter filter, String suffix, JComponent accessory)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      filter - file filter
      suffix - default suffix
      accessory - accessory component
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(List filters, String suffix, JComponent accessory)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      filters - file filters
      suffix - default suffix
      accessory - accessory component
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(String title, FileFilter filter, String suffix)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      title - title for the dialog.
      filter - file filter
      suffix - default suffix
      Returns:
      name of the file
    • getWriteFile

      public static String getWriteFile(String title, List filters, String suffix)
      Get the file that this FileManager will write to using the specified parameters.
      Parameters:
      title - title for the dialog.
      filters - List of file filters
      suffix - default suffix
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile()
      Get the file that this FileManager will read from using the defaults.
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile(FileFilter filter)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      filter - filter to use
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile(FileFilter filter, boolean includeAllFilter)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      filter - filter to use
      includeAllFilter - true to include the "All files (*.*)" filter
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile(String title, FileFilter filter)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      title - title for the dialog
      filter - filter to use
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile(String title, List filters)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      title - title for the dialog
      filters - List of filters to use
      Returns:
      name of the file
    • getReadFile

      public static String getReadFile(String title, List filters, JComponent accessory)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      title - title for the dialog
      filters - List of filters to use
      accessory - accessory for the chooser (may be null)
      Returns:
      name of the file
    • getReadFileOrURL

      public static String getReadFileOrURL(String title, List filters, JComponent accessory)
      Get the file that this FileManager will read from using the specified parameters to configure the widget.
      Parameters:
      title - title for the dialog
      filters - List of filters to use
      accessory - accessory for the chooser (may be null)
      Returns:
      name of the file
    • getFile

      public static String getFile(boolean forWrite, String title, String buttonText, String property, List filters, String suffix, boolean includeAllFilter, JComponent accessory, boolean includeUrl)
      Get the file that this FileManager is pointing to.
      Parameters:
      forWrite - true if this is for getting a file to write to
      title - title for the dialog
      buttonText - text for the approve button
      property - property for the store
      filters - List of filters to use
      suffix - default suffix for file to write
      includeAllFilter - true to include the "All files (*.*)" filter
      accessory - accessory for the chooser
      includeUrl - allow a URL
      Returns:
      name of the file
    • getFile

      public static String getFile(boolean forWrite, String title, String buttonText, String property, List filters, String suffix, boolean includeAllFilter, JComponent accessory, boolean includeUrl, String dfltFile)
      Get the file that this FileManager is pointing to.
      Parameters:
      forWrite - true if this is for getting a file to write to
      title - title for the dialog
      buttonText - text for the approve button
      property - property for the store
      filters - List of filters to use
      suffix - default suffix for file to write
      includeAllFilter - true to include the "All files (*.*)" filter
      accessory - accessory for the chooser
      includeUrl - allow a URL
      dfltFile - the default file
      Returns:
      name of the file
    • makeDirectoryHistoryComponent

      public static JComponent makeDirectoryHistoryComponent(JFileChooser fileChooser, boolean includeLabel)
      Create the directory history button and menu
      Parameters:
      fileChooser - The chooser to set the dir on
      includeLabel - Should the label be included in the component.
      Returns:
      The jbutton and label that pops up the directory history list