Class AbstractFileChooserOptions<T,S extends AbstractFileChooserOptions<T,S>>
- java.lang.Object
-
- net.sf.jguiraffe.gui.dlg.AbstractDialogOptions<T,S>
-
- net.sf.jguiraffe.gui.dlg.filechooser.AbstractFileChooserOptions<T,S>
-
- Type Parameters:
T
- the result type of the dialogS
- the self type
- Direct Known Subclasses:
FileChooserOptions
,MultiFileChooserOptions
public abstract class AbstractFileChooserOptions<T,S extends AbstractFileChooserOptions<T,S>> extends AbstractDialogOptions<T,S>
An abstract base class for the options of file chooser dialogs.
The concrete option classes for file chooser dialogs distinguish only in the result type: a single
File
for the normal dialog and a collection of files for the multi dialog. Therefore, this base class already defines all properties, but leaves the result type open.- Since:
- 1.4
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFileChooserOptions(DialogResultCallback<T,?> resultCallback)
Creates a new instance ofAbstractFileChooserOptions
and sets the callback to be notified with the dialog result.protected
AbstractFileChooserOptions(DialogResultCallback<T,D> resultCallback, D data)
Creates a new instance ofAbstractFileChooserOptions
and sets the callback to be notified with the dialog result and an additional data object to be passed to the callback.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
getCurrentFile()
Returns the current file to be selected initially.FileExtensionFilter
getCurrentFilter()
Returns the current filter.int
getCurrentFilterIndex()
Returns the index of the current filter when the dialog is opened.List<FileExtensionFilter>
getFilters()
Returns a (unmodifiable) list with predefined file filters.File
getInitialDirectory()
Returns the initial directory for the file chooser dialog.S
setCurrentFile(File file)
Allows pre-selecting a specific file.S
setCurrentFilterIndex(int index)
Sets the index of the filter to be active when the dialog is opened.S
setFilters(List<FileExtensionFilter> filters)
Sets the filters for the file types to be displayed.S
setFilters(FileExtensionFilter... filters)
Sets the filters for the file types to be displayed as var args.S
setInitialDirectory(File directory)
Allows setting the initial directory for the file chooser dialog.-
Methods inherited from class net.sf.jguiraffe.gui.dlg.AbstractDialogOptions
getCancelInvoker, getResultCallback, getSelf, getTitle, getTitleResource, resolveTitle, setCanceledCallback, setCanceledCallback, setTitle, setTitleResource
-
-
-
-
Constructor Detail
-
AbstractFileChooserOptions
protected AbstractFileChooserOptions(DialogResultCallback<T,D> resultCallback, D data)
Creates a new instance ofAbstractFileChooserOptions
and sets the callback to be notified with the dialog result and an additional data object to be passed to the callback.- Type Parameters:
D
- the type of the data object- Parameters:
resultCallback
- the result callbackdata
- the data object for the callback- Throws:
IllegalArgumentException
- if the result callback is null
-
AbstractFileChooserOptions
protected AbstractFileChooserOptions(DialogResultCallback<T,?> resultCallback)
Creates a new instance ofAbstractFileChooserOptions
and sets the callback to be notified with the dialog result.- Parameters:
resultCallback
- the result callback- Throws:
IllegalArgumentException
- if the result callback is null
-
-
Method Detail
-
setInitialDirectory
public S setInitialDirectory(File directory)
Allows setting the initial directory for the file chooser dialog. When the dialog opens, the files in this directory are displayed.- Parameters:
directory
- the initial directory- Returns:
- this object
-
getInitialDirectory
public File getInitialDirectory()
Returns the initial directory for the file chooser dialog. Result can be null if no such directory has been set.- Returns:
- the initial directory
-
setCurrentFile
public S setCurrentFile(File file)
Allows pre-selecting a specific file. When the dialog opens this file is already selected, but the user can select another one.- Parameters:
file
- the file that is currently selected- Returns:
- this object
-
getCurrentFile
public File getCurrentFile()
Returns the current file to be selected initially. Result can be null if no such file has been set.- Returns:
- the currently selected file
-
setFilters
public S setFilters(List<FileExtensionFilter> filters)
Sets the filters for the file types to be displayed. With this option the user is given the possibility to restrict the display of files to certain predefined types. Note that a filter for all files is not added automatically; this must be done by the application.- Parameters:
filters
- the list with file filters- Returns:
- this object
-
setFilters
public S setFilters(FileExtensionFilter... filters)
Sets the filters for the file types to be displayed as var args. This method is analogous tosetFilters(List)
, but can be called with an arbitrary number of filter objects.- Parameters:
filters
- the file filters- Returns:
- this object
-
setCurrentFilterIndex
public S setCurrentFilterIndex(int index)
Sets the index of the filter to be active when the dialog is opened. Per default, this is the first filter in the list of filters; but with this property a different filter can be selected. If the index passed to this method is out of range for the list of filters, no filter is selected explicitly. (The behavior then depends on the UI library.)- Parameters:
index
- the index of the current filter- Returns:
- this object
-
getCurrentFilterIndex
public int getCurrentFilterIndex()
Returns the index of the current filter when the dialog is opened.- Returns:
- the index of the current filter
-
getCurrentFilter
public FileExtensionFilter getCurrentFilter()
Returns the current filter. This is the filter selected by thecurrentFilterIndex
property. If the current filter index is out of range, this method returns null.- Returns:
- the current filter or null
- See Also:
setCurrentFilterIndex(int)
-
getFilters
public List<FileExtensionFilter> getFilters()
Returns a (unmodifiable) list with predefined file filters. If no filters have been set, the list is empty.- Returns:
- a list with file filters
-
-