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,
                                  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,
                                  String lastDirProperty,
                                  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 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,
                                                          String title,
                                                          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​(String value)
        Builder method to set title property.
        Parameters:
        value - The string that goes in the dialog window's title bar
        Returns:
        this
      • defaultFilter

        public FileChooserManager defaultFilter​(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​(String value)
        Builder method to set extension property.
        Parameters:
        value - The file extension that will be selected as the default file filter
        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​(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​(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 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.