com.ibm.as400.ui.framework.java
Class FileChooserDialog

java.lang.Object
  |
  +--com.ibm.as400.ui.framework.java.FileChooserDialog

public class FileChooserDialog
extends java.lang.Object

This interface provides a simple mechanism for the user to choose a file to open or choose a file to save. A default start directory, default file, and multiple file selection is supported.

Restrictions:

Since:
v5r1m0

Field Summary
static int CANCEL_OPTION
          Return value if cancel is chosen.
static int COMMIT_OPTION
          Return value if commit (yes, ok) is chosen.
static int DIRECTORIES_ONLY
          Instruction to display only directories.
static int FILES_AND_DIRECTORIES
          Instruction to display both files and directories.
static int FILES_ONLY
          Instruction to display only files.
 
Constructor Summary
FileChooserDialog()
          Creates a FileChooserDialog pointing to the user's home directory.
FileChooserDialog(java.io.File file)
          Creates a FileChooserDialog using the given File as the path.
FileChooserDialog(java.lang.String currentDirectoryPath)
          Creates a FileChooserDialog using the given path.
 
Method Summary
 void addFilter(java.lang.String[] extensions, java.lang.String description)
          Adds a file Filter to the FileChooserDialog
 java.io.File getCurrentDirectory()
          Returns the current directory.
 java.lang.String getDialogTitle()
          Gets the string that goes in the FileChooserDialog's titlebar.
 java.lang.String[] getFilter()
          Returns the currently selected file filter.
 java.io.File getSelectedFile()
          Returns the selected file.
 java.io.File[] getSelectedFiles()
          Returns a list of selected files if the filechooser is set to allow multi-selection.
 int getSelectionMode()
          Returns the current file-selection mode.
 boolean isMultiSelectionEnabled()
          Returns true if multiple files can be selected.
 void removeAcceptAllFilter()
          Removes the Accept All filter (*.*) from this FileChooserDialog
 void setCurrentDirectory(java.io.File currentDirectory)
          Sets the current directory.
 void setDialogTitle(java.lang.String dialogTitle)
          Sets the string that goes in the FileChooserDialog's titlebar.
 void setFilter(java.lang.String[] extensions)
          Sets the current file filter.
 void setMultiSelectionEnabled(boolean b)
          Sets the filechooser to allow multiple file selections.
 void setSelectedFile(java.io.File file)
          Sets the selected file.
 void setSelectedFiles(java.io.File[] files)
          Sets the list of selected files if the filechooser is set to allow multi-selection.
 void setSelectionMode(int mode)
          Sets the FileChooserDialog to allow the user to just select files, just select directories, or select both files and directories.
 int showCustomDialog(WindowManager parent, java.lang.String commitButtonText)
          Brings up a FileChooserDialog with custom text on the CommitButton.
 int showOpenDialog(WindowManager parent)
          Brings up an "Open" FileChooserDialog.
 int showSaveDialog(WindowManager parent)
          Brings up a "Save" FileChooserDialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORIES_ONLY

public static final int DIRECTORIES_ONLY
Instruction to display only directories.

FILES_ONLY

public static final int FILES_ONLY
Instruction to display only files.

FILES_AND_DIRECTORIES

public static final int FILES_AND_DIRECTORIES
Instruction to display both files and directories.

COMMIT_OPTION

public static final int COMMIT_OPTION
Return value if commit (yes, ok) is chosen.

CANCEL_OPTION

public static final int CANCEL_OPTION
Return value if cancel is chosen.
Constructor Detail

FileChooserDialog

public FileChooserDialog()
Creates a FileChooserDialog pointing to the user's home directory.

FileChooserDialog

public FileChooserDialog(java.lang.String currentDirectoryPath)
Creates a FileChooserDialog using the given path. Passing in a null string causes the file chooser to point to the users home directory.
Parameters:
currentDirectoryPath - a String giving the path to a file or directory

FileChooserDialog

public FileChooserDialog(java.io.File file)
Creates a FileChooserDialog using the given File as the path. Passing in a null file causes the file chooser to point to the users's home directory.
Parameters:
file - a File object specifying the path to a file or directory
Method Detail

setDialogTitle

public void setDialogTitle(java.lang.String dialogTitle)
Sets the string that goes in the FileChooserDialog's titlebar.
Parameters:
dialogTitle - The translatable String to be displayed
See Also:
getDialogTitle()

getDialogTitle

