ucar.unidata.util
Class FileManager

java.lang.Object
  extended by 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

Nested Class Summary
static class FileManager.ExtFilter
          A FileFilter extension that allows specifiying an extension and description.
static class FileManager.MyFileChooser
          Have our own class here so it can put the hook in to fix the lock up problem on windows.
static class FileManager.NetcdfExtFilter
          A FileFilter extension for netCDF files.
 
Field Summary
static PatternFileFilter FILTER_ANIMATEDGIF
          Filter for QuickTime files
static PatternFileFilter FILTER_AVI
          Filter for QuickTime files
static PatternFileFilter FILTER_CSV
          Filter for CSV files
static PatternFileFilter FILTER_IMAGE
          Filter for Image files
static PatternFileFilter FILTER_IMAGE_OR_PDF
          Filter for image or pdf files
static PatternFileFilter FILTER_IMAGEWRITE
          Filter for Image files for writing
static PatternFileFilter FILTER_JAR
          File filter used for bundle files
static PatternFileFilter FILTER_JPG
          Filter for JPEG files
static PatternFileFilter FILTER_KML
          Filter for xls files
static PatternFileFilter FILTER_KMZ
          Filter for kmz files
static PatternFileFilter FILTER_LOG
          Filter for log files
static PatternFileFilter FILTER_MOV
          Filter for QuickTime files
static PatternFileFilter FILTER_NETCDF
          Filter for netCDF files
static PatternFileFilter FILTER_TXT
          Filter for Text files
static PatternFileFilter FILTER_XLS
          Filter for xls files
static PatternFileFilter FILTER_XML
          Filter for XML files
static String NULL_BTNTEXT
          null button text intrinsic
static String NULL_STRING
          null string intrinsic
static String NULL_TITLE
          null title intrinsic
static String PROP_DIR_HISTORY
          Property in the store for the history list
static String PROP_DIRECTORY
          Property in the store for the last dir
static String SUFFIX_AVI
          _more_
static String SUFFIX_CSV
          Suffix for CSV files
static String SUFFIX_GIF
          Suffix for GIF files
static String SUFFIX_JAR
          Suffix for JAR files
static String SUFFIX_JPG
          Suffix for JPEG files
static String SUFFIX_KML
          Suffix for CSV files
static String SUFFIX_KMZ
          Suffix for CSV files
static String SUFFIX_LOG
          Suffix for log files
static String SUFFIX_MOV
          Suffix for Quicktime files
static String SUFFIX_NETCDF
          Suffix for netCDF files
static String SUFFIX_PNG
          Suffix for PNG files
static String SUFFIX_TXT
          Suffix for CSV files
static String SUFFIX_XLS
          Suffix for CSV files
static String SUFFIX_XML
          Suffix for XML files
 
Constructor Summary
FileManager(Component parent)
          Create a FileManager and use parent as the parent for the dialog.
FileManager(Component parent, String defDir, FileFilter filter)
          Create a FileManager and use the specified params to configure its behavior.
FileManager(Component parent, String defDir, FileFilter filter, String title)
          Create a FileManager and use the specified params to configure its behavior.
FileManager(Component parent, String defDir, List filters)
          Create a FileManager and use the specified params to configure its behavior.
FileManager(Component parent, String defDir, List filters, String title)
          Create a FileManager and use the specified params to configure its behavior.
FileManager(Component parent, String defDir, List filters, String title, boolean includeAllFilter)
          Create a FileManager and use the specified params to configure its behavior.
FileManager(Component parent, String defDir, String file_extension, String desc)
          Create a FileManager and use the specified params to configure its behavior.
 
Method Summary
static void addToHistory(File file)
          Add the file (or its parent directory if it is not a directory) to the history list.
 String chooseFilename()
          Choose a filename.
 String chooseFilename(String title)
          Choose a filename and set the title in the dialog.
 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.
 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.
 JFileChooser getChooser()
          Get the chooser that this FileManager wraps.
static File getDirectory(String dfltDir)
          Return a directory selection.
static File getDirectory(String dfltDir, String title)
          Have the user select a directory
static File getDirectory(String dfltDir, String title, JComponent accessory)
          _more_
 String getDirectoryName()
          Get the current directory name.
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.
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.
static boolean getFileHidingEnabled()
          _more_
static List getHistoryList()
          Get the history list.
static List getHistoryList(ActionListener listener)
          Get the history list.
static String getReadFile()
          Get the file that this FileManager will read from using the defaults.
static String getReadFile(FileFilter filter)
          Get the file that this FileManager will read from using the specified parameters to configure the widget.
static String getReadFile(FileFilter filter, boolean includeAllFilter)
          Get the file that this FileManager will read from using the specified parameters to configure the widget.
static String getReadFile(String title, FileFilter filter)
          Get the file that this FileManager will read from using the specified parameters to configure the widget.
static String getReadFile(String title, List filters)
          Get the file that this FileManager will read from using the specified parameters to configure the widget.
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.
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.
static String getWriteFile()
          Get the file that this FileManager will write to using the defaults.
static String getWriteFile(FileFilter filter, String suffix)
          Get the file that this FileManager will write to using the specified parameters.
static String getWriteFile(FileFilter filter, String suffix, JComponent accessory)
          Get the file that this FileManager will write to using the specified parameters.
