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'sJFileChooserimplementation.- Since:
- 7578
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.JFileChooserjFileChooserThe 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 voidaddChoosableFileFilter(javax.swing.filechooser.FileFilter filter)Adds a filter to the list of user choosable file filters.javax.swing.ActionMapgetActionMap()Gets the list of action names.javax.swing.filechooser.FileFilter[]getChoosableFileFilters()Gets the list of user choosable file filters.java.io.FilegetCurrentDirectory()Returns the current directory.javax.swing.filechooser.FileFiltergetFileFilter()Returns the currently selected file filter.java.io.FilegetSelectedFile()Returns the selected file.java.io.File[]getSelectedFiles()Returns a list of selected files if the file chooser is set to allow multiple selection.booleanisMultiSelectionEnabled()Returns true if multiple files can be selected.voidsetAcceptAllFileFilterUsed(boolean b)Determines whether theAcceptAll FileFilteris used as an available choice in the choosable filter list.voidsetCurrentDirectory(java.io.File f)Sets the current directory.voidsetDialogTitle(java.lang.String title)Sets the string that goes in theJFileChooserwindow's title bar.voidsetFileFilter(javax.swing.filechooser.FileFilter cff)Sets the current file filter.voidsetFileSelectionMode(int selectionMode)Sets theJFileChooserto allow the user to just select files, just select directories, or select both files and directories.voidsetMultiSelectionEnabled(boolean multiple)Sets the file chooser to allow multiple file selections.voidsetSelectedFile(java.io.File file)Sets the selected file.intshowOpenDialog(java.awt.Component parent)Pops up an "Open File" file chooser dialog.intshowSaveDialog(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:AbstractFileChooserAdds a filter to the list of user choosable file filters. For information on setting the file selection mode, seesetFileSelectionMode.- Specified by:
addChoosableFileFilterin classAbstractFileChooser- Parameters:
filter- theFileFilterto 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:AbstractFileChooserGets the list of user choosable file filters.- Specified by:
getChoosableFileFiltersin classAbstractFileChooser- Returns:
- a
FileFilterarray containing all the choosable file filters - See Also:
AbstractFileChooser.addChoosableFileFilter(javax.swing.filechooser.FileFilter)
-
getCurrentDirectory
public java.io.File getCurrentDirectory()
Description copied from class:AbstractFileChooserReturns the current directory.- Specified by:
getCurrentDirectoryin classAbstractFileChooser- Returns:
- the current directory
- See Also:
AbstractFileChooser.setCurrentDirectory(java.io.File)
-
getFileFilter
public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from class:AbstractFileChooserReturns the currently selected file filter.- Specified by:
getFileFilterin 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:AbstractFileChooserReturns the selected file. This can be set either by the programmer viasetSelectedFileor 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:
getSelectedFilein classAbstractFileChooser- Returns:
- the selected file
- See Also:
AbstractFileChooser.setSelectedFile(java.io.File)
-
getSelectedFiles
public java.io.File[] getSelectedFiles()
Description copied from class:AbstractFileChooserReturns a list of selected files if the file chooser is set to allow multiple selection.- Specified by:
getSelectedFilesin 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:AbstractFileChooserReturns true if multiple files can be selected.- Specified by:
isMultiSelectionEnabledin classAbstractFileChooser- Returns:
- true if multiple files can be selected
- See Also:
AbstractFileChooser.setMultiSelectionEnabled(boolean)
-
setAcceptAllFileFilterUsed
public void setAcceptAllFileFilterUsed(boolean b)
Description copied from class:AbstractFileChooserDetermines whether theAcceptAll FileFilteris used as an available choice in the choosable filter list. If false, theAcceptAllfile filter is removed from the list of available file filters. If true, theAcceptAllfile filter will become the actively used file filter.- Specified by:
setAcceptAllFileFilterUsedin classAbstractFileChooser- Parameters:
b- whether theAcceptAll FileFilteris 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:AbstractFileChooserSets the current directory. Passing innullsets 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 ascurrentDirectoryis 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:
setCurrentDirectoryin 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:AbstractFileChooserSets the string that goes in theJFileChooserwindow's title bar.- Specified by:
setDialogTitlein classAbstractFileChooser- Parameters:
title- the newStringfor the title bar
-
setFileFilter
public void setFileFilter(javax.swing.filechooser.FileFilter cff)
Description copied from class:AbstractFileChooserSets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.- Specified by:
setFileFilterin classAbstractFileChooser- Parameters:
cff- the new current file filter to use- See Also:
AbstractFileChooser.getFileFilter()
-
setFileSelectionMode
public void setFileSelectionMode(int selectionMode)
Description copied from class:AbstractFileChooserSets theJFileChooserto allow the user to just select files, just select directories, or select both files and directories. The default isJFilesChooser.FILES_ONLY.- Specified by:
setFileSelectionModein 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:AbstractFileChooserSets the file chooser to allow multiple file selections.- Specified by:
setMultiSelectionEnabledin 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:AbstractFileChooserSets 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:
setSelectedFilein classAbstractFileChooser- Parameters:
file- the selected file- See Also:
AbstractFileChooser.getSelectedFile()
-
showOpenDialog
public int showOpenDialog(java.awt.Component parent)
Description copied from class:AbstractFileChooserPops 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:
showOpenDialogin classAbstractFileChooser- Parameters:
parent- the parent component of the dialog, can benull; seeshowDialogfor 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:AbstractFileChooserPops 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:
showSaveDialogin classAbstractFileChooser- Parameters:
parent- the parent component of the dialog, can benull; seeshowDialogfor 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:AbstractFileChooserGets the list of action names.- Specified by:
getActionMapin classAbstractFileChooser- Returns:
- a
ActionMaparray containing all the action names
-
-