1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.layer.markerlayer;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.net.URL;
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import javax.swing.JOptionPane;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
15 | import org.openstreetmap.josm.data.gpx.GpxLink;
|
---|
16 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
17 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Marker class with Web URL activation.
|
---|
21 | *
|
---|
22 | * @author Frederik Ramm <frederik@remote.org>
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class WebMarker extends ButtonMarker {
|
---|
26 |
|
---|
27 | public final URL webUrl;
|
---|
28 |
|
---|
29 | public WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) {
|
---|
30 | super(ll, "web.png", parentLayer, time, offset);
|
---|
31 | this.webUrl = webUrl;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override public void actionPerformed(ActionEvent ev) {
|
---|
35 | String error = OpenBrowser.displayUrl(webUrl.toString());
|
---|
36 | if (error != null) {
|
---|
37 | JOptionPane.showMessageDialog(Main.parent,
|
---|
38 | "<html><b>" +
|
---|
39 | tr("There was an error while trying to display the URL for this marker") +
|
---|
40 | "</b><br>" + tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error,
|
---|
41 | tr("Error displaying URL"), JOptionPane.ERROR_MESSAGE);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public WayPoint convertToWayPoint() {
|
---|
47 | WayPoint wpt = super.convertToWayPoint();
|
---|
48 | GpxLink link = new GpxLink(webUrl.toString());
|
---|
49 | link.type = "web";
|
---|
50 | wpt.attr.put(GpxConstants.META_LINKS, Collections.singleton(link));
|
---|
51 | return wpt;
|
---|
52 | }
|
---|
53 | }
|
---|