Changeset 5131 in josm for trunk


Ignore:
Timestamp:
2012-03-29T22:37:42+02:00 (8 years ago)
Author:
xeen
Message:

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.

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

Legend:

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

    r4886 r5131  
    8989                    }
    9090                }
    91                 );
     91        );
     92    }
     93
     94    /**
     95     * Updates the {@see AllFormatsImporter} that is contained in the importers list. If
     96     * you do not use the importers variable directly, you don’t need to call this.
     97     *
     98     *  Updating the AllFormatsImporter is required when plugins add new importers that
     99     *  support new file extensions. The old AllFormatsImporter doesn’t include the new
     100     *  extensions and thus will not display these files.
     101     */
     102    public static void updateAllFormatsImporter() {
     103        for(int i=0; i < importers.size(); i++) {
     104            if(importers.get(i) instanceof AllFormatsImporter) {
     105                importers.set(i, new AllFormatsImporter());
     106            }
     107        }
    92108    }
    93109
     
    100116     */
    101117    public static List<ExtensionFileFilter> getImportExtensionFileFilters() {
     118        updateAllFormatsImporter();
    102119        LinkedList<ExtensionFileFilter> filters = new LinkedList<ExtensionFileFilter>();
    103120        for (FileImporter importer : importers) {
     
    199216            if (name.endsWith("."+ext))
    200217                return true;
    201                 return false;
     218        return false;
    202219    }
    203220
     
    210227    @Override public String getDescription() {
    211228        return description;
     229    }
     230
     231    public String getExtensions() {
     232        return extensions;
    212233    }
    213234
  • trunk/src/org/openstreetmap/josm/io/AllFormatsImporter.java

    r4533 r5131  
    55
    66import java.io.File;
     7import java.util.Iterator;
    78
    89import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    1314public class AllFormatsImporter extends FileImporter {
    1415    public AllFormatsImporter() {
    15         super(new ExtensionFileFilter("osm,xml,osm.gz,osm.bz2,osm.bz,osc,gpx,gpx.gz,nmea,nme,nma,log,txt,wms,jpg", "", tr("All Formats")
    16                     + " (*.gpx *.osm *.nmea *.jpg ...)"));
     16        super(new ExtensionFileFilter(getAllExtensions(), "", tr("All Formats")
     17                + " (*.gpx *.osm *.nmea *.jpg ...)"));
    1718    }
     19
    1820    @Override public boolean acceptFile(File pathname) {
    1921        return false;
    2022    }
     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    }
    2142}
Note: See TracChangeset for help on using the changeset viewer.