Changeset 16597 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TaginfoAction.java
- Timestamp:
- 2020-06-11T11:32:21+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.