public class JFileChooserManager extends Object
JFileChooser
dialogs.
A simpler usage is to call the DiskAccessAction.createAndOpenFileChooser(boolean, boolean, java.lang.String)
methods.
Modifier and Type | Field and Description |
---|---|
private String |
curDir |
private JFileChooser |
fc |
private String |
lastDirProperty |
private boolean |
open |
Constructor and Description |
---|
JFileChooserManager(boolean open)
Creates a new
JFileChooserManager . |
JFileChooserManager(boolean open,
String lastDirProperty)
Creates a new
JFileChooserManager . |
JFileChooserManager(boolean open,
String lastDirProperty,
String defaultDir)
Creates a new
JFileChooserManager . |
Modifier and Type | Method and Description |
---|---|
JFileChooserManager |
createFileChooser()
Creates a new
JFileChooser with default settings. |
JFileChooserManager |
createFileChooser(boolean multiple,
String title,
Collection<? extends FileFilter> filters,
FileFilter defaultFilter,
int selectionMode)
Creates a new
JFileChooser with given settings for a collection of FileFilter s. |
JFileChooserManager |
createFileChooser(boolean multiple,
String title,
FileFilter filter,
int selectionMode)
Creates a new
JFileChooser with given settings for a single FileFilter . |
JFileChooserManager |
createFileChooser(boolean multiple,
String title,
String extension,
boolean allTypes,
int selectionMode)
Creates a new
JFileChooser with given settings for a file extension. |
private JFileChooserManager |
doCreateFileChooser(boolean multiple,
String title,
Collection<? extends FileFilter> filters,
FileFilter defaultFilter,
String extension,
int selectionMode,
boolean allTypes) |
JFileChooser |
getFileChooser()
Replies the
JFileChooser that has been previously created. |
String |
getInitialDirectory()
Replies the initial directory used to construct the
JFileChooser . |
JFileChooser |
openFileChooser()
Opens the
JFileChooser that has been created. |
JFileChooser |
openFileChooser(Component parent)
Opens the
JFileChooser that has been created and waits for the user to choose a file/directory, or cancel the dialog. |
private final boolean open
private final String lastDirProperty
private JFileChooser fc
public JFileChooserManager(boolean open)
JFileChooserManager
.open
- If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.createFileChooser()
public JFileChooserManager(boolean open, String lastDirProperty)
JFileChooserManager
.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 JFileChooser.
Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.createFileChooser()
public JFileChooserManager(boolean open, String lastDirProperty, String defaultDir)
JFileChooserManager
.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 JFileChooser.
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 JFileChooser if the lastDirProperty
property value is missing.createFileChooser()
public final JFileChooser getFileChooser()
JFileChooser
that has been previously created.JFileChooser
that has been previously created, or null
if it has not been created yet.createFileChooser()
public final String getInitialDirectory()
JFileChooser
.JFileChooser
.public final JFileChooserManager createFileChooser()
JFileChooser
with default settings. All files will be accepted.public final JFileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode)
JFileChooser
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 JFileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode)
JFileChooser
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 JFileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode)
JFileChooser
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 final JFileChooserManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes)
public final JFileChooser openFileChooser()
JFileChooser
that has been created. Nothing happens if it has not been created yet.JFileChooser
if the user effectively choses a file or directory. null
if the user cancelled the dialog.public JFileChooser openFileChooser(Component parent)
JFileChooser
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 JFileChooser. If null, uses Main.parent
.JFileChooser
if the user effectively choses a file or directory. null
if the user cancelled the dialog.