package editor.gui.generic;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 * This is a {@link JFileChooser} that confirms first if a file should be overwritten.
 *
 * @author Alec Roelke
 */
@SuppressWarnings("serial")
public class OverwriteFileChooser extends JFileChooser
{
    /**
     * Create a new OverwriteFileChooser.
     */
    public OverwriteFileChooser()
    {
        super();
    }

    /**
     * Create a new OverwriteFileChooser that starts in the given path
     *
     * @param currentDirectoryPath path to start in
     */
    public OverwriteFileChooser(String currentDirectoryPath)
    {
        super(currentDirectoryPath);
    }

    @Override
    public void approveSelection()
    {
        if (getSelectedFile().exists() && getDialogType() == SAVE_DIALOG)
        {
            switch (JOptionPane.showConfirmDialog(this, "File already exists.  Overwrite?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION))
            {
            case JOptionPane.YES_OPTION:
                super.approveSelection();
                return;
            case JOptionPane.NO_OPTION:
                return;
            case JOptionPane.CANCEL_OPTION:
                cancelSelection();
                return;
            case JOptionPane.CLOSED_OPTION:
                return;
            }
        }
        super.approveSelection();
    }
}

@@ -22,16 +22,63 @@
 neric;%0A%0A
+import java.io.File;%0Aimport java.util.Arrays;%0A%0A
 import j
@@ -133,16 +133,72 @@
 ionPane;
+%0Aimport javax.swing.filechooser.FileNameExtensionFilter;
 %0A%0A/**%0A *
@@ -772,24 +772,914 @@
 th);%0A    %7D%0A%0A
+    /**%0A     * %7B@inheritDoc%7D%0A     * %3Cp%3E%0A     * If the file name doesn't have an extension specified by the file filter, add it.%0A     */%0A    @Override%0A    public File getSelectedFile()%0A    %7B%0A        if (getFileFilter() instanceof FileNameExtensionFilter)%0A        %7B%0A            FileNameExtensionFilter filter = (FileNameExtensionFilter)getFileFilter();%0A            String fname = super.getSelectedFile().getAbsolutePath();%0A            if (Arrays.stream(filter.getExtensions()).noneMatch((ext) -%3E fname.endsWith(%22.%22 + ext)))%0A                return new File(fname + %22.%22 + filter.getExtensions()%5B0%5D);%0A        %7D%0A        return super.getSelectedFile();%0A    %7D%0A%0A    /**%0A     * %7B@inheritDoc%7D%0A     * %3Cp%3E%0A     * If the file already exists, make sure the user wants to replace it first. If not,%0A     * allow them to make another choice or close the dialog depending on what was%0A     * selected.%0A     */%0A
     @Overrid

Add default extension handling