source: josm/trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/DefaultMarkerProducers.java@ 12328

Last change on this file since 12328 was 12328, checked in by Don-vip, 7 years ago

fix #2089 - Add support for MP3, AIFF and AAC audio codecs (.mp3, .aac, .aif, .aiff files) if Java FX is on the classpath (i.e. Windows, macOS, nearly all major Linux distributions). The classes are not public on purpose, as the whole system will have to be simplified when all Linux distributions propose Java FX and so we can get rid of old Java Sound implementation.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.markerlayer;
3
4import java.io.File;
5import java.net.MalformedURLException;
6import java.net.URL;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.Collections;
10import java.util.Optional;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.gpx.Extensions;
14import org.openstreetmap.josm.data.gpx.GpxConstants;
15import org.openstreetmap.josm.data.gpx.GpxLink;
16import org.openstreetmap.josm.data.gpx.WayPoint;
17import org.openstreetmap.josm.tools.Utils;
18
19/**
20 * Marker specifying the default behaviour.
21 * @since 11892 (extracted from Marker)
22 */
23public final class DefaultMarkerProducers implements MarkerProducers {
24
25 @Override
26 public Collection<Marker> createMarkers(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time,
27 double offset) {
28 String uri = null;
29 // cheapest way to check whether "link" object exists and is a non-empty collection of GpxLink objects...
30 Collection<GpxLink> links = wpt.<GpxLink>getCollection(GpxConstants.META_LINKS);
31 if (links != null) {
32 for (GpxLink oneLink : links) {
33 uri = oneLink.uri;
34 break;
35 }
36 }
37
38 URL url = uriToUrl(uri, relativePath);
39 String urlStr = url == null ? "" : url.toString();
40 String symbolName = Optional.ofNullable(wpt.getString("symbol"))
41 .orElseGet(() -> wpt.getString(GpxConstants.PT_SYM));
42 // text marker is returned in every case, see #10208
43 final Marker marker = new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset);
44 if (url == null) {
45 return Collections.singleton(marker);
46 } else if (Utils.hasExtension(urlStr, "wav", "mp3", "aac", "aif", "aiff")) {
47 final AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset);
48 Extensions exts = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS);
49 if (exts != null && exts.containsKey("offset")) {
50 try {
51 audioMarker.syncOffset = Double.parseDouble(exts.get("sync-offset"));
52 } catch (NumberFormatException nfe) {
53 Main.warn(nfe);
54 }
55 }
56 return Arrays.asList(marker, audioMarker);
57 } else if (Utils.hasExtension(urlStr, "png", "jpg", "jpeg", "gif")) {
58 return Arrays.asList(marker, new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset));
59 } else {
60 return Arrays.asList(marker, new WebMarker(wpt.getCoor(), url, parentLayer, time, offset));
61 }
62 }
63
64 private static URL uriToUrl(String uri, File relativePath) {
65 URL url = null;
66 if (uri != null) {
67 try {
68 url = new URL(uri);
69 } catch (MalformedURLException e) {
70 // Try a relative file:// url, if the link is not in an URL-compatible form
71 if (relativePath != null) {
72 url = Utils.fileToURL(new File(relativePath.getParentFile(), uri));
73 }
74 }
75 }
76 return url;
77 }
78}
Note: See TracBrowser for help on using the repository browser.