Changeset 5456 in josm


Ignore:
Timestamp:
2012-08-19T00:51:01+02:00 (7 years ago)
Author:
Don-vip
Message:

Restrict GPX "save as" and "export" dialogs to GPX FileFilter

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java

    r5266 r5456  
    1919import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2020import org.openstreetmap.josm.io.FileExporter;
     21import org.openstreetmap.josm.io.GpxImporter;
    2122import org.openstreetmap.josm.tools.CheckParameterUtil;
    2223import org.openstreetmap.josm.tools.Shortcut;
     
    7374            throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
    7475
    75         File file = createAndOpenSaveFileChooser(tr("Export GPX file"), "gpx");
     76        File file = createAndOpenSaveFileChooser(tr("Export GPX file"), GpxImporter.FILE_FILTER);
    7677        if (file == null)
    7778            return;
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r5438 r5456  
    2323import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2424import org.openstreetmap.josm.io.FileExporter;
     25import org.openstreetmap.josm.io.GpxImporter;
    2526import org.openstreetmap.josm.tools.Shortcut;
    2627
     
    142143            return createAndOpenSaveFileChooser(tr("Save OSM file"), "osm");
    143144        else if (layer instanceof GpxLayer)
    144             return createAndOpenSaveFileChooser(tr("Save GPX file"), "gpx");
     145            return createAndOpenSaveFileChooser(tr("Save GPX file"), GpxImporter.FILE_FILTER);
    145146        return createAndOpenSaveFileChooser(tr("Save Layer"), "lay");
    146147    }
     
    181182    }
    182183
     184    /**
     185     * Creates a new "Save" dialog for a single {@link ExtensionFileFilter} and makes it visible.<br/>
     186     * When the user has chosen a file, checks the file extension, and confirms overwrite if needed.
     187     *
     188     * @param title The dialog title
     189     * @param filter The dialog file filter
     190     * @return The output {@code File}
     191     * @since 5456
     192     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
     193     */
     194    public static File createAndOpenSaveFileChooser(String title, ExtensionFileFilter filter) {
     195        JFileChooser fc = createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, null);
     196        return checkFileAndConfirmOverWrite(fc, filter.getDefaultExtension());
     197    }
     198
     199    /**
     200     * Creates a new "Save" dialog for a given file extension and makes it visible.<br/>
     201     * When the user has chosen a file, checks the file extension, and confirms overwrite if needed.
     202     *
     203     * @param title The dialog title
     204     * @param extension The file extension
     205     * @return The output {@code File}
     206     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, String)
     207     */
    183208    public static File createAndOpenSaveFileChooser(String title, String extension) {
    184 
    185209        JFileChooser fc = createAndOpenFileChooser(false, false, title, extension);
    186         if (fc == null) return null;
    187 
     210        return checkFileAndConfirmOverWrite(fc, extension);
     211    }
     212   
     213    private static File checkFileAndConfirmOverWrite(JFileChooser fc, String extension) {
     214        if (fc == null) return null;
    188215        File file = fc.getSelectedFile();
    189216        String fn = file.getPath();
     
    193220            if (ff instanceof ExtensionFileFilter) {
    194221                fn += "." + ((ExtensionFileFilter)ff).getDefaultExtension();
    195             } else if(extension != null) {
     222            } else if (extension != null) {
    196223                fn += "." + extension;
    197224            }
Note: See TracChangeset for help on using the changeset viewer.