Changeset 9537 in josm


Ignore:
Timestamp:
2016-01-19T11:20:23+01:00 (8 years ago)
Author:
bastiK
Message:

applied #12370 - adapted osm file filter to other file types (patch by kolesar)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 deleted
5 edited

Legend:

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

    r9466 r9537  
    5353        final List<Class<? extends FileImporter>> importerNames = Arrays.asList(
    5454                org.openstreetmap.josm.io.OsmImporter.class,
    55                 org.openstreetmap.josm.io.OsmGzipImporter.class,
    56                 org.openstreetmap.josm.io.OsmZipImporter.class,
    5755                org.openstreetmap.josm.io.OsmChangeImporter.class,
    5856                org.openstreetmap.josm.io.GpxImporter.class,
    5957                org.openstreetmap.josm.io.NMEAImporter.class,
    6058                org.openstreetmap.josm.io.NoteImporter.class,
    61                 org.openstreetmap.josm.io.OsmBzip2Importer.class,
    6259                org.openstreetmap.josm.io.JpgImporter.class,
    6360                org.openstreetmap.josm.io.WMSLayerImporter.class,
     
    142139    }
    143140
     141    public enum AddArchiveExtension { NONE, BASE, ALL }
     142
    144143    /**
    145144     * Updates the {@link AllFormatsImporter} that is contained in the importers list. If
     
    287286        this.defaultExtension = defaultExtension;
    288287        this.description = description;
     288    }
     289
     290    /**
     291     * Construct an extension file filter with the extensions supported by {@link org.openstreetmap.josm.io.Compression}
     292     * automatically added to the {@code extensions}. The specified {@code extensions} will be added to the description
     293     * in the form {@code old-description (*.ext1, *.ext2)}.
     294     * @param extensions The comma-separated list of file extensions
     295     * @param defaultExtension The default extension
     296     * @param description A short textual description of the file type without supported extensions in parentheses
     297     * @param addArchiveExtension Whether to also add the archive extensions to the description
     298     * @param archiveExtensions List of extensions to be added
     299     * @return The constructed filter
     300     */
     301    public static ExtensionFileFilter newFilterWithArchiveExtensions(
     302            String extensions, String defaultExtension, String description, AddArchiveExtension addArchiveExtension, List<String> archiveExtensions) {
     303        final Collection<String> extensionsPlusArchive = new LinkedHashSet<>();
     304        final Collection<String> extensionsForDescription = new LinkedHashSet<>();
     305        for (String e : extensions.split(",")) {
     306            extensionsPlusArchive.add(e);
     307            if (addArchiveExtension != AddArchiveExtension.NONE) {
     308                extensionsForDescription.add("*." + e);
     309            }
     310            for (String extension : archiveExtensions) {
     311                extensionsPlusArchive.add(e + '.' + extension);
     312                if (addArchiveExtension == AddArchiveExtension.ALL) {
     313                    extensionsForDescription.add("*." + e + '.' + extension);
     314                }
     315            }
     316        }
     317        return new ExtensionFileFilter(
     318            Utils.join(",", extensionsPlusArchive),
     319            defaultExtension,
     320            description + (!extensionsForDescription.isEmpty()
     321                ? " (" + Utils.join(", ", extensionsForDescription) + ")"
     322                : "")
     323            );
    289324    }
    290325
     
    301336    public static ExtensionFileFilter newFilterWithArchiveExtensions(
    302337            String extensions, String defaultExtension, String description, boolean addArchiveExtensionsToDescription) {
    303         final Collection<String> extensionsPlusArchive = new LinkedHashSet<>();
    304         final Collection<String> extensionsForDescription = new LinkedHashSet<>();
    305         for (String e : extensions.split(",")) {
    306             extensionsPlusArchive.add(e);
    307             extensionsPlusArchive.add(e + ".gz");
    308             extensionsPlusArchive.add(e + ".bz2");
    309             extensionsForDescription.add("*." + e);
    310             if (addArchiveExtensionsToDescription) {
    311                 extensionsForDescription.add("*." + e + ".gz");
    312                 extensionsForDescription.add("*." + e + ".bz2");
    313             }
    314         }
    315         return new ExtensionFileFilter(Utils.join(",", extensionsPlusArchive), defaultExtension,
    316                 description + " (" + Utils.join(", ", extensionsForDescription) + ")");
     338
     339        List<String> archiveExtensions = Arrays.asList("gz", "bz2");
     340        return newFilterWithArchiveExtensions(
     341            extensions,
     342            defaultExtension,
     343            description,
     344            addArchiveExtensionsToDescription ? AddArchiveExtension.ALL : AddArchiveExtension.BASE,
     345            archiveExtensions
     346        );
    317347    }
    318348
  • trunk/src/org/openstreetmap/josm/io/OsmBzip2Exporter.java

    r6718 r9537  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import org.openstreetmap.josm.actions.ExtensionFileFilter;
    37
    48/**
     
    1115     */
    1216    public OsmBzip2Exporter() {
    13         super(OsmBzip2Importer.FILE_FILTER);
     17        super(new ExtensionFileFilter(
     18            "osm.bz2,osm.bz", "osm.bz2", tr("OSM Server Files bzip2 compressed") + " (*.osm.bz2, *.osm.bz)"));
    1419    }
    1520
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r9296 r9537  
    3232     */
    3333    public OsmExporter() {
    34         super(OsmImporter.FILE_FILTER);
     34        super(new ExtensionFileFilter(
     35            "osm,xml", "osm", tr("OSM Server Files") + " (*.osm)"));
    3536    }
    3637
  • trunk/src/org/openstreetmap/josm/io/OsmGzipExporter.java

    r6718 r9537  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import org.openstreetmap.josm.actions.ExtensionFileFilter;
    37
    48/**
     
    1115     */
    1216    public OsmGzipExporter() {
    13         super(OsmGzipImporter.FILE_FILTER);
     17        super(new ExtensionFileFilter(
     18            "osm.gz", "osm.gz", tr("OSM Server Files gzip compressed") + " (*.osm.gz)"));
    1419    }
    1520
  • trunk/src/org/openstreetmap/josm/io/OsmImporter.java

    r8929 r9537  
    88import java.io.IOException;
    99import java.io.InputStream;
     10import java.util.Arrays;
    1011
    1112import javax.swing.JOptionPane;
     
    2425     * The OSM file filter (*.osm and *.xml files).
    2526     */
    26     public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
    27             "osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)");
     27    public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
     28            "osm,xml", "osm", tr("OSM Server Files") + " (*.osm, *.osm.gz, *.osm.bz2, *.osm.zip, *.xml)", ExtensionFileFilter.AddArchiveExtension.NONE, Arrays.asList("gz", "bz", "bz2", "zip"));
    2829
    2930    /**
Note: See TracChangeset for help on using the changeset viewer.