source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TaginfoAction.java@ 13959

Last change on this file since 13959 was 13959, checked in by Don-vip, 6 years ago

use IRelation in PropertiesDialog

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.Map;
8import java.util.Objects;
9import java.util.function.IntFunction;
10
11import javax.swing.JTable;
12
13import org.openstreetmap.josm.actions.JosmAction;
14import org.openstreetmap.josm.data.osm.IRelation;
15import org.openstreetmap.josm.data.preferences.StringProperty;
16import org.openstreetmap.josm.tools.OpenBrowser;
17import org.openstreetmap.josm.tools.Utils;
18
19/**
20 * Launch browser with Taginfo statistics for selected object.
21 * @since 13521
22 */
23public class TaginfoAction extends JosmAction {
24
25 final transient StringProperty TAGINFO_URL_PROP = new StringProperty("taginfo.url", "https://taginfo.openstreetmap.org/");
26
27 private final JTable tagTable;
28 private final IntFunction<String> tagKeySupplier;
29 private final IntFunction<Map<String, Integer>> tagValuesSupplier;
30
31 private final JTable membershipTable;
32 private final IntFunction<IRelation<?>> memberValueSupplier;
33
34 /**
35 * Constructs a new {@code TaginfoAction}.
36 * @param tagTable The tag table. Cannot be null
37 * @param tagKeySupplier Finds the key from given row of tag table. Cannot be null
38 * @param tagValuesSupplier Finds the values from given row of tag table (map of values and number of occurrences). Cannot be null
39 * @param membershipTable The membership table. Can be null
40 * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null
41 * @since 13959 (signature)
42 */
43 public TaginfoAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier,
44 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) {
45 super(tr("Go to Taginfo"), "dialogs/taginfo", tr("Launch browser with Taginfo statistics for selected object"), null, false);
46 this.tagTable = Objects.requireNonNull(tagTable);
47 this.tagKeySupplier = Objects.requireNonNull(tagKeySupplier);
48 this.tagValuesSupplier = Objects.requireNonNull(tagValuesSupplier);
49 this.membershipTable = membershipTable;
50 this.memberValueSupplier = memberValueSupplier;
51 }
52
53 @Override
54 public void actionPerformed(ActionEvent e) {
55 final String url;
56 if (tagTable.getSelectedRowCount() == 1) {
57 final int row = tagTable.getSelectedRow();
58 final String key = Utils.encodeUrl(tagKeySupplier.apply(row)).replaceAll("\\+", "%20");
59 Map<String, Integer> values = tagValuesSupplier.apply(row);
60 if (values.size() == 1) {
61 url = TAGINFO_URL_PROP.get() + "tags/" + key
62 + '=' + Utils.encodeUrl(values.keySet().iterator().next()).replaceAll("\\+", "%20");
63 } else {
64 url = TAGINFO_URL_PROP.get() + "keys/" + key;
65 }
66 } else if (membershipTable != null && membershipTable.getSelectedRowCount() == 1) {
67 final String type = (memberValueSupplier.apply(membershipTable.getSelectedRow())).get("type");
68 url = TAGINFO_URL_PROP.get() + "relations/" + type;
69 } else {
70 return;
71 }
72 OpenBrowser.displayUrl(url);
73 }
74}
Note: See TracBrowser for help on using the repository browser.