Changeset 8806 in josm for trunk/src/org


Ignore:
Timestamp:
2015-09-29T20:12:40+02:00 (5 years ago)
Author:
simon04
Message:

fix #10208 - Gpx markers: show names for audio, image, url, markers

Modifies interface MarkerProducers which is not used outside of JOSM core.

Location:
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r8540 r8806  
    1515import java.text.SimpleDateFormat;
    1616import java.util.ArrayList;
     17import java.util.Arrays;
    1718import java.util.Collection;
     19import java.util.Collections;
    1820import java.util.Date;
    1921import java.util.HashMap;
     
    183185        Marker.markerProducers.add(new MarkerProducers() {
    184186            @Override
    185             public Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) {
     187            public Collection<Marker> createMarkers(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) {
    186188                String uri = null;
    187189                // cheapest way to check whether "link" object exists and is a non-empty collection of GpxLink objects...
     
    207209
    208210                String urlStr = url == null ? "" : url.toString();
     211                String symbolName = wpt.getString("symbol");
     212                if (symbolName == null) {
     213                    symbolName = wpt.getString(GpxConstants.PT_SYM);
     214                }
     215                // text marker is returned in every case, see #10208
     216                final Marker marker = new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset);
    209217                if (url == null) {
    210                     String symbolName = wpt.getString("symbol");
    211                     if (symbolName == null) {
    212                         symbolName = wpt.getString(GpxConstants.PT_SYM);
    213                     }
    214                     return new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset);
     218                    return Collections.singleton(marker);
    215219                } else if (urlStr.endsWith(".wav")) {
    216                     AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset);
     220                    final AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset);
    217221                    Extensions exts = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS);
    218222                    if (exts != null && exts.containsKey("offset")) {
     
    223227                        }
    224228                    }
    225                     return audioMarker;
     229                    return Arrays.asList(marker, audioMarker);
    226230                } else if (urlStr.endsWith(".png") || urlStr.endsWith(".jpg") || urlStr.endsWith(".jpeg") || urlStr.endsWith(".gif")) {
    227                     return new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset);
     231                    final ImageMarker imageMarker = new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset);
     232                    return Arrays.asList(marker, imageMarker);
    228233                } else {
    229                     return new WebMarker(wpt.getCoor(), url, parentLayer, time, offset);
     234                    final WebMarker webMarker = new WebMarker(wpt.getCoor(), url, parentLayer, time, offset);
     235                    return Arrays.asList(marker, webMarker);
    230236                }
    231237            }
     
    246252     * @return a new Marker object
    247253     */
    248     public static Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) {
     254    public static Collection<Marker> createMarkers(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) {
    249255        for (MarkerProducers maker : Marker.markerProducers) {
    250             Marker marker = maker.createMarker(wpt, relativePath, parentLayer, time, offset);
    251             if (marker != null)
    252                 return marker;
     256            final Collection<Marker> markers = maker.createMarkers(wpt, relativePath, parentLayer, time, offset);
     257            if (markers != null)
     258                return markers;
    253259        }
    254260        return null;
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r8804 r8806  
    129129                offset = time - firstTime;
    130130            }
    131             Marker m = Marker.createMarker(wpt, indata.storageFile, this, time, offset);
    132             if (m != null) {
    133                 data.add(m);
     131            final Collection<Marker> markers = Marker.createMarkers(wpt, indata.storageFile, this, time, offset);
     132            if (markers != null) {
     133                data.addAll(markers);
    134134            }
    135135        }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerProducers.java

    r6830 r8806  
    33
    44import java.io.File;
     5import java.util.Collection;
    56
    67import org.openstreetmap.josm.data.gpx.WayPoint;
     
    1617public interface MarkerProducers {
    1718    /**
    18      * Returns a Marker object if this implementation wants to create one for the
     19     * Returns a collection of Marker objects if this implementation wants to create one for the
    1920     * given input data, or <code>null</code> otherwise.
    2021     *
     
    2223     * @param relativePath An path to use for constructing relative URLs or
    2324     *        <code>null</code> for no relative URLs
    24      * @return A Marker object, or <code>null</code>.
     25     * @return A collection of Marker objects, or <code>null</code>.
    2526     */
    26     Marker createMarker(WayPoint wp, File relativePath, MarkerLayer parentLayer, double time, double offset);
     27    Collection<Marker> createMarkers(WayPoint wp, File relativePath, MarkerLayer parentLayer, double time, double offset);
    2728}
Note: See TracChangeset for help on using the changeset viewer.