Changeset 16839 in josm
- Timestamp:
- 2020-08-03T22:06:42+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenBrowserAction.java
r16833 r16839 18 18 import org.openstreetmap.josm.spi.preferences.Config; 19 19 import org.openstreetmap.josm.tools.ImageProvider; 20 import org.openstreetmap.josm.tools.ImageResource; 20 21 import org.openstreetmap.josm.tools.OpenBrowser; 21 22 import org.openstreetmap.josm.tools.Utils; … … 37 38 */ 38 39 public OpenBrowserAction(String name, String url) { 39 new ImageProvider("help/internet").getResource().attachImageIcon(this, true); 40 this(name, url, null); 41 } 42 43 /** 44 * Constructs a new {@link OpenBrowserAction}. 45 * @param name the name of this action 46 * @param url the URL to launch 47 * @param icon the action icon 48 * @since 16839 49 */ 50 public OpenBrowserAction(String name, String url, ImageResource icon) { 51 if (icon == null) { 52 new ImageProvider("help/internet").getResource().attachImageIcon(this, true); 53 } else { 54 icon.attachImageIcon(this, true); 55 } 40 56 this.urls.add(url); 41 57 this.originalName = name; -
trunk/src/org/openstreetmap/josm/gui/util/AbstractTag2LinkPopupListener.java
r15724 r16839 41 41 42 42 protected void addLinks(JPopupMenu popup, String key, String value) { 43 Tag2Link.getLinksForTag(key, value, (name, url) -> { 43 Tag2Link.getLinksForTag(key, value, (name, url, icon) -> { 44 44 if (itemList.isEmpty()) { 45 45 itemList.add(popup.add(new JPopupMenu.Separator())); … … 49 49 browserActions.get(name).addUrl(url); 50 50 } else { 51 final OpenBrowserAction action = new OpenBrowserAction(name, url); 51 final OpenBrowserAction action = new OpenBrowserAction(name, url, icon); 52 52 browserActions.put(name, action); 53 53 itemList.add(popup.add(action)); -
trunk/src/org/openstreetmap/josm/tools/Tag2Link.java
r16836 r16839 11 11 import java.util.Arrays; 12 12 import java.util.Collections; 13 import java.util.HashMap; 13 14 import java.util.List; 14 15 import java.util.Map; 16 import java.util.Optional; 17 import java.util.function.Supplier; 15 18 import java.util.function.UnaryOperator; 16 19 import java.util.regex.Matcher; … … 23 26 import javax.json.JsonValue; 24 27 28 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 25 29 import org.openstreetmap.josm.data.osm.OsmUtils; 26 30 import org.openstreetmap.josm.data.preferences.CachingProperty; … … 77 81 * @param name the name/label of the link 78 82 * @param url the URL of the link 83 * @param icon the icon to use 79 84 */ 80 void acceptLink(String name, String url); 85 void acceptLink(String name, String url, ImageResource icon); 81 86 } 82 87 … … 142 147 } 143 148 149 final HashMap<OsmPrimitiveType, Optional<ImageResource>> memoize = new HashMap<>(); 150 final Supplier<ImageResource> imageResource = () -> memoize 151 .computeIfAbsent(OsmPrimitiveType.NODE, type -> OsmPrimitiveImageProvider.getResource(key, value, type)) 152 .orElse(null); 153 144 154 // Search 145 155 if (key.matches("^(.+[:_])?name([:_]" + languagePattern + ")?$")) { 156 final ImageResource search = new ImageProvider("dialogs/search").getResource(); 146 157 PREF_SEARCH_ENGINES.get().forEach(url -> 147 linkConsumer.acceptLink(tr("Search on {0}", getHost(url, url)), url.replace("$1", Utils.encodeUrl(value)))); 158 linkConsumer.acceptLink(tr("Search on {0}", getHost(url, url)), url.replace("$1", Utils.encodeUrl(value)), search)); 148 159 } 149 160 … … 155 166 : null; 156 167 if (key.matches("^(.+[:_])?website([:_].+)?$") && validURL != null) { 157 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 168 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 158 169 } 159 170 if (key.matches("^(.+[:_])?source([:_].+)?$") && validURL != null) { 160 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 171 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 161 172 } 162 173 if (key.matches("^(.+[:_])?url([:_].+)?$") && validURL != null) { 163 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 174 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 164 175 } 165 176 if (key.matches("image") && validURL != null) { 166 linkConsumer.acceptLink(tr("View image"), validURL); 177 linkConsumer.acceptLink(tr("View image"), validURL, imageResource.get()); 167 178 } 168 179 … … 173 184 final String lang = Utils.firstNotEmptyString("en", keyMatcher.group("lang"), valueMatcher.group("lang")); 174 185 final String url = "https://" + lang + ".wikipedia.org/wiki/" + valueMatcher.group("article").replace(' ', '_'); 175 linkConsumer.acceptLink(tr("View Wikipedia article"), url); 186 linkConsumer.acceptLink(tr("View Wikipedia article"), url, imageResource.get()); 176 187 } 177 188 if (key.matches("(.*:)?wikidata")) { 178 189 OsmUtils.splitMultipleValues(value) 179 .forEach(q -> linkConsumer.acceptLink(tr("View Wikidata item"), "https://www.wikidata.org/wiki/" + q)); 190 .forEach(q -> linkConsumer.acceptLink(tr("View Wikidata item"), "https://www.wikidata.org/wiki/" + q, imageResource.get())); 180 191 } 181 192 if (key.matches("(.*:)?species")) { 182 193 final String url = "https://species.wikimedia.org/wiki/" + value; 183 linkConsumer.acceptLink(getLinkName(url, key), url); 194 linkConsumer.acceptLink(getLinkName(url, key), url, imageResource.get()); 184 195 } 185 196 if (key.matches("wikimedia_commons|image") && value.matches("(?i:File):.*")) { 186 linkConsumer.acceptLink(tr("View image on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + value); 197 String url = "https://commons.wikimedia.org/wiki/" + value; 198 linkConsumer.acceptLink(tr("View image on Wikimedia Commons"), url, imageResource.get()); 187 199 } 188 200 if (key.matches("wikimedia_commons|image") && value.matches("(?i:Category):.*")) { 189 linkConsumer.acceptLink(tr("View category on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + value); 201 String url = "https://commons.wikimedia.org/wiki/" + value; 202 linkConsumer.acceptLink(tr("View category on Wikimedia Commons"), url, imageResource.get()); 190 203 } 191 204 … … 193 206 final String formattedValue = valueFormatter.getOrDefault(key, x -> x).apply(value); 194 207 final String url = urlFormatter.replace("$1", formattedValue); 195 linkConsumer.acceptLink(getLinkName(url, key), url); 208 linkConsumer.acceptLink(getLinkName(url, key), url, imageResource.get()); 196 209 }); 197 210 } -
trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java
r16836 r16839 20 20 List<String> links = new ArrayList<>(); 21 21 22 void addLink(String name, String url) { 22 void addLink(String name, String url, ImageResource icon) { 23 23 links.add(name + " // " + url); 24 24 }
Note:
See TracChangeset
for help on using the changeset viewer.