Class AbstractFileChooser
- java.lang.Object
-
- org.openstreetmap.josm.gui.widgets.AbstractFileChooser
-
- Direct Known Subclasses:
NativeFileChooser
,SwingFileChooser
public abstract class AbstractFileChooser extends java.lang.Object
Abstract class to allow different file chooser implementations.- Since:
- 7578
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Locale
locale
The locale for both implementations
-
Constructor Summary
Constructors Constructor Description AbstractFileChooser()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Adds a filter to the list of user choosable file filters.abstract javax.swing.ActionMap
getActionMap()
Gets the list of action names.abstract javax.swing.filechooser.FileFilter[]
getChoosableFileFilters()
Gets the list of user choosable file filters.abstract java.io.File
getCurrentDirectory()
Returns the current directory.abstract javax.swing.filechooser.FileFilter
getFileFilter()
Returns the currently selected file filter.abstract java.io.File
getSelectedFile()
Returns the selected file.abstract java.io.File[]
getSelectedFiles()
Returns a list of selected files if the file chooser is set to allow multiple selection.abstract boolean
isMultiSelectionEnabled()
Returns true if multiple files can be selected.abstract void
setAcceptAllFileFilterUsed(boolean b)
Determines whether theAcceptAll FileFilter
is used as an available choice in the choosable filter list.abstract void
setCurrentDirectory(java.io.File dir)
Sets the current directory.static void
setDefaultLocale(java.util.Locale l)
Sets the default locale for all implementations.abstract void
setDialogTitle(java.lang.String title)
Sets the string that goes in theJFileChooser
window's title bar.abstract void
setFileFilter(javax.swing.filechooser.FileFilter filter)
Sets the current file filter.abstract void
setFileSelectionMode(int selectionMode)
Sets theJFileChooser
to allow the user to just select files, just select directories, or select both files and directories.abstract void
setMultiSelectionEnabled(boolean multiple)
Sets the file chooser to allow multiple file selections.abstract void
setSelectedFile(java.io.File file)
Sets the selected file.abstract int
showOpenDialog(java.awt.Component parent)
Pops up an "Open File" file chooser dialog.abstract int
showSaveDialog(java.awt.Component parent)
Pops up a "Save File" file chooser dialog.
-
-
-
Field Detail
-
locale
protected static volatile java.util.Locale locale
The locale for both implementations
-
-
Constructor Detail
-
AbstractFileChooser
public AbstractFileChooser()
-
-
Method Detail
-
setDefaultLocale
public static void setDefaultLocale(java.util.Locale l)
Sets the default locale for all implementations.- Parameters:
l
- locale
-
addChoosableFileFilter
public abstract void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Adds a filter to the list of user choosable file filters. For information on setting the file selection mode, seesetFileSelectionMode
.- Parameters:
filter
- theFileFilter
to add to the choosable file filter list- See Also:
getChoosableFileFilters()
,setFileSelectionMode(int)
-
getChoosableFileFilters
public abstract javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
Gets the list of user choosable file filters.- Returns:
- a
FileFilter
array containing all the choosable file filters - See Also:
addChoosableFileFilter(javax.swing.filechooser.FileFilter)
-
getCurrentDirectory
public abstract java.io.File getCurrentDirectory()
Returns the current directory.- Returns:
- the current directory
- See Also:
setCurrentDirectory(java.io.File)
-
getFileFilter
public abstract javax.swing.filechooser.FileFilter getFileFilter()
Returns the currently selected file filter.- Returns:
- the current file filter
- See Also:
setFileFilter(javax.swing.filechooser.FileFilter)
,addChoosableFileFilter(javax.swing.filechooser.FileFilter)
-
getSelectedFile
public abstract java.io.File getSelectedFile()
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.- Returns:
- the selected file
- See Also:
setSelectedFile(java.io.File)
-
getSelectedFiles
public abstract java.io.File[] getSelectedFiles()
Returns a list of selected files if the file chooser is set to allow multiple selection.- Returns:
- an array of selected files if the file chooser is set to allow multiple selection, or an empty array otherwise.
-
isMultiSelectionEnabled
public abstract boolean isMultiSelectionEnabled()
Returns true if multiple files can be selected.- Returns:
- true if multiple files can be selected
- See Also:
setMultiSelectionEnabled(boolean)
-
setAcceptAllFileFilterUsed
public abstract void setAcceptAllFileFilterUsed(boolean b)
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.- Parameters:
b
- whether theAcceptAll FileFilter
is used as an available choice in the choosable filter list- See Also:
setFileFilter(javax.swing.filechooser.FileFilter)
-
setCurrentDirectory
public abstract void setCurrentDirectory(java.io.File dir)
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.- Parameters:
dir
- the current directory to point to- See Also:
getCurrentDirectory()
-
setDialogTitle
public abstract void setDialogTitle(java.lang.String title)
Sets the string that goes in theJFileChooser
window's title bar.- Parameters:
title
- the newString
for the title bar
-
setFileFilter
public abstract void setFileFilter(javax.swing.filechooser.FileFilter filter)
Sets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.- Parameters:
filter
- the new current file filter to use- See Also:
getFileFilter()
-
setFileSelectionMode
public abstract void setFileSelectionMode(int selectionMode)
Sets theJFileChooser
to allow the user to just select files, just select directories, or select both files and directories. The default isJFilesChooser.FILES_ONLY
.- Parameters:
selectionMode
- the type of files to be displayed:- JFileChooser.FILES_ONLY
- JFileChooser.DIRECTORIES_ONLY
- JFileChooser.FILES_AND_DIRECTORIES
- Throws:
java.lang.IllegalArgumentException
- ifmode
is an illegal file selection mode
-
setMultiSelectionEnabled
public abstract void setMultiSelectionEnabled(boolean multiple)
Sets the file chooser to allow multiple file selections.- Parameters:
multiple
- true if multiple files may be selected- See Also:
isMultiSelectionEnabled()
-
setSelectedFile
public abstract void setSelectedFile(java.io.File file)
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.- Parameters:
file
- the selected file- See Also:
getSelectedFile()
-
showOpenDialog
public abstract int showOpenDialog(java.awt.Component parent)
Pops up an "Open File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.- 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
- Throws:
java.awt.HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
showSaveDialog
public abstract int showSaveDialog(java.awt.Component parent)
Pops up a "Save File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.- 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
- Throws:
java.awt.HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
getActionMap
public abstract javax.swing.ActionMap getActionMap()
Gets the list of action names.- Returns:
- a
ActionMap
array containing all the action names - Since:
- 18113
-
-