source: josm/trunk/src/org/openstreetmap/josm/io/AllFormatsImporter.java @ 5241

Revision 5131, 1.3 KB checked in by xeen, 8 weeks ago (diff)

automatically add file extensions added by plugins to the "All Formats" importer.

If you have the PBF plugin installed it should now be possible to open .osm.pbf
files without selecting the PBF importer first.

  • Property svn:eol-style set to native
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.util.Iterator;
8
9import org.openstreetmap.josm.actions.ExtensionFileFilter;
10
11/**
12 * Dummy importer that adds the "All Formats"-Filter when opening files
13 */
14public class AllFormatsImporter extends FileImporter {
15    public AllFormatsImporter() {
16        super(new ExtensionFileFilter(getAllExtensions(), "", tr("All Formats")
17                + " (*.gpx *.osm *.nmea *.jpg ...)"));
18    }
19
20    @Override public boolean acceptFile(File pathname) {
21        return false;
22    }
23
24    /**
25     * Builds list of all supported extensions by the registered FileImporters.
26     * @return String comma separated list of supported file extensions
27     */
28    private static String getAllExtensions() {
29        Iterator<FileImporter> imp = ExtensionFileFilter.importers.iterator();
30        StringBuilder ext = new StringBuilder();
31        while(imp.hasNext()) {
32            FileImporter fi = imp.next();
33            if(fi instanceof AllFormatsImporter) {
34                continue;
35            }
36            ext.append(fi.filter.getExtensions());
37            ext.append(",");
38        }
39        // remove last comma
40        return ext.substring(0, ext.length()-1).toString();
41    }
42}
Note: See TracBrowser for help on using the repository browser.