org.eclipse.swt.widgets
Class FileDialog

java.lang.Object
  extended byorg.eclipse.swt.widgets.Dialog
      extended byorg.eclipse.swt.widgets.FileDialog

public class FileDialog
extends Dialog

Instances of this class allow the user to navigate the file system and select or enter a file name.

Styles:
SAVE, OPEN, MULTI
Events:
(none)

IMPORTANT: This class is intended to be subclassed only within the SWT implementation.


Constructor Summary
FileDialog(Shell parent)
          Constructs a new instance of this class given only its parent.
FileDialog(Shell parent, int style)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 
Method Summary
 java.lang.String getFileName()
          Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.
 java.lang.String[] getFileNames()
          Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.
 java.lang.String[] getFilterExtensions()
          Returns the file extensions which the dialog will use to filter the files it shows.
 java.lang.String[] getFilterNames()
          Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.
 java.lang.String getFilterPath()
          Returns the directory path that the dialog will use, or an empty string if this is not set.
 java.lang.String open()
          Makes the dialog visible and brings it to the front of the display.
 void setFileName(java.lang.String string)
          Set the initial filename which the dialog will select by default when opened to the argument, which may be null.
 void setFilterExtensions(java.lang.String[] extensions)
          Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.
 void setFilterNames(java.lang.String[] names)
          Sets the the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.
 void setFilterPath(java.lang.String string)
          Sets the directory path that the dialog will use to the argument, which may be null.
 
Methods inherited from class org.eclipse.swt.widgets.Dialog
checkSubclass, getParent, getStyle, getText, setText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDialog

public FileDialog(Shell parent)
Constructs a new instance of this class given only its parent.

Parameters:
parent - a shell which will be the parent of the new instance
Throws:
java.lang.IllegalArgumentException -
SWTException -

FileDialog

public FileDialog(Shell parent,
                  int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
parent - a shell which will be the parent of the new instance
style - the style of dialog to construct
Throws:
java.lang.IllegalArgumentException -
SWTException -
Method Detail

getFileName

public java.lang.String getFileName()
Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.

Returns:
the relative path of the file

getFileNames

public java.lang.String[] getFileNames()
Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.

Returns:
the relative paths of the files

getFilterExtensions

public java.lang.String[] getFilterExtensions()
Returns the file extensions which the dialog will use to filter the files it shows.

Returns:
the file extensions filter

getFilterNames

public java.lang.String[] getFilterNames()
Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.

Returns:
the list of filter names

getFilterPath

public java.lang.String getFilterPath()
Returns the directory path that the dialog will use, or an empty string if this is not set. File names in this path will appear in the dialog, filtered according to the filter extensions.

Returns:
the directory path string
See Also:
setFilterExtensions(java.lang.String[])

open

public java.lang.String open()
Makes the dialog visible and brings it to the front of the display.

Returns:
a string describing the absolute path of the first selected file, or null if the dialog was cancelled or an error occurred
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the dialog has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog

setFileName

public void setFileName(java.lang.String string)
Set the initial filename which the dialog will select by default when opened to the argument, which may be null. The name will be prefixed with the filter path when one is supplied.

Parameters:
string - the file name

setFilterExtensions

public void setFilterExtensions(java.lang.String[] extensions)
Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.

The strings are platform specific. For example, on Windows, an extension filter string is typically of the form "*.extension", where "*.*" matches all files.

Parameters:
extensions - the file extension filter

setFilterNames

public void setFilterNames(java.lang.String[] names)
Sets the the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.

Parameters:
names - the list of filter names

setFilterPath

public void setFilterPath(java.lang.String string)
Sets the directory path that the dialog will use to the argument, which may be null. File names in this path will appear in the dialog, filtered according to the filter extensions. If the string is null, then the operating system's default filter path will be used.

Note that the path string is platform dependent. For convenience, either '/' or '\' can be used as a path separator.

Parameters:
string - the directory path
See Also:
setFilterExtensions(java.lang.String[])