source: josm/trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java@ 8056

Last change on this file since 8056 was 8056, checked in by bastiK, 9 years ago

fixed #11096 - png -> svg

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.markerlayer;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.io.File;
8import java.net.URL;
9import java.util.Collections;
10
11import javax.swing.JOptionPane;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.data.gpx.GpxConstants;
16import org.openstreetmap.josm.data.gpx.GpxLink;
17import org.openstreetmap.josm.data.gpx.WayPoint;
18import org.openstreetmap.josm.gui.Notification;
19import org.openstreetmap.josm.tools.CheckParameterUtil;
20import org.openstreetmap.josm.tools.OpenBrowser;
21
22/**
23 * Marker class with Web URL activation.
24 *
25 * @author Frederik Ramm
26 *
27 */
28public class WebMarker extends ButtonMarker {
29
30 private final URL webUrl;
31
32 public WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) {
33 super(ll, "web", parentLayer, time, offset);
34 CheckParameterUtil.ensureParameterNotNull(webUrl, "webUrl");
35 this.webUrl = webUrl;
36 }
37
38 @Override public void actionPerformed(ActionEvent ev) {
39 String error = OpenBrowser.displayUrl(webUrl.toString());
40 if (error != null) {
41 setErroneous(true);
42 new Notification(
43 "<b>" + tr("There was an error while trying to display the URL for this marker") + "</b><br>" +
44 tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error)
45 .setIcon(JOptionPane.ERROR_MESSAGE)
46 .setDuration(Notification.TIME_LONG)
47 .show();
48 } else {
49 updateErroneous();
50 }
51 }
52
53 @Override
54 public WayPoint convertToWayPoint() {
55 WayPoint wpt = super.convertToWayPoint();
56 GpxLink link = new GpxLink(webUrl.toString());
57 link.type = "web";
58 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link));
59 return wpt;
60 }
61
62 private final void updateErroneous() {
63 if ("file".equals(webUrl.getProtocol())) {
64 String path = webUrl.getPath();
65 try {
66 setErroneous(path.isEmpty() || !new File(path).exists());
67 } catch (Exception e) {
68 Main.warn(e);
69 setErroneous(true);
70 }
71 } else {
72 setErroneous(false);
73 }
74 }
75}
Note: See TracBrowser for help on using the repository browser.