001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.io.importexport; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.io.File; 007import java.util.Iterator; 008 009import org.openstreetmap.josm.actions.ExtensionFileFilter; 010 011/** 012 * Dummy importer that adds the "All Formats"-Filter when opening files 013 */ 014public class AllFormatsImporter extends FileImporter { 015 /** 016 * Constructs a new {@code AllFormatsImporter}. 017 */ 018 public AllFormatsImporter() { 019 super(new ExtensionFileFilter(getAllExtensions(), "", tr("All Formats") 020 + " (*.gpx *.osm *.nmea *.jpg ...)")); 021 } 022 023 @Override 024 public boolean acceptFile(File pathname) { 025 return false; 026 } 027 028 /** 029 * Builds list of all supported extensions by the registered FileImporters. 030 * @return String comma separated list of supported file extensions 031 */ 032 private static String getAllExtensions() { 033 Iterator<FileImporter> imp = ExtensionFileFilter.getImporters().iterator(); 034 StringBuilder ext = new StringBuilder(); 035 while (imp.hasNext()) { 036 FileImporter fi = imp.next(); 037 if (fi instanceof AllFormatsImporter || fi.filter == null) { 038 continue; 039 } 040 ext.append(fi.filter.getExtensions()).append(','); 041 } 042 // remove last comma 043 return ext.substring(0, ext.length()-1); 044 } 045}