Ignore:
Timestamp:
2018-11-20T00:09:48+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #17000 - add link to OSM History Viewer (pewu)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/OpenChangesetPopupMenu.java

    r14248 r14432  
    1010import java.util.Arrays;
    1111import java.util.List;
     12import java.util.Objects;
    1213
    1314import javax.swing.AbstractAction;
     
    1819import org.openstreetmap.josm.data.StructUtils;
    1920import org.openstreetmap.josm.data.StructUtils.StructEntry;
     21import org.openstreetmap.josm.data.osm.PrimitiveId;
    2022import org.openstreetmap.josm.spi.preferences.Config;
    2123import org.openstreetmap.josm.tools.ImageProvider;
     
    3335     *
    3436     * @param changesetId the changeset id
     37     * @param primitiveId the primitive id
     38     * @since 14432
    3539     */
    36     public OpenChangesetPopupMenu(final long changesetId) {
     40    public OpenChangesetPopupMenu(final long changesetId, final PrimitiveId primitiveId) {
    3741        StructUtils.getListOfStructs(Config.getPref(), "history-dialog.tools", DEFAULT_ENTRIES, ChangesetViewerEntry.class)
    3842                .stream()
    39                 .map(entry -> entry.toAction(changesetId))
     43                .map(entry -> entry.toAction(changesetId, primitiveId))
     44                .filter(Objects::nonNull)
    4045                .forEach(this::add);
    4146    }
     
    5863            new ChangesetViewerEntry(tr("Open {0}", "achavi (Augmented OSM Change Viewer)"), "https://overpass-api.de/achavi/?changeset={0}"),
    5964            new ChangesetViewerEntry(tr("Open {0}", "OSMCha (OSM Changeset Analyzer)"), "https://osmcha.mapbox.com/changesets/{0}"),
    60             new ChangesetViewerEntry(tr("Open {0}", "OSM History Viewer"), "http://osmhv.openstreetmap.de/changeset.jsp?id={0}"),
     65            new ChangesetViewerEntry(tr("Open {0}", "OSM History Viewer (osmrmhv)"), "http://osmhv.openstreetmap.de/changeset.jsp?id={0}"),
     66            new ChangesetViewerEntry(tr("Open {0}", "OSM History Viewer (Pewu)"), "https://pewu.github.io/osm-history/#/{1}/{2}"),
    6167            new ChangesetViewerEntry(tr("Open {0}", "WhoDidIt (OSM Changeset Analyzer)"),
    6268                    "http://simon04.dev.openstreetmap.org/whodidit/index.html?changeset={0}&show=1")
     
    7076        @StructEntry
    7177        public String name;
    72         /** Templated service url. <code>{0}</code> will be replaced by changeset id */
     78        /**
     79         * Templated service url.
     80         * <code>{0}</code> will be replaced by changeset id
     81         * <code>{1}</code> will be replaced by object type (node, way, relation)
     82         * <code>{2}</code> will be replaced by object id
     83         */
    7384        @StructEntry
    7485        public String url;
     
    8192
    8293        ChangesetViewerEntry(String name, String url) {
    83             this.name = name;
    84             this.url = url;
     94            this.name = Objects.requireNonNull(name);
     95            this.url = Objects.requireNonNull(url);
    8596        }
    8697
    87         Action toAction(final long changesetId) {
    88             return new OpenBrowserAction(name, MessageFormat.format(this.url, Long.toString(changesetId)));
     98        Action toAction(final long changesetId, PrimitiveId primitiveId) {
     99            if (primitiveId != null) {
     100                return new OpenBrowserAction(name, MessageFormat.format(url,
     101                        Long.toString(changesetId), primitiveId.getType().getAPIName(), Long.toString(primitiveId.getUniqueId())));
     102            } else if (url.contains("{0}")) {
     103                return new OpenBrowserAction(name, MessageFormat.format(url, Long.toString(changesetId)));
     104            }
     105            return null;
    89106        }
    90107    }
Note: See TracChangeset for help on using the changeset viewer.