org.openstreetmap.josm.gui.widgets
Class JFileChooserManager

java.lang.Object
  extended by org.openstreetmap.josm.gui.widgets.JFileChooserManager

public class JFileChooserManager
extends java.lang.Object

A chained utility class used to create and open JFileChooser dialogs.
Use only this class if you need to control specifically your JFileChooser dialog.

A simpler usage is to call the DiskAccessAction.createAndOpenFileChooser(boolean, boolean, java.lang.String) methods.

Since:
5438

Field Summary
private  java.lang.String curDir
           
private  javax.swing.JFileChooser fc
           
private  java.lang.String lastDirProperty
           
private  boolean open
           
 
Constructor Summary
JFileChooserManager(boolean open)
          Creates a new JFileChooserManager.
JFileChooserManager(boolean open, java.lang.String lastDirProperty)
          Creates a new JFileChooserManager.
JFileChooserManager(boolean open, java.lang.String lastDirProperty, java.lang.String defaultDir)
          Creates a new JFileChooserManager.
 
Method Summary
 JFileChooserManager createFileChooser()
          Creates a new JFileChooser with default settings.
 JFileChooserManager 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 new JFileChooser with given settings for a collection of FileFilters.
 JFileChooserManager createFileChooser(boolean multiple, java.lang.String title, javax.swing.filechooser.FileFilter filter, int selectionMode)
          Creates a new JFileChooser with given settings for a single FileFilter.
 JFileChooserManager createFileChooser(boolean multiple, java.lang.String title, java.lang.String extension, boolean allTypes, int selectionMode)
          Creates a new JFileChooser with given settings for a file extension.
private  JFileChooserManager doCreateFileChooser(boolean multiple, java.lang.String title, java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters, javax.swing.filechooser.FileFilter defaultFilter, java.lang.String extension, int selectionMode, boolean allTypes)
           
 javax.swing.JFileChooser getFileChooser()
          Replies the JFileChooser that has been previously created.
 java.lang.String getInitialDirectory()
          Replies the initial directory used to construct the JFileChooser.
 javax.swing.JFileChooser openFileChooser()
          Opens the JFileChooser that has been created.
 javax.swing.JFileChooser openFileChooser(java.awt.Component parent)
          Opens the JFileChooser that has been created and waits for the user to choose a file/directory, or cancel the dialog.
Nothing happens if the dialog has not been created yet.
When the user choses a file or directory, the lastDirProperty is updated to the chosen directory path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

open

private final boolean open

lastDirProperty

private final java.lang.String lastDirProperty

curDir

private final java.lang.String curDir

fc

private javax.swing.JFileChooser fc
Constructor Detail

JFileChooserManager

public JFileChooserManager(boolean open)
Creates a new JFileChooserManager.

Parameters:
open - If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
See Also:
createFileChooser()

JFileChooserManager

public JFileChooserManager(boolean open,
                           java.lang.String lastDirProperty)
Creates a new JFileChooserManager.

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 JFileChooser. Then, if the user effetively choses a file or a directory, this property will be updated to the directory path.
See Also:
createFileChooser()

JFileChooserManager

public JFileChooserManager(boolean open,
                           java.lang.String lastDirProperty,
                           java.lang.String defaultDir)
Creates a new JFileChooserManager.

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 JFileChooser. Then, if the user effetively choses 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.
See Also:
createFileChooser()
Method Detail

getFileChooser

public final javax.swing.JFileChooser getFileChooser()
Replies the JFileChooser that has been previously created.

Returns:
The JFileChooser that has been previously created, or null if it has not been created yet.
See Also:
createFileChooser()

getInitialDirectory

public final java.lang.String getInitialDirectory()
Replies the initial directory used to construct the JFileChooser.

Returns:
The initial directory used to construct the JFileChooser.

createFileChooser

public final JFileChooserManager createFileChooser()
Creates a new JFileChooser with default settings. All files will be accepted.

Returns:
this

createFileChooser

public final JFileChooserManager createFileChooser(boolean multiple,
                                                   java.lang.String title,
                                                   javax.swing.filechooser.FileFilter filter,
                                                   int selectionMode)
Creates a new JFileChooser with given settings for a single FileFilter.

Parameters:
multiple - If true, makes the dialog allow multiple file selections
title - The string that goes in the dialog window's title bar
filter - The only file filter that will be proposed by the dialog
selectionMode - 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)
  • Returns:
    this
    See Also:
    DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)

    createFileChooser

    public final JFileChooserManager 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 new JFileChooser with given settings for a collection of FileFilters.

    Parameters:
    multiple - If true, makes the dialog allow multiple file selections
    title - The string that goes in the dialog window's title bar
    filters - The file filters that will be proposed by the dialog
    defaultFilter - The file filter that will be selected by default
    selectionMode - 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)
  • Returns:
    this
    See Also:
    DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)

    createFileChooser

    public final JFileChooserManager createFileChooser(boolean multiple,
                                                       java.lang.String title,
                                                       java.lang.String extension,
                                                       boolean allTypes,
                                                       int selectionMode)
    Creates a new JFileChooser with given settings for a file extension.

    Parameters:
    multiple - If true, makes the dialog allow multiple file selections
    title - The string that goes in the dialog window's title bar
    extension - The file extension that will be selected as the default file filter
    allTypes - 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 proposed
    selectionMode - 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)
  • Returns:
    this
    See Also:
    DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)

    doCreateFileChooser

    private final JFileChooserManager doCreateFileChooser(boolean multiple,
                                                          java.lang.String title,
                                                          java.util.Collection<? extends javax.swing.filechooser.FileFilter> filters,
                                                          javax.swing.filechooser.FileFilter defaultFilter,
                                                          java.lang.String extension,
                                                          int selectionMode,
                                                          boolean allTypes)

    openFileChooser

    public final javax.swing.JFileChooser openFileChooser()
    Opens the JFileChooser that has been created. Nothing happens if it has not been created yet.

    Returns:
    the JFileChooser if the user effectively choses a file or directory. null if the user cancelled the dialog.

    openFileChooser

    public javax.swing.JFileChooser openFileChooser(java.awt.Component parent)
    Opens the JFileChooser that has been created and waits for the user to choose a file/directory, or cancel the dialog.
    Nothing happens if the dialog has not been created yet.
    When the user choses a file or directory, the lastDirProperty is updated to the chosen directory path.

    Parameters:
    parent - The Component used as the parent of the JFileChooser. If null, uses Main.parent.
    Returns:
    the JFileChooser if the user effectively choses a file or directory. null if the user cancelled the dialog.


    JOSM