Class FileChooserManager

    • Constructor Detail

      • FileChooserManager

        public FileChooserManager​(boolean open)
        Creates a new FileChooserManager.
        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 new FileChooserManager.
        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 new FileChooserManager.
        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 the lastDirProperty property value is missing.
        See Also:
        createFileChooser()
    • Method Detail

      • getFileChooser

        public final AbstractFileChooser getFileChooser()
        Replies the AbstractFileChooser that has been previously created.
        Returns:
        The AbstractFileChooser 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 AbstractFileChooser.
        Returns:
        The initial directory used to construct the AbstractFileChooser.
      • createFileChooser

        public final FileChooserManager createFileChooser​(boolean multiple,
                                                          java.lang.String title,
                                                          javax.swing.filechooser.FileFilter filter,
                                                          int selectionMode)
        Creates a new AbstractFileChooser 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 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 new AbstractFileChooser 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 FileChooserManager createFileChooser​(boolean multiple,
                                                          java.lang.String title,
                                                          java.lang.String extension,
                                                          boolean allTypes,
                                                          int selectionMode)
        Creates a new AbstractFileChooser 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)
      • multiple

        public FileChooserManager multiple​(boolean value)
        Builder method to set multiple property.
        Parameters:
        value - If true, makes the dialog allow multiple file selections
        Returns:
        this
      • title

        public FileChooserManager title​(java.lang.String value)
        Builder method to set title property.
        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 set filters property.
        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 set defaultFilter property.
        Parameters:
        value - The file filter that will be selected by default
        Returns:
        this
      • selectionMode

        public FileChooserManager selectionMode​(int value)
        Builder method to set selectionMode property.
        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)
        Returns:
        this
      • extension

        public FileChooserManager extension​(java.lang.String value)
        Builder method to set extension property.
        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 set additionalTypes property.
        Parameters:
        value - matching types will additionally be added to the "file type" combobox.
        Returns:
        this
      • allTypes

        public FileChooserManager allTypes​(boolean value)
        Builder method to set allTypes property.
        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 include extension will be proposed
        Returns:
        this
      • file

        public FileChooserManager file​(java.io.File value)
        Builder method to set file property.
        Parameters:
        value - File object with default filename
        Returns:
        this
      • openFileChooser

        public final AbstractFileChooser openFileChooser()
        Opens the AbstractFileChooser that has been created.
        Returns:
        the AbstractFileChooser if the user effectively chooses a file or directory. null if the user cancelled the dialog.
      • openFileChooser

        public AbstractFileChooser openFileChooser​(java.awt.Component parent)
        Opens the AbstractFileChooser that 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, the lastDirProperty is updated to the chosen directory path.
        Parameters:
        parent - The Component used as the parent of the AbstractFileChooser. If null, uses MainApplication.getMainFrame().
        Returns:
        the AbstractFileChooser if the user effectively chooses a file or directory.null if 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 File or null if the user cancelled the dialog.