Changeset 16597 in josm for trunk/src/org
- Timestamp:
- 2020-06-11T11:32:21+02:00 (4 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
r16596 r16597 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( tr("Go to Taginfo"),194 private final TaginfoAction taginfoAction = new TaginfoAction( 195 195 tagTable, editHelper::getDataKey, editHelper::getDataValues, 196 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0) , null);196 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0)); 197 197 private final TaginfoAction tagHistoryAction = taginfoAction.toTagHistoryAction(); 198 198 private final Collection<TaginfoAction> taginfoNationalActions = new ArrayList<>(); … … 375 375 final LatLon center = newSel.iterator().next().getBBox().getCenter(); 376 376 Territories.getRegionalTaginfoUrls(center).stream() 377 .map(taginfo -> new TaginfoAction(tr("Go to Taginfo ({0})", taginfo.toString()), 378 tagTable, editHelper::getDataKey, editHelper::getDataValues, 379 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0), taginfo.getUrl()) 377 .map(taginfo -> taginfoAction.withTaginfoUrl(tr("Go to Taginfo ({0})", taginfo.toString()), taginfo.getUrl()) 380 378 ).forEach(taginfoNationalActions::add); 381 379 taginfoNationalActions.stream().map(membershipMenu::add).forEach(membershipMenuTagInfoNatItems::add); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TaginfoAction.java
r16596 r16597 35 35 private TaginfoAction(String name, Supplier<Tag> tagSupplier, Supplier<String> relationTypeSupplier, String taginfoUrl) { 36 36 super(name); 37 this.tagSupplier = tagSupplier;38 this.relationTypeSupplier = relationTypeSupplier;39 this.taginfoUrl = taginfoUrl;37 this.tagSupplier = Objects.requireNonNull(tagSupplier); 38 this.relationTypeSupplier = Objects.requireNonNull(relationTypeSupplier); 39 this.taginfoUrl = withoutTrailingSlash(Objects.requireNonNull(taginfoUrl)); 40 40 } 41 41 … … 47 47 */ 48 48 public TaginfoAction(Supplier<Tag> tagSupplier, Supplier<String> relationTypeSupplier) { 49 super(tr("Go to Taginfo"));49 this(tr("Go to Taginfo"), tagSupplier, relationTypeSupplier, TAGINFO_URL_PROP.get()); 50 50 new ImageProvider("dialogs/taginfo").getResource().attachImageIcon(this, true); 51 putValue(SHORT_DESCRIPTION, tr("Launch browser with Taginfo statistics for selected object"));52 this.tagSupplier = Objects.requireNonNull(tagSupplier);53 this.relationTypeSupplier = Objects.requireNonNull(relationTypeSupplier);54 this.taginfoUrl = getTaginfoUrl(null);55 51 } 56 52 57 53 /** 58 54 * Constructs a new {@code TaginfoAction} with a given URL and optional name suffix. 59 * @param name the action's text as displayed on the menu (if it is added to a menu)60 55 * @param tagTable The tag table. Cannot be null 61 56 * @param tagKeySupplier Finds the key from given row of tag table. Cannot be null … … 63 58 * @param membershipTable The membership table. Can be null 64 59 * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null 65 * @param taginfoUrl Taginfo URL. Can be null 66 * @since 15565 60 * @since 16597 67 61 */ 68 public TaginfoAction(String name, JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier, 69 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier, String taginfoUrl) { 70 super(name); 71 new ImageProvider("dialogs/taginfo").getResource().attachImageIcon(this, true); 72 putValue(SHORT_DESCRIPTION, tr("Launch browser with Taginfo statistics for selected object")); 73 this.taginfoUrl = getTaginfoUrl(taginfoUrl); 62 public TaginfoAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier, 63 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) { 64 this(getTagSupplier(tagTable, tagKeySupplier, tagValuesSupplier), 65 getRelationTypeSupplier(membershipTable, memberValueSupplier)); 66 } 67 68 private static Supplier<Tag> getTagSupplier(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier) { 74 69 Objects.requireNonNull(tagTable); 75 70 Objects.requireNonNull(tagKeySupplier); 76 71 Objects.requireNonNull(tagValuesSupplier); 77 this.tagSupplier =() -> {72 return () -> { 78 73 if (tagTable.getSelectedRowCount() == 1) { 79 74 final int row = tagTable.getSelectedRow(); … … 85 80 return null; 86 81 }; 87 this.relationTypeSupplier = () -> membershipTable != null && membershipTable.getSelectedRowCount() == 1 82 } 83 84 private static Supplier<String> getRelationTypeSupplier(JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) { 85 return () -> membershipTable != null && membershipTable.getSelectedRowCount() == 1 88 86 ? memberValueSupplier.apply(membershipTable.getSelectedRow()).get("type") : null; 89 87 } … … 100 98 OpenBrowser.displayUrl(getTaginfoUrlForRelationType(type)); 101 99 } 102 }103 104 private static String getTaginfoUrl(String taginfoUrl) {105 if (taginfoUrl == null) {106 taginfoUrl = TAGINFO_URL_PROP.get();107 }108 return withoutTrailingSlash(taginfoUrl);109 100 } 110 101 … … 136 127 137 128 /** 129 * Returns a new action which launches the Taginfo instance from the given URL 130 * @param name the action's text as displayed on the menu (if it is added to a menu) 131 * @param taginfoUrl Taginfo URL 132 * @since 16597 133 */ 134 public TaginfoAction withTaginfoUrl(String name, String taginfoUrl) { 135 TaginfoAction action = new TaginfoAction(name, tagSupplier, relationTypeSupplier, taginfoUrl); 136 new ImageProvider("dialogs/taginfo").getResource().attachImageIcon(action, true); 137 return action; 138 } 139 140 /** 138 141 * Returns a new action which launches https://taghistory.raifer.tech/ for the given tag 139 142 * @return a new action … … 141 144 */ 142 145 public TaginfoAction toTagHistoryAction() { 143 String url = withoutTrailingSlash(TAG_HISTORY_URL_PROP.get());146 String url = TAG_HISTORY_URL_PROP.get(); 144 147 return new TaginfoAction(tr("Go to OSM Tag History"), tagSupplier, relationTypeSupplier, url) { 145 148 @Override -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r16596 r16597 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;5 3 6 4 import java.awt.event.FocusEvent; … … 100 98 tagMenu.addSeparator(); 101 99 tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn))); 102 TaginfoAction taginfoAction = new TaginfoAction(t r("Go to Taginfo"), table, tagKeyFn, tagValuesFn, null, null, null);100 TaginfoAction taginfoAction = new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null); 103 101 tagMenu.add(trackJosmAction(taginfoAction.toTagHistoryAction())); 104 102 tagMenu.add(trackJosmAction(taginfoAction));
Note:
See TracChangeset
for help on using the changeset viewer.