Class SwingFileChooser
- java.lang.Object
-
- org.openstreetmap.josm.gui.widgets.AbstractFileChooser
-
- org.openstreetmap.josm.gui.widgets.SwingFileChooser
-
public class SwingFileChooser extends AbstractFileChooser
File chooser based on the Swing'sJFileChooser
implementation.- Since:
- 7578
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.JFileChooser
jFileChooser
The JFileChooser which we use for this.-
Fields inherited from class org.openstreetmap.josm.gui.widgets.AbstractFileChooser
locale
-
-
Constructor Summary
Constructors Constructor Description SwingFileChooser(java.io.File file)
Constructs a newSwingFileChooser
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Adds a filter to the list of user choosable file filters.javax.swing.ActionMap
getActionMap()
Gets the list of action names.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 theAcceptAll 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 theJFileChooser
window's title bar.void
setFileFilter(javax.swing.filechooser.FileFilter cff)
Sets the current file filter.void
setFileSelectionMode(int selectionMode)
Sets theJFileChooser
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.-
Methods inherited from class org.openstreetmap.josm.gui.widgets.AbstractFileChooser
setDefaultLocale
-
-
-
-
Field Detail
-
jFileChooser
private final javax.swing.JFileChooser jFileChooser
The JFileChooser which we use for this.
-
-
Constructor Detail
-
SwingFileChooser
public SwingFileChooser(java.io.File file)
Constructs a newSwingFileChooser
.- Parameters:
file
- the current file/directory to point to
-
-
Method Detail
-
addChoosableFileFilter
public void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Description copied from class:AbstractFileChooser
Adds a filter to the list of user choosable file filters. For information on setting the file selection mode, seesetFileSelectionMode
.- Specified by:
addChoosableFileFilter
in classAbstractFileChooser
- Parameters:
filter
- theFileFilter
to add to the choosable file filter list- See Also:
AbstractFileChooser.getChoosableFileFilters()
,AbstractFileChooser.setFileSelectionMode(int)
-
getChoosableFileFilters
public javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
Description copied from class:AbstractFileChooser
Gets the list of user choosable file filters.- Specified by:
getChoosableFileFilters
in classAbstractFileChooser
- Returns:
- a
FileFilter
array containing all the choosable file filters - See Also:
AbstractFileChooser.addChoosableFileFilter(javax.swing.filechooser.FileFilter)
-
getCurrentDirectory
public java.io.File getCurrentDirectory()
Description copied from class:AbstractFileChooser
Returns the current directory.- Specified by:
getCurrentDirectory
in classAbstractFileChooser
- Returns:
- the current directory
- See Also:
AbstractFileChooser.setCurrentDirectory(java.io.File)
-
getFileFilter
public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from class:AbstractFileChooser
Returns the currently selected file filter.- Specified by:
getFileFilter
in classAbstractFileChooser
- Returns:
- the current file filter
- See Also:
AbstractFileChooser.setFileFilter(javax.swing.filechooser.FileFilter)
,AbstractFileChooser.addChoosableFileFilter(javax.swing.filechooser.FileFilter)
-
getSelectedFile
public java.io.File getSelectedFile()
Description copied from class:AbstractFileChooser
Returns the selected file. This can be set either by the programmer viasetSelectedFile
or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.- Specified by:
getSelectedFile
in classAbstractFileChooser
- Returns:
- the selected file
- See Also:
AbstractFileChooser.setSelectedFile(java.io.File)
-
getSelectedFiles
public java.io.File[] getSelectedFiles()
Description copied from class:AbstractFileChooser
Returns a list of selected files if the file chooser is set to allow multiple selection.- Specified by:
getSelectedFiles
in classAbstractFileChooser
- Returns:
- an array of selected files if the file chooser is set to allow multiple selection, or an empty array otherwise.
-
isMultiSelectionEnabled
public boolean isMultiSelectionEnabled()
Description copied from class:AbstractFileChooser
Returns true if multiple files can be selected.- Specified by:
isMultiSelectionEnabled
in classAbstractFileChooser
- Returns:
- true if multiple files can be selected
- See Also:
AbstractFileChooser.setMultiSelectionEnabled(boolean)
-
setAcceptAllFileFilterUsed
public void setAcceptAllFileFilterUsed(boolean b)
Description copied from class:AbstractFileChooser
Determines whether theAcceptAll FileFilter
is used as an available choice in the choosable filter list. If false, theAcceptAll
file filter is removed from the list of available file filters. If true, theAcceptAll
file filter will become the actively used file filter.- Specified by:
setAcceptAllFileFilterUsed
in classAbstractFileChooser
- Parameters:
b
- whether theAcceptAll FileFilter
is used as an available choice in the choosable filter list- See Also:
AbstractFileChooser.setFileFilter(javax.swing.filechooser.FileFilter)
-
setCurrentDirectory
public void setCurrentDirectory(java.io.File f)
Description copied from class:AbstractFileChooser
Sets the current directory. Passing innull
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 ascurrentDirectory
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.- Specified by:
setCurrentDirectory
in classAbstractFileChooser
- Parameters:
f
- the current directory to point to- See Also:
AbstractFileChooser.getCurrentDirectory()
-
setDialogTitle
public void setDialogTitle(java.lang.String title)
Description copied from class:AbstractFileChooser
Sets the string that goes in theJFileChooser
window's title bar.- Specified by:
setDialogTitle
in classAbstractFileChooser
- Parameters:
title
- the newString
for the title bar
-
setFileFilter
public void setFileFilter(javax.swing.filechooser.FileFilter cff)
Description copied from class:AbstractFileChooser
Sets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.- Specified by:
setFileFilter
in classAbstractFileChooser
- Parameters:
cff
- the new current file filter to use- See Also:
AbstractFileChooser.getFileFilter()
-
setFileSelectionMode
public void setFileSelectionMode(int selectionMode)
Description copied from class:AbstractFileChooser
Sets theJFileChooser
to allow the user to just select files, just select directories, or select both files and directories. The default isJFilesChooser.FILES_ONLY
.- Specified by:
setFileSelectionMode
in classAbstractFileChooser
- Parameters:
selectionMode
- the type of files to be displayed:- JFileChooser.FILES_ONLY
- JFileChooser.DIRECTORIES_ONLY
- JFileChooser.FILES_AND_DIRECTORIES
-
setMultiSelectionEnabled
public void setMultiSelectionEnabled(boolean multiple)
Description copied from class:AbstractFileChooser
Sets the file chooser to allow multiple file selections.- Specified by:
setMultiSelectionEnabled
in classAbstractFileChooser
- Parameters:
multiple
- true if multiple files may be selected- See Also:
AbstractFileChooser.isMultiSelectionEnabled()
-
setSelectedFile
public void setSelectedFile(java.io.File file)
Description copied from class:AbstractFileChooser
Sets the selected file. If the file's parent directory is not the current directory, changes the current directory to be the file's parent directory.- Specified by:
setSelectedFile
in classAbstractFileChooser
- Parameters:
file
- the selected file- See Also:
AbstractFileChooser.getSelectedFile()
-
showOpenDialog
public int showOpenDialog(java.awt.Component parent)
Description copied from class:AbstractFileChooser
Pops up an "Open File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.- Specified by:
showOpenDialog
in classAbstractFileChooser
- Parameters:
parent
- the parent component of the dialog, can benull
; seeshowDialog
for details- Returns:
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION if an error occurs or the dialog is dismissed
- See Also:
GraphicsEnvironment.isHeadless()
-
showSaveDialog
public int showSaveDialog(java.awt.Component parent)
Description copied from class:AbstractFileChooser
Pops up a "Save File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.- Specified by:
showSaveDialog
in classAbstractFileChooser
- Parameters:
parent
- the parent component of the dialog, can benull
; seeshowDialog
for details- Returns:
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION if an error occurs or the dialog is dismissed
- See Also:
GraphicsEnvironment.isHeadless()
-
getActionMap
public javax.swing.ActionMap getActionMap()
Description copied from class:AbstractFileChooser
Gets the list of action names.- Specified by:
getActionMap
in classAbstractFileChooser
- Returns:
- a
ActionMap
array containing all the action names
-
-