- Timestamp:
- 2009-06-27T01:15:36+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java
r1677 r1697 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.event.ActionEvent;7 6 import java.awt.event.KeyEvent; 8 import java.util.Collection;9 import java.util.LinkedList;10 import java.util.regex.Pattern;11 7 12 import javax.swing.JOptionPane;13 14 import org.openstreetmap.josm.Main;15 import org.openstreetmap.josm.data.osm.Node;16 8 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; 9 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 21 10 import org.openstreetmap.josm.tools.Shortcut; 22 11 23 public class HistoryInfoAction extends JosmAction {12 public class HistoryInfoAction extends AbstractInfoAction { 24 13 25 14 public HistoryInfoAction() { 26 15 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);16 tr("Display history information about OSM ways, nodes, or relations."), 17 Shortcut.registerShortcut("core:history", 18 tr("History of Element"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), true); 30 19 } 31 20 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 } 21 @Override 22 protected String createInfoUrl(OsmPrimitive primitive) { 23 return getBaseURL() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.id + "/history"; 80 24 } 81 25 }
Note:
See TracChangeset
for help on using the changeset viewer.