source: josm/trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java@ 1586

Last change on this file since 1586 was 1586, checked in by stoecker, 15 years ago

fix hardcoded URL - patch by Gubaer

File size: 2.9 KB
Line 
1//License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9import java.util.LinkedList;
10import java.util.regex.Pattern;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
20import org.openstreetmap.josm.tools.OpenBrowser;
21import org.openstreetmap.josm.tools.Shortcut;
22
23public class HistoryInfoAction extends JosmAction {
24
25 public HistoryInfoAction() {
26 super(tr("History of Element"), "about",
27 tr("Display history information about OSM ways or nodes."),
28 Shortcut.registerShortcut("core:history",
29 tr("History of Element"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), true);
30 }
31
32 /**
33 * replies the base URL for browsing the the history of an OSM primitive
34 *
35 * @return the base URL, i.e. http://api.openstreetmap.org/browse
36 */
37 protected String getBaseURL() {
38 String baseUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
39 Pattern pattern = Pattern.compile("/api/?$");
40 String ret = pattern.matcher(baseUrl).replaceAll("/browse");
41 if (ret.equals(baseUrl)) {
42 System.out.println("WARNING: unexpected format of API base URL. Redirection to history page for OSM primitive will probably fail. API base URL is: " + baseUrl);
43 }
44 return ret;
45 }
46
47 public void actionPerformed(ActionEvent e) {
48 final Collection<Object> sel = new LinkedList<Object>();
49 final String baseUrl = getBaseURL();
50 new AbstractVisitor() {
51 public void visit(Node n) {
52 if(n.id <= 0) return;
53 OpenBrowser.displayUrl(baseUrl + "/node/" + n.id + "/history");
54 sel.add(n);
55 }
56
57 public void visit(Way w) {
58 if(w.id <= 0) return;
59 OpenBrowser.displayUrl(baseUrl + "/way/" + w.id + "/history");
60 sel.add(w);
61 }
62
63 public void visit(Relation e) {
64 if(e.id <= 0) return;
65 OpenBrowser.displayUrl(baseUrl + "/relation/" + e.id + "/history");
66 sel.add(e);
67 }
68
69 public void visitAll() {
70 for (OsmPrimitive osm : Main.ds.getSelected())
71 osm.visit(this);
72 }
73 }.visitAll();
74
75 if (sel.isEmpty()) {
76 JOptionPane.showMessageDialog(Main.parent,
77 tr("Please select at least one node, way or relation. Only already uploaded elements have a history."));
78 return;
79 }
80 }
81}
Note: See TracBrowser for help on using the repository browser.