static String getWriteFile(List filters, String suffix)
          Get the file that this FileManager will write to using the specified parameters.
static String getWriteFile(List filters, String suffix, JComponent accessory)
          Get the file that this FileManager will write to using the specified parameters.
static String getWriteFile(String filename)
          Get the file that this FileManager will write to using the defaults.
static String getWriteFile(String title, FileFilter filter, String suffix)
          Get the file that this FileManager will write to using the specified parameters.
static String getWriteFile(String title, List filters, String suffix)
          Get the file that this FileManager will write to using the specified parameters.
static JComponent makeDirectoryHistoryComponent(JFileChooser fileChooser, boolean includeLabel)
          Create the directory history button and menu
 void setAccessory(JComponent comp)
          Set the accessory for the file chooser to comp.
 void setApproveButtonText(String approveButtonText)
          Set the approve button text for the chooser.
static void setFileHidingEnabled(boolean value)
          _more_
static void setFixFileLockup(boolean b)
          Do we set the FileChooser.useShellFolder=false This fixes the occasional problemo of a system lockup running under windows
 void setSelectedFile(String file)
          Set the selected file for the chooser.
static void setStore(PersistentStore store, String writeProperty, String readProperty)
          Set the persistent store for this FileManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_DIR_HISTORY

public static final String PROP_DIR_HISTORY
Property in the store for the history list

See Also:
Constant Field Values

PROP_DIRECTORY

public static final String PROP_DIRECTORY
Property in the store for the last dir

See Also:
Constant Field Values

SUFFIX_XML

public static final String SUFFIX_XML
Suffix for XML files

See Also:
Constant Field Values

SUFFIX_AVI

public static final String SUFFIX_AVI
_more_

See Also:
Constant Field Values

SUFFIX_CSV

public static final String SUFFIX_CSV
Suffix for CSV files

See Also:
Constant Field Values

SUFFIX_XLS

public static final String SUFFIX_XLS
Suffix for CSV files

See Also:
Constant Field Values

SUFFIX_KML

public static final String SUFFIX_KML
Suffix for CSV files

See Also:
Constant Field Values

SUFFIX_KMZ

public static final String SUFFIX_KMZ
Suffix for CSV files

See Also:
Constant Field Values

SUFFIX_JPG

public static final String SUFFIX_JPG
Suffix for JPEG files

See Also:
Constant Field Values

SUFFIX_PNG

public static final String SUFFIX_PNG
Suffix for PNG files

See Also:
Constant Field Values

SUFFIX_GIF

public static final String SUFFIX_GIF
Suffix for GIF files

See Also:
Constant Field Values

SUFFIX_MOV

public static final String SUFFIX_MOV
Suffix for Quicktime files

See Also:
Constant Field Values

SUFFIX_TXT

public static final String SUFFIX_TXT
Suffix for CSV files

See Also:
Constant Field Values

SUFFIX_LOG

public static final String SUFFIX_LOG
Suffix for log files

See Also:
Constant Field Values

SUFFIX_NETCDF

public static final String SUFFIX_NETCDF
Suffix for netCDF files

See Also:
Constant Field Values

SUFFIX_JAR

public static final String SUFFIX_JAR
Suffix for JAR files

See Also:
Constant Field Values

FILTER_XML

public static final PatternFileFilter FILTER_XML
Filter for XML files


FILTER_NETCDF

public static final PatternFileFilter FILTER_NETCDF
Filter for netCDF files


FILTER_CSV

public static final PatternFileFilter FILTER_CSV
Filter for CSV files


FILTER_TXT

public static final PatternFileFilter FILTER_TXT
Filter for Text files


FILTER_XLS

public static final PatternFileFilter FILTER_XLS
Filter for xls files


FILTER_KML

public static final PatternFileFilter FILTER_KML
Filter for xls files


FILTER_JAR

public static final PatternFileFilter FILTER_JAR
File filter used for bundle files


FILTER_JPG

public static final PatternFileFilter FILTER_JPG
Filter for JPEG files


FILTER_IMAGE

public static final PatternFileFilter FILTER_IMAGE
Filter for Image files


FILTER_IMAGEWRITE

public static final PatternFileFilter FILTER_IMAGEWRITE
Filter for Image files for writing


FILTER_IMAGE_OR_PDF

public static final PatternFileFilter FILTER_IMAGE_OR_PDF
Filter for image or pdf files


FILTER_MOV

public static final PatternFileFilter FILTER_MOV
Filter for QuickTime files


FILTER_AVI

public static final PatternFileFilter FILTER_AVI
Filter for QuickTime files


FILTER_ANIMATEDGIF

public static final PatternFileFilter FILTER_ANIMATEDGIF
Filter for QuickTime files


FILTER_LOG

public static final PatternFileFilter FILTER_LOG
Filter for log files


FILTER_KMZ

public static final PatternFileFilter FILTER_KMZ
Filter for kmz files


NULL_STRING

public static final String NULL_STRING
null string intrinsic


NULL_BTNTEXT

public static final String NULL_BTNTEXT
null button text intrinsic


NULL_TITLE

public static final String NULL_TITLE
null title intrinsic

Constructor Detail

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 Detail

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