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 java.lang.String |
curDir |
private AbstractFileChooser |
fc |
private java.lang.String |
lastDirProperty |
private boolean |
open |
static BooleanProperty |
PROP_USE_NATIVE_FILE_DIALOG
Property to enable use of native file dialogs.
|
Constructor and Description |
---|
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 |
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. |
private FileChooserManager |
doCreateFileChooser(boolean multiple,
java.lang.String title,
java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters,
javax.swing.filechooser.FileFilter defaultFilter,
java.lang.String extension,
int selectionMode,
boolean allTypes) |
AbstractFileChooser |
getFileChooser()
Replies the
AbstractFileChooser that has been previously created. |
java.lang.String |
getInitialDirectory()
Replies the initial directory used to construct the
AbstractFileChooser . |
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.Nothing happens if the dialog has not been created yet. When the user choses a file or directory, the lastDirProperty is updated to the chosen directory path. |
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 AbstractFileChooser fc
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)
private FileChooserManager doCreateFileChooser(boolean multiple, java.lang.String title, java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters, javax.swing.filechooser.FileFilter defaultFilter, java.lang.String extension, int selectionMode, boolean allTypes)
public final AbstractFileChooser openFileChooser()
AbstractFileChooser
that has been created. Nothing happens if it has not been created yet.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.