Class FileChooserManager
- java.lang.Object
-
- org.openstreetmap.josm.gui.widgets.FileChooserManager
-
public class FileChooserManager extends java.lang.Object
A chained utility class used to create and openAbstractFileChooserdialogs.
Use only this class if you need to control specifically your AbstractFileChooser dialog.
A simpler usage is to call the
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, java.lang.String)methods.- Since:
- 5438 (creation), 7578 (rename)
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Predicate<ExtensionFileFilter>additionalTypesprivate java.lang.StringcurDirprivate javax.swing.filechooser.FileFilterdefaultFilterprivate java.lang.Stringextensionprivate AbstractFileChooserfcprivate java.io.Filefileprivate java.util.Collection<? extends javax.swing.filechooser.FileFilter>filtersprivate java.lang.StringlastDirPropertyprivate booleanmultipleprivate booleanopenstatic BooleanPropertyPROP_USE_DETAILS_VIEW_FILE_DIALOGProperty to use the details view in file dialogs.static BooleanPropertyPROP_USE_NATIVE_FILE_DIALOGProperty to enable use of native file dialogs.private intselectionModeprivate java.lang.Stringtitle
-
Constructor Summary
Constructors Constructor Description FileChooserManager()Creates a newFileChooserManagerwith default values.FileChooserManager(boolean open)Creates a newFileChooserManager.FileChooserManager(boolean open, java.lang.String lastDirProperty)Creates a newFileChooserManager.FileChooserManager(boolean open, java.lang.String lastDirProperty, java.lang.String defaultDir)Creates a newFileChooserManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileChooserManageradditionalTypes(java.util.function.Predicate<ExtensionFileFilter> value)Builder method to setadditionalTypesproperty.FileChooserManagerallTypes(boolean value)Builder method to setallTypesproperty.FileChooserManagercreateFileChooser()Creates a newAbstractFileChooserwith default settings.FileChooserManagercreateFileChooser(boolean multiple, java.lang.String title, java.lang.String extension, boolean allTypes, int selectionMode)Creates a newAbstractFileChooserwith given settings for a file extension.FileChooserManagercreateFileChooser(boolean multiple, java.lang.String title, java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters, javax.swing.filechooser.FileFilter defaultFilter, int selectionMode)Creates a newAbstractFileChooserwith given settings for a collection ofFileFilters.FileChooserManagercreateFileChooser(boolean multiple, java.lang.String title, javax.swing.filechooser.FileFilter filter, int selectionMode)Creates a newAbstractFileChooserwith given settings for a singleFileFilter.FileChooserManagerdefaultFilter(javax.swing.filechooser.FileFilter value)Builder method to setdefaultFilterproperty.FileChooserManagerdoCreateFileChooser()BuildsFileChooserManagerobject using properties set by builder methods or default values.FileChooserManagerextension(java.lang.String value)Builder method to setextensionproperty.FileChooserManagerfile(java.io.File value)Builder method to setfileproperty.FileChooserManagerfilters(java.util.Collection<? extends javax.swing.filechooser.FileFilter> value)Builder method to setfiltersproperty.AbstractFileChoosergetFileChooser()Replies theAbstractFileChooserthat has been previously created.java.io.FilegetFileForSave()Opens the file chooser dialog, then checks if filename has the given extension.java.lang.StringgetInitialDirectory()Replies the initial directory used to construct theAbstractFileChooser.FileChooserManagermultiple(boolean value)Builder method to setmultipleproperty.AbstractFileChooseropenFileChooser()Opens theAbstractFileChooserthat has been created.AbstractFileChooseropenFileChooser(java.awt.Component parent)Opens theAbstractFileChooserthat has been created and waits for the user to choose a file/directory, or cancel the dialog.
When the user chooses a file or directory, thelastDirPropertyis updated to the chosen directory path.FileChooserManagerselectionMode(int value)Builder method to setselectionModeproperty.FileChooserManagertitle(java.lang.String value)Builder method to settitleproperty.
-
-
-
Field Detail
-
PROP_USE_NATIVE_FILE_DIALOG
public static final BooleanProperty PROP_USE_NATIVE_FILE_DIALOG
Property to enable use of native file dialogs.
-
PROP_USE_DETAILS_VIEW_FILE_DIALOG
public static final BooleanProperty PROP_USE_DETAILS_VIEW_FILE_DIALOG
Property to use the details view in file dialogs.
-
open
private final boolean open
-
lastDirProperty
private final java.lang.String lastDirProperty
-
curDir
private final java.lang.String curDir
-
multiple
private boolean multiple
-
title
private java.lang.String title
-
filters
private java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters
-
defaultFilter
private javax.swing.filechooser.FileFilter defaultFilter
-
selectionMode
private int selectionMode
-
extension
private java.lang.String extension
-
additionalTypes
private java.util.function.Predicate<ExtensionFileFilter> additionalTypes
-
file
private java.io.File file
-
fc
private AbstractFileChooser fc
-
-
Constructor Detail
-
FileChooserManager
public FileChooserManager()
Creates a newFileChooserManagerwith default values.- See Also:
createFileChooser()
-
FileChooserManager
public FileChooserManager(boolean open)
Creates a newFileChooserManager.- Parameters:
open- If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.- See Also:
createFileChooser()
-
FileChooserManager
public FileChooserManager(boolean open, java.lang.String lastDirProperty)
Creates a newFileChooserManager.- Parameters:
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.- See Also:
createFileChooser()
-
FileChooserManager
public FileChooserManager(boolean open, java.lang.String lastDirProperty, java.lang.String defaultDir)
Creates a newFileChooserManager.- Parameters:
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 thelastDirPropertyproperty value is missing.- See Also:
createFileChooser()
-
-
Method Detail
-
getFileChooser
public final AbstractFileChooser getFileChooser()
Replies theAbstractFileChooserthat has been previously created.- Returns:
- The
AbstractFileChooserthat has been previously created, ornullif it has not been created yet. - See Also:
createFileChooser()
-
getInitialDirectory
public final java.lang.String getInitialDirectory()
Replies the initial directory used to construct theAbstractFileChooser.- Returns:
- The initial directory used to construct the
AbstractFileChooser.
-
createFileChooser
public final FileChooserManager createFileChooser()
Creates a newAbstractFileChooserwith default settings. All files will be accepted.- Returns:
- this
-
createFileChooser
public final FileChooserManager createFileChooser(boolean multiple, java.lang.String title, javax.swing.filechooser.FileFilter filter, int selectionMode)
Creates a newAbstractFileChooserwith given settings for a singleFileFilter.- Parameters:
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:- just select files (
JFileChooser.FILES_ONLY) - just select directories (
JFileChooser.DIRECTORIES_ONLY) - select both files and directories (
JFileChooser.FILES_AND_DIRECTORIES)
- just select files (
- Returns:
- this
- See Also:
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
-
createFileChooser
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)
Creates a newAbstractFileChooserwith given settings for a collection ofFileFilters.- Parameters:
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:- just select files (
JFileChooser.FILES_ONLY) - just select directories (
JFileChooser.DIRECTORIES_ONLY) - select both files and directories (
JFileChooser.FILES_AND_DIRECTORIES)
- just select files (
- Returns:
- this
- See Also:
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
-
createFileChooser
public final FileChooserManager createFileChooser(boolean multiple, java.lang.String title, java.lang.String extension, boolean allTypes, int selectionMode)
Creates a newAbstractFileChooserwith given settings for a file extension.- Parameters:
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 includeextensionwill be proposedselectionMode- The selection mode that allows the user to:- just select files (
JFileChooser.FILES_ONLY) - just select directories (
JFileChooser.DIRECTORIES_ONLY) - select both files and directories (
JFileChooser.FILES_AND_DIRECTORIES)
- just select files (
- Returns:
- this
- See Also:
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
-
multiple
public FileChooserManager multiple(boolean value)
Builder method to setmultipleproperty.- Parameters:
value- If true, makes the dialog allow multiple file selections- Returns:
- this
-
title
public FileChooserManager title(java.lang.String value)
Builder method to settitleproperty.- Parameters:
value- The string that goes in the dialog window's title bar- Returns:
- this
-
filters
public FileChooserManager filters(java.util.Collection<? extends javax.swing.filechooser.FileFilter> value)
Builder method to setfiltersproperty.- Parameters:
value- The file filters that will be proposed by the dialog- Returns:
- this
-
defaultFilter
public FileChooserManager defaultFilter(javax.swing.filechooser.FileFilter value)
Builder method to setdefaultFilterproperty.- Parameters:
value- The file filter that will be selected by default- Returns:
- this
-
selectionMode
public FileChooserManager selectionMode(int value)
Builder method to setselectionModeproperty.- Parameters:
value- The selection mode that allows the user to:- just select files (
JFileChooser.FILES_ONLY) - just select directories (
JFileChooser.DIRECTORIES_ONLY) - select both files and directories (
JFileChooser.FILES_AND_DIRECTORIES)
- just select files (
- Returns:
- this
-
extension
public FileChooserManager extension(java.lang.String value)
Builder method to setextensionproperty.- Parameters:
value- The file extension that will be selected as the default file filter- Returns:
- this
-
additionalTypes
public FileChooserManager additionalTypes(java.util.function.Predicate<ExtensionFileFilter> value)
Builder method to setadditionalTypesproperty.- Parameters:
value- matching types will additionally be added to the "file type" combobox.- Returns:
- this
-
allTypes
public FileChooserManager allTypes(boolean value)
Builder method to setallTypesproperty.- Parameters:
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 includeextensionwill be proposed- Returns:
- this
-
file
public FileChooserManager file(java.io.File value)
Builder method to setfileproperty.- Parameters:
value-Fileobject with default filename- Returns:
- this
-
doCreateFileChooser
public FileChooserManager doCreateFileChooser()
BuildsFileChooserManagerobject using properties set by builder methods or default values.- Returns:
- this
-
openFileChooser
public final AbstractFileChooser openFileChooser()
Opens theAbstractFileChooserthat has been created.- Returns:
- the
AbstractFileChooserif the user effectively chooses a file or directory.nullif the user cancelled the dialog.
-
openFileChooser
public AbstractFileChooser openFileChooser(java.awt.Component parent)
Opens theAbstractFileChooserthat has been created and waits for the user to choose a file/directory, or cancel the dialog.
When the user chooses a file or directory, thelastDirPropertyis updated to the chosen directory path.- Parameters:
parent- The Component used as the parent of the AbstractFileChooser. If null, usesMainApplication.getMainFrame().- Returns:
- the
AbstractFileChooserif the user effectively chooses a file or directory.nullif the user cancelled the dialog.
-
getFileForSave
public java.io.File getFileForSave()
Opens the file chooser dialog, then checks if filename has the given extension. If not, adds the extension and asks for overwrite if filename exists.- Returns:
- the
Fileornullif the user cancelled the dialog.
-
-