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

Last change on this file was 13281, checked in by stoecker, 8 years ago

see #15734 - drop some old checks

  • 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.data.coor.LatLon;
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.gui.Notification;
18import org.openstreetmap.josm.tools.CheckParameterUtil;
19import org.openstreetmap.josm.tools.Logging;
20import org.openstreetmap.josm.tools.OpenBrowser;
21
22/**
23 * Marker class with Web URL activation.
24 *
25 * @author Frederik Ramm
26 * @since 200
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, /* ICON(markers/) */ "web", parentLayer, time, offset);
34 CheckParameterUtil.ensureParameterNotNull(webUrl, "webUrl");
35 this.webUrl = webUrl;
36 }
37
38 @Override
39 public void actionPerformed(ActionEvent ev) {
40 String error = OpenBrowser.displayUrl(webUrl.toString());
41 if (error != null) {
42 setErroneous(true);
43 new Notification(
44 "<b>" + tr("There was an error while trying to display the URL for this marker") + "</b><br>" +
45 tr("(URL was: ") + webUrl + ')' + "<br>" + error)
46 .setIcon(JOptionPane.ERROR_MESSAGE)
47 .setDuration(Notification.TIME_LONG)
48 .show();
49 } else {
50 updateErroneous();
51 }
52 }
53
54 @Override
55 public WayPoint convertToWayPoint() {
56 WayPoint wpt = super.convertToWayPoint();
57 GpxLink link = new GpxLink(webUrl.toString());
58 link.type = "web";
59 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link));
60 return wpt;
61 }
62
63 private void updateErroneous() {
64 if ("file".equals(webUrl.getProtocol())) {
65 String path = webUrl.getPath();
66 try {
67 setErroneous(path.isEmpty() || !new File(path).exists());
68 } catch (SecurityException e) {
69 Logging.warn(e);
70 setErroneous(true);
71 }
72 } else {
73 setErroneous(false);
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.