public class NativeFileChooser extends AbstractFileChooser
FileDialog
implementation,
which looks like more a native file chooser than the Swing implementation.Modifier and Type | Field and Description |
---|---|
private java.awt.FileDialog |
fileDialog
The instance of the fileDialog
|
private javax.swing.filechooser.FileFilter |
fileFilter |
private int |
selectionMode |
locale
Constructor and Description |
---|
NativeFileChooser(java.io.File file)
Constructs a new
NativeFileChooser . |
Modifier and Type | Method and Description |
---|---|
void |
addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Adds a filter to the list of user choosable file filters.
|
javax.swing.filechooser.FileFilter[] |
getChoosableFileFilters()
Gets the list of user choosable file filters.
|
java.io.File |
getCurrentDirectory()
Returns the current directory.
|
javax.swing.filechooser.FileFilter |
getFileFilter()
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 file chooser is
set to allow multiple selection.
|
boolean |
isMultiSelectionEnabled()
Returns true if multiple files can be selected.
|
void |
setAcceptAllFileFilterUsed(boolean b)
Determines whether the
AcceptAll FileFilter is used
as an available choice in the choosable filter list. |
void |
setCurrentDirectory(java.io.File f)
Sets the current directory.
|
void |
setDialogTitle(java.lang.String title)
Sets the string that goes in the
JFileChooser window's
title bar. |
void |
setFileFilter(javax.swing.filechooser.FileFilter cff)
Sets the current file filter.
|
void |
setFileSelectionMode(int selectionMode)
Sets the
JFileChooser to allow the user to just
select files, just select
directories, or select both files and directories. |
void |
setMultiSelectionEnabled(boolean multiple)
Sets the file chooser to allow multiple file selections.
|
void |
setSelectedFile(java.io.File file)
Sets the selected file.
|
int |
showOpenDialog(java.awt.Component parent)
Pops up an "Open File" file chooser dialog.
|
int |
showSaveDialog(java.awt.Component parent)
Pops up a "Save File" file chooser dialog.
|
static boolean |
supportsSelectionMode(int selectionMode)
Determines if the selection mode is suuported by the native file chooser.
|
setDefaultLocale
private final java.awt.FileDialog fileDialog
private javax.swing.filechooser.FileFilter fileFilter
private int selectionMode
public NativeFileChooser(java.io.File file)
NativeFileChooser
.file
- the current file/directory to point topublic void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
AbstractFileChooser
setFileSelectionMode
.addChoosableFileFilter
in class AbstractFileChooser
filter
- the FileFilter
to add to the choosable file
filter listAbstractFileChooser.getChoosableFileFilters()
,
AbstractFileChooser.setFileSelectionMode(int)
public javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
AbstractFileChooser
getChoosableFileFilters
in class AbstractFileChooser
FileFilter
array containing all the choosable
file filtersAbstractFileChooser.addChoosableFileFilter(javax.swing.filechooser.FileFilter)
public java.io.File getCurrentDirectory()
AbstractFileChooser
getCurrentDirectory
in class AbstractFileChooser
AbstractFileChooser.setCurrentDirectory(java.io.File)
public javax.swing.filechooser.FileFilter getFileFilter()
AbstractFileChooser
getFileFilter
in class AbstractFileChooser
AbstractFileChooser.setFileFilter(javax.swing.filechooser.FileFilter)
,
AbstractFileChooser.addChoosableFileFilter(javax.swing.filechooser.FileFilter)
public java.io.File getSelectedFile()
AbstractFileChooser
setSelectedFile
or by a user action, such as
either typing the filename into the UI or selecting the
file from a list in the UI.getSelectedFile
in class AbstractFileChooser
AbstractFileChooser.setSelectedFile(java.io.File)
public java.io.File[] getSelectedFiles()
AbstractFileChooser
getSelectedFiles
in class AbstractFileChooser
public boolean isMultiSelectionEnabled()
AbstractFileChooser
isMultiSelectionEnabled
in class AbstractFileChooser
AbstractFileChooser.setMultiSelectionEnabled(boolean)
public void setAcceptAllFileFilterUsed(boolean b)
AbstractFileChooser
AcceptAll FileFilter
is used
as an available choice in the choosable filter list.
If false, the AcceptAll
file filter is removed from
the list of available file filters.
If true, the AcceptAll
file filter will become the
the actively used file filter.setAcceptAllFileFilterUsed
in class AbstractFileChooser
b
- whether the AcceptAll FileFilter
is used
as an available choice in the choosable filter listAbstractFileChooser.setFileFilter(javax.swing.filechooser.FileFilter)
public void setCurrentDirectory(java.io.File f)
AbstractFileChooser
null
sets the
file chooser to point to the user's default directory.
This default depends on the operating system. It is
typically the "My Documents" folder on Windows, and the user's
home directory on Unix.
If the file passed in as currentDirectory
is not a
directory, the parent of the file will be used as the currentDirectory.
If the parent is not traversable, then it will walk up the parent tree
until it finds a traversable directory, or hits the root of the
file system.setCurrentDirectory
in class AbstractFileChooser
f
- the current directory to point toAbstractFileChooser.getCurrentDirectory()
public void setDialogTitle(java.lang.String title)
AbstractFileChooser
JFileChooser
window's
title bar.setDialogTitle
in class AbstractFileChooser
title
- the new String
for the title barpublic void setFileFilter(javax.swing.filechooser.FileFilter cff)
AbstractFileChooser
setFileFilter
in class AbstractFileChooser
cff
- the new current file filter to useAbstractFileChooser.getFileFilter()
public void setFileSelectionMode(int selectionMode)
AbstractFileChooser
JFileChooser
to allow the user to just
select files, just select
directories, or select both files and directories. The default is
JFilesChooser.FILES_ONLY
.setFileSelectionMode
in class AbstractFileChooser
selectionMode
- the type of files to be displayed:
public void setMultiSelectionEnabled(boolean multiple)
AbstractFileChooser
setMultiSelectionEnabled
in class AbstractFileChooser
multiple
- true if multiple files may be selectedAbstractFileChooser.isMultiSelectionEnabled()
public void setSelectedFile(java.io.File file)
AbstractFileChooser
setSelectedFile
in class AbstractFileChooser
file
- the selected fileAbstractFileChooser.getSelectedFile()
public int showOpenDialog(java.awt.Component parent)
AbstractFileChooser
showOpenDialog
in class AbstractFileChooser
parent
- the parent component of the dialog,
can be null
;
see showDialog
for detailsGraphicsEnvironment.isHeadless()
public int showSaveDialog(java.awt.Component parent)
AbstractFileChooser
showSaveDialog
in class AbstractFileChooser
parent
- the parent component of the dialog,
can be null
;
see showDialog
for detailsGraphicsEnvironment.isHeadless()
public static boolean supportsSelectionMode(int selectionMode)
selectionMode
- the selection modetrue
if the selection mode is supported, false
otherwise