1 | //License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.LinkedList;
|
---|
10 | import java.util.regex.Pattern;
|
---|
11 |
|
---|
12 | import javax.swing.JOptionPane;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
|
---|
20 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
21 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
22 |
|
---|
23 | public 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 | }
|
---|