private static File chooseFileToWrite(Component owner, FileFilter filter, String extension, File pathToNavigateTo, String fileName) {

        File result = null;

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileFilter(filter);
        if (pathToNavigateTo != null) {
            fileChooser.setCurrentDirectory(pathToNavigateTo);
        }
        if (fileName != null) {
            fileChooser.setSelectedFile(new File(fileName));
        }

        int returnVal = fileChooser.showSaveDialog(owner);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            result = fileChooser.getSelectedFile();

            if (FileSelectorUtility.getExtension(result) == null) {
                result = new File(result.getAbsolutePath() + extension);
            }

            if (result != null && result.exists()) {
                int answer = JOptionPane.showConfirmDialog(owner,
                        "This file already exists. Overwrite?", "File exists",
                        JOptionPane.YES_NO_OPTION);
                if (answer == JOptionPane.NO_OPTION) {
                    result = null;
                }
            }
        }
        return result;
    }