public class FileChooserManager extends java.lang.Object
AbstractFileChooser
dialogs.
A simpler usage is to call the DiskAccessAction.createAndOpenFileChooser(boolean, boolean, java.lang.String)
methods.
Modifier and Type | Field and Description |
---|---|
private boolean |
allTypes |
private java.lang.String |
curDir |
private javax.swing.filechooser.FileFilter |
defaultFilter |
private java.lang.String |
extension |
private AbstractFileChooser |
fc |
private java.io.File |
file |
private java.util.Collection<? extends javax.swing.filechooser.FileFilter> |
filters |
private java.lang.String |
lastDirProperty |
private boolean |
multiple |
private boolean |
open |
static BooleanProperty |
PROP_USE_NATIVE_FILE_DIALOG
Property to enable use of native file dialogs.
|
private int |
selectionMode |
private java.lang.String |
title |
Constructor and Description |
---|
FileChooserManager()
Creates a new
FileChooserManager with default values. |
FileChooserManager(boolean open)
Creates a new
FileChooserManager . |
FileChooserManager(boolean open,
java.lang.String lastDirProperty)
Creates a new
FileChooserManager . |
FileChooserManager(boolean open,
java.lang.String lastDirProperty,
java.lang.String defaultDir)
Creates a new
FileChooserManager . |
Modifier and Type | Method and Description |
---|---|
FileChooserManager |
allTypes(boolean value)
Builder method to set
allTypes property. |
FileChooserManager |
createFileChooser()
Creates a new
AbstractFileChooser with default settings. |
FileChooserManager |
createFileChooser(boolean multiple,
java.lang.String title,
java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters,
javax.swing.filechooser.FileFilter defaultFilter,
int selectionMode)
Creates a new
AbstractFileChooser with given settings for a collection of FileFilter s. |
FileChooserManager |
createFileChooser(boolean multiple,
java.lang.String title,
javax.swing.filechooser.FileFilter filter,
int selectionMode)
Creates a new
AbstractFileChooser with given settings for a single FileFilter . |
FileChooserManager |
createFileChooser(boolean multiple,
java.lang.String title,
java.lang.String extension,
boolean allTypes,
int selectionMode)
Creates a new
AbstractFileChooser with given settings for a file extension. |
FileChooserManager |
defaultFilter(javax.swing.filechooser.FileFilter value)
Builder method to set
defaultFilter property. |
FileChooserManager |
doCreateFileChooser()
Builds
FileChooserManager object using properties set by builder methods or default values. |
FileChooserManager |
extension(java.lang.String value)
Builder method to set
extension property. |
FileChooserManager |
file(java.io.File value)
Builder method to set
file property. |
FileChooserManager |
filters(java.util.Collection<? extends javax.swing.filechooser.FileFilter> value)
Builder method to set
filters property. |
AbstractFileChooser |
getFileChooser()
Replies the
AbstractFileChooser that has been previously created. |
java.io.File |
getFileForSave()
Opens the file chooser dialog, then checks if filename has the given extension.
|
java.lang.String |
getInitialDirectory()
Replies the initial directory used to construct the
AbstractFileChooser . |
FileChooserManager |
multiple(boolean value)
Builder method to set
multiple property. |
AbstractFileChooser |
openFileChooser()
Opens the
AbstractFileChooser that has been created. |
AbstractFileChooser |
openFileChooser(java.awt.Component parent)
Opens the
AbstractFileChooser that has been created and waits for the user to choose a file/directory, or cancel the dialog.When the user choses a file or directory, the lastDirProperty is updated to the chosen directory path. |
FileChooserManager |
selectionMode(int value)
Builder method to set
selectionMode property. |
FileChooserManager |
title(java.lang.String value)
Builder method to set
title property. |
public static final BooleanProperty PROP_USE_NATIVE_FILE_DIALOG
private final boolean open
private final java.lang.String lastDirProperty
private final java.lang.String curDir
private boolean multiple
private java.lang.String title
private java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters
private javax.swing.filechooser.FileFilter defaultFilter
private int selectionMode
private java.lang.String extension
private boolean allTypes
private java.io.File file
private AbstractFileChooser fc
public FileChooserManager()
FileChooserManager
with default values.createFileChooser()
public FileChooserManager(boolean open)
FileChooserManager
.open
- If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.createFileChooser()
public FileChooserManager(boolean open, java.lang.String lastDirProperty)
FileChooserManager
.open
- If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.lastDirProperty
- The name of the property used to get the last directory. This directory is used to initialize the AbstractFileChooser.
Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.createFileChooser()
public FileChooserManager(boolean open, java.lang.String lastDirProperty, java.lang.String defaultDir)
FileChooserManager
.open
- If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.lastDirProperty
- The name of the property used to get the last directory. This directory is used to initialize the AbstractFileChooser.
Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.defaultDir
- The default directory used to initialize the AbstractFileChooser if the lastDirProperty
property value is missing.createFileChooser()
public final AbstractFileChooser getFileChooser()
AbstractFileChooser
that has been previously created.AbstractFileChooser
that has been previously created, or null
if it has not been created yet.createFileChooser()
public final java.lang.String getInitialDirectory()
AbstractFileChooser
.AbstractFileChooser
.public final FileChooserManager createFileChooser()
AbstractFileChooser
with default settings. All files will be accepted.public final FileChooserManager createFileChooser(boolean multiple, java.lang.String title, javax.swing.filechooser.FileFilter filter, int selectionMode)
AbstractFileChooser
with given settings for a single FileFilter
.multiple
- If true, makes the dialog allow multiple file selectionstitle
- The string that goes in the dialog window's title barfilter
- The only file filter that will be proposed by the dialogselectionMode
- The selection mode that allows the user to:JFileChooser.FILES_ONLY
)JFileChooser.DIRECTORIES_ONLY
)JFileChooser.FILES_AND_DIRECTORIES
)DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
public final FileChooserManager createFileChooser(boolean multiple, java.lang.String title, java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters, javax.swing.filechooser.FileFilter defaultFilter, int selectionMode)
AbstractFileChooser
with given settings for a collection of FileFilter
s.multiple
- If true, makes the dialog allow multiple file selectionstitle
- The string that goes in the dialog window's title barfilters
- The file filters that will be proposed by the dialogdefaultFilter
- The file filter that will be selected by defaultselectionMode
- The selection mode that allows the user to:JFileChooser.FILES_ONLY
)JFileChooser.DIRECTORIES_ONLY
)JFileChooser.FILES_AND_DIRECTORIES
)DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
public final FileChooserManager createFileChooser(boolean multiple, java.lang.String title, java.lang.String extension, boolean allTypes, int selectionMode)
AbstractFileChooser
with given settings for a file extension.multiple
- If true, makes the dialog allow multiple file selectionstitle
- The string that goes in the dialog window's title barextension
- The file extension that will be selected as the default file filterallTypes
- If true, all the files types known by JOSM will be proposed in the "file type" combobox.
If false, only the file filters that include extension
will be proposedselectionMode
- The selection mode that allows the user to:JFileChooser.FILES_ONLY
)JFileChooser.DIRECTORIES_ONLY
)JFileChooser.FILES_AND_DIRECTORIES
)DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
public FileChooserManager multiple(boolean value)
multiple
property.value
- If true, makes the dialog allow multiple file selectionspublic FileChooserManager title(java.lang.String value)
title
property.value
- The string that goes in the dialog window's title barpublic FileChooserManager filters(java.util.Collection<? extends javax.swing.filechooser.FileFilter> value)
filters
property.value
- The file filters that will be proposed by the dialogpublic FileChooserManager defaultFilter(javax.swing.filechooser.FileFilter value)
defaultFilter
property.value
- The file filter that will be selected by defaultpublic FileChooserManager selectionMode(int value)
selectionMode
property.value
- The selection mode that allows the user to:JFileChooser.FILES_ONLY
)JFileChooser.DIRECTORIES_ONLY
)JFileChooser.FILES_AND_DIRECTORIES
)public FileChooserManager extension(java.lang.String value)
extension
property.value
- The file extension that will be selected as the default file filterpublic FileChooserManager allTypes(boolean value)
allTypes
property.value
- If true, all the files types known by JOSM will be proposed in the "file type" combobox.
If false, only the file filters that include extension
will be proposedpublic FileChooserManager file(java.io.File value)
file
property.value
- File
object with default filenamepublic FileChooserManager doCreateFileChooser()
FileChooserManager
object using properties set by builder methods or default values.public final AbstractFileChooser openFileChooser()
AbstractFileChooser
that has been created.AbstractFileChooser
if the user effectively choses a file or directory. null
if the user cancelled the dialog.public AbstractFileChooser openFileChooser(java.awt.Component parent)
AbstractFileChooser
that has been created and waits for the user to choose a file/directory, or cancel the dialog.lastDirProperty
is updated to the chosen directory path.parent
- The Component used as the parent of the AbstractFileChooser. If null, uses Main.parent
.AbstractFileChooser
if the user effectively choses a file or directory. null
if the user cancelled the dialog.public java.io.File getFileForSave()
File
or null
if the user cancelled the dialog.