public java.lang.String getDialogTitle()
Gets the string that goes in the FileChooserDialog's titlebar.
See Also:
setDialogTitle(java.lang.String)

setSelectionMode

public void setSelectionMode(int mode)
Sets the FileChooserDialog to allow the user to just select files, just select directories, or select both files and directories.
Parameters:
dialogType - the type of dialog to be displayed: FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
See Also:
getSelectionMode()

getSelectionMode

public int getSelectionMode()
Returns the current file-selection mode.
Returns:
an int indicating the type of dialog to be displayed: FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
See Also:
setSelectionMode(int)

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean b)
Sets the filechooser to allow multiple file selections. NOTE: this method is non-funcitonal prior to JRE 1.3.
See Also:
isMultiSelectionEnabled()

isMultiSelectionEnabled

public boolean isMultiSelectionEnabled()
Returns true if multiple files can be selected.
Returns:
true if multiple files can be selected.
See Also:
setMultiSelectionEnabled(boolean)

setSelectedFile

public void setSelectedFile(java.io.File file)
Sets the selected file. If the file's parent directory is not the current directory, changes the current directory to be the file's parent directory.
Parameters:
File - the selected file
See Also:
getSelectedFile()

getSelectedFile

public java.io.File getSelectedFile()
Returns the selected file. This can be set either by the programmer via setSelectedFile() or by a user action, such as either typing the filename in the UI or selecting the file from a list in the UI.
Returns:
the selected file
See Also:
setSelectedFile(java.io.File)

setSelectedFiles

public void setSelectedFiles(java.io.File[] files)
Sets the list of selected files if the filechooser is set to allow multi-selection. Note: should not be used with JREs prior to 1.3
Parameters:
files - An Array of files to be initially selcted

getSelectedFiles

public java.io.File[] getSelectedFiles()
Returns a list of selected files if the filechooser is set to allow multi-selection. Note: should not be used with JREs prior to 1.3

setCurrentDirectory

public void setCurrentDirectory(java.io.File currentDirectory)
Sets the current directory. Passing in null sets the FileChooserDialog to point to the users's home directory. If the file passed in as currentDirectory is not a directory, the parent of the file will be used as the currentDirectory.
Parameters:
currentDirectory - the current directory to point to
See Also:
getCurrentDirectory()

getCurrentDirectory

public java.io.File getCurrentDirectory()
Returns the current directory.
Returns:
the current directory
See Also:
setCurrentDirectory(java.io.File)

showOpenDialog

public int showOpenDialog(WindowManager parent)
Brings up an "Open" FileChooserDialog.
Parameters:
parent - the WindowManager that is the parent of this dialog
Returns:
the option selected by the user : CANCEL_OPTION, COMMIT_OPTION

showSaveDialog

public int showSaveDialog(WindowManager parent)
Brings up a "Save" FileChooserDialog.
Parameters:
parent - the WindowManager that is the parent of this dialog
Returns:
the option selected by the user : CANCEL_OPTION, COMMIT_OPTION

showCustomDialog

public int showCustomDialog(WindowManager parent,
                            java.lang.String commitButtonText)
Brings up a FileChooserDialog with custom text on the CommitButton.
Parameters:
parent - the WindowManager that is the parent of this dialog
approveButtonText - the text of the ApproveButton
Returns:
the option selected by the user : CANCEL_OPTION, COMMIT_OPTION

addFilter

public void addFilter(java.lang.String[] extensions,
                      java.lang.String description)
Adds a file Filter to the FileChooserDialog

Adds a file Filter to the FileChooserDialog. The last filter added will be the initially used filter.

Parameters:
extensions - An array of file extension to filter i.e. "txt", "doc"
description - A translatable description of the filter
Since:
v5r1m0

getFilter

public java.lang.String[] getFilter()
Returns the currently selected file filter.
Returns:
the extensions being filtered. If the accept all filter is being used the string "*.*" will be returned as the first item in the array.
See Also:
setFilter(java.lang.String[]), addFilter(java.lang.String[], java.lang.String)

setFilter

public void setFilter(java.lang.String[] extensions)
Sets the current file filter. The file filter is used by the FileChooserDialog to filter out files from view from the user and must have previously been added to this instance of FileChooserDialog.
Parameters:
extensions - the file extensions i.e. "txt" to filter
See Also:
getFilter(), addFilter(java.lang.String[], java.lang.String)

removeAcceptAllFilter

public void removeAcceptAllFilter()
Removes the Accept All filter (*.*) from this FileChooserDialog
Since:
v5r1m0