Changeset 16275 in josm
- Timestamp:
- 2020-04-12T16:21:16+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r16189 r16275 192 192 private final HelpAction helpTagAction = new HelpTagAction(tagTable, editHelper::getDataKey, editHelper::getDataValues); 193 193 private final HelpAction helpRelAction = new HelpMembershipAction(membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0)); 194 private final TaginfoAction taginfoAction = new TaginfoAction(tagTable, editHelper::getDataKey, editHelper::getDataValues, 195 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0)); 194 private final TaginfoAction taginfoAction = new TaginfoAction(tr("Go to Taginfo"), 195 tagTable, editHelper::getDataKey, editHelper::getDataValues, 196 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0), null); 196 197 private final Collection<TaginfoAction> taginfoNationalActions = new ArrayList<>(); 197 198 private final PasteValueAction pasteValueAction = new PasteValueAction(); … … 365 366 tagMenuTagInfoNatItems.forEach(tagMenu::remove); 366 367 tagMenuTagInfoNatItems.clear(); 367 taginfoNationalActions.forEach(JosmAction::destroy);368 368 taginfoNationalActions.clear(); 369 369 } … … 603 603 @Override 604 604 public void destroy() { 605 taginfoAction.destroy();606 605 destroyTaginfoNationalActions(); 607 606 super.destroy(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TaginfoAction.java
r16083 r16275 8 8 import java.util.Objects; 9 9 import java.util.function.IntFunction; 10 import java.util.function.Supplier; 10 11 12 import javax.swing.AbstractAction; 11 13 import javax.swing.JTable; 12 14 13 import org.openstreetmap.josm.actions.JosmAction;14 15 import org.openstreetmap.josm.data.osm.IRelation; 16 import org.openstreetmap.josm.data.osm.Tag; 15 17 import org.openstreetmap.josm.data.preferences.StringProperty; 18 import org.openstreetmap.josm.tools.ImageProvider; 16 19 import org.openstreetmap.josm.tools.OpenBrowser; 17 20 import org.openstreetmap.josm.tools.Utils; … … 21 24 * @since 13521 22 25 */ 23 public class TaginfoAction extends JosmAction {26 public class TaginfoAction extends AbstractAction { 24 27 25 28 private static final StringProperty TAGINFO_URL_PROP = new StringProperty("taginfo.url", "https://taginfo.openstreetmap.org/"); 26 29 27 private final JTable tagTable; 28 private final IntFunction<String> tagKeySupplier; 29 private final IntFunction<Map<String, Integer>> tagValuesSupplier; 30 30 private final Supplier<Tag> tagSupplier; 31 private final Supplier<String> relationTypeSupplier; 31 32 private final String taginfoUrl; 32 private final JTable membershipTable;33 private final IntFunction<IRelation<?>> memberValueSupplier;34 33 35 34 /** 36 35 * Constructs a new {@code TaginfoAction}. 37 * @param tagTable The tag table. Cannot be null 38 * @param tagKeySupplier Finds the key from given row of tag table. Cannot be null 39 * @param tagValuesSupplier Finds the values from given row of tag table (map of values and number of occurrences). Cannot be null 40 * @param membershipTable The membership table. Can be null 41 * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null 42 * @since 13959 (signature) 36 * @param tagSupplier Supplies the tag for which Taginfo should be opened 37 * @param relationTypeSupplier Supplies a relation type for which Taginfo should be opened 38 * @since 16275 43 39 */ 44 public TaginfoAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier, 45 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) { 46 this(tr("Go to Taginfo"), tagTable, tagKeySupplier, tagValuesSupplier, membershipTable, memberValueSupplier, TAGINFO_URL_PROP.get()); 40 public TaginfoAction(Supplier<Tag> tagSupplier, Supplier<String> relationTypeSupplier) { 41 super(tr("Go to Taginfo")); 42 new ImageProvider("dialogs/taginfo").getResource().attachImageIcon(this, true); 43 putValue(SHORT_DESCRIPTION, tr("Launch browser with Taginfo statistics for selected object")); 44 this.tagSupplier = Objects.requireNonNull(tagSupplier); 45 this.relationTypeSupplier = Objects.requireNonNull(relationTypeSupplier); 46 this.taginfoUrl = getTaginfoUrl(null); 47 47 } 48 48 … … 55 55 * @param membershipTable The membership table. Can be null 56 56 * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null 57 * @param taginfoUrl Taginfo URL. Can notbe null57 * @param taginfoUrl Taginfo URL. Can be null 58 58 * @since 15565 59 59 */ 60 60 public TaginfoAction(String name, JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier, 61 61 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier, String taginfoUrl) { 62 super(name, /* ICON */ "dialogs/taginfo", 63 tr("Launch browser with Taginfo statistics for selected object"), null, false); 64 this.taginfoUrl = taginfoUrl.endsWith("/") ? taginfoUrl : taginfoUrl + '/'; 65 this.tagTable = Objects.requireNonNull(tagTable); 66 this.tagKeySupplier = Objects.requireNonNull(tagKeySupplier); 67 this.tagValuesSupplier = Objects.requireNonNull(tagValuesSupplier); 68 this.membershipTable = membershipTable; 69 this.memberValueSupplier = memberValueSupplier; 62 super(name); 63 new ImageProvider("dialogs/taginfo").getResource().attachImageIcon(this, true); 64 putValue(SHORT_DESCRIPTION, tr("Launch browser with Taginfo statistics for selected object")); 65 this.taginfoUrl = getTaginfoUrl(taginfoUrl); 66 Objects.requireNonNull(tagTable); 67 Objects.requireNonNull(tagKeySupplier); 68 Objects.requireNonNull(tagValuesSupplier); 69 this.tagSupplier = () -> { 70 if (tagTable.getSelectedRowCount() == 1) { 71 final int row = tagTable.getSelectedRow(); 72 final String key = Utils.encodeUrl(tagKeySupplier.apply(row)).replaceAll("\\+", "%20"); 73 Map<String, Integer> values = tagValuesSupplier.apply(row); 74 String value = values.size() == 1 ? values.keySet().iterator().next() : null; 75 return new Tag(key, value); 76 } 77 return null; 78 }; 79 this.relationTypeSupplier = () -> membershipTable != null && membershipTable.getSelectedRowCount() == 1 80 ? memberValueSupplier.apply(membershipTable.getSelectedRow()).get("type") : null; 70 81 } 71 82 72 83 @Override 73 84 public void actionPerformed(ActionEvent e) { 74 final String url; 75 if (tagTable.getSelectedRowCount() == 1) { 76 final int row = tagTable.getSelectedRow(); 77 final String key = Utils.encodeUrl(tagKeySupplier.apply(row)).replaceAll("\\+", "%20"); 78 Map<String, Integer> values = tagValuesSupplier.apply(row); 79 if (values.size() == 1) { 80 url = taginfoUrl + "tags/" + key 81 + '=' + Utils.encodeUrl(values.keySet().iterator().next()).replaceAll("\\+", "%20"); 82 } else { 83 url = taginfoUrl + "keys/" + key; 84 } 85 } else if (membershipTable != null && membershipTable.getSelectedRowCount() == 1) { 86 final String type = (memberValueSupplier.apply(membershipTable.getSelectedRow())).get("type"); 87 url = taginfoUrl + "relations/" + type; 88 } else { 85 Tag tag = tagSupplier.get(); 86 if (tag != null) { 87 openTaginfoForTag(tag, taginfoUrl); 89 88 return; 90 89 } 91 OpenBrowser.displayUrl(url); 90 String type = relationTypeSupplier.get(); 91 if (type != null) { 92 openTaginfoForRelationType(type, taginfoUrl); 93 } 94 } 95 96 private static String getTaginfoUrl(String taginfoUrl) { 97 if (taginfoUrl == null) { 98 taginfoUrl = TAGINFO_URL_PROP.get(); 99 } 100 return taginfoUrl.endsWith("/") ? taginfoUrl : taginfoUrl + '/'; 101 } 102 103 /** 104 * Opens Taginfo for the given tag or key (if the tag value is null) 105 * @param tag the tag 106 * @param taginfoUrl Taginfo URL (may be null) 107 * @since 16275 108 */ 109 public static void openTaginfoForTag(Tag tag, String taginfoUrl) { 110 taginfoUrl = getTaginfoUrl(taginfoUrl); 111 if (tag.getValue().isEmpty()) { 112 OpenBrowser.displayUrl(taginfoUrl + "keys/" + tag.getKey()); 113 } else { 114 OpenBrowser.displayUrl(taginfoUrl + "tags/" + tag.getKey() + '=' + Utils.encodeUrl(tag.getValue()).replaceAll("\\+", "%20")); 115 } 116 } 117 118 /** 119 * Opens Taginfo for the given relation type 120 * @param type the relation type 121 * @param taginfoUrl Taginfo URL (may be null) 122 * @since 16275 123 */ 124 public static void openTaginfoForRelationType(String type, String taginfoUrl) { 125 taginfoUrl = getTaginfoUrl(taginfoUrl); 126 OpenBrowser.displayUrl(taginfoUrl + "relations/" + type); 92 127 } 93 128 } -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r15772 r16275 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.history; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.event.FocusEvent; … … 85 87 tagMenu.addSeparator(); 86 88 tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn))); 87 tagMenu.add(trackJosmAction(new TaginfoAction(t able, tagKeyFn, tagValuesFn, null, null)));89 tagMenu.add(trackJosmAction(new TaginfoAction(tr("Go to Taginfo"), table, tagKeyFn, tagValuesFn, null, null, null))); 88 90 89 91 table.addMouseListener(new PopupMenuLauncher(tagMenu));
Note:
See TracChangeset
for help on using the changeset viewer.