mbien commented on code in PR #8114:
URL: https://github.com/apache/netbeans/pull/8114#discussion_r1904215473
##########
platform/openide.util.ui/src/org/openide/util/ImageUtilities.java:
##########
@@ -210,6 +210,59 @@ public static final Image loadImage(String resource,
boolean localized) {
return loadImageInternal(resource, localized);
}
+ /**
+ * Load an image from an URL. If the URL uses the {@code nbresloc}
protocol, it is loaded using
+ * the resource loading mechanism provided by {@link
#loadImage(java.lang.String)}. An SVG
+ * image may be substituted when available.
+ *
+ * <p>This method is intended for use only when a URL must be used instead
of a resource path,
+ * e.g. in the implementation of pre-existing NetBeans APIs.
+ *
+ * @param url the URL of the image, possibly with the nbresloc protocol
+ * @return the loaded image, or either null or an uninitialized image if
the image was not
+ * available
+ * @since 7.34
+ */
+ public static final Image loadImage(URL url) {
+ Parameters.notNull("icon", url);
+ if (url.getProtocol().equals("nbresloc")) { // NOI18N
+ // Omit the initial slash of the path.
+ return loadImage(url.getPath().substring(1));
+ } else {
+ /* Observed to return an image with size (-1, -1) if URL points to
a non-existent file
+ (after ensureLoaded(Image) is called). */
+ return Toolkit.getDefaultToolkit().createImage(url);
Review Comment:
maybe this makes the decision easier which type to incentivize ;) JMH
HashMap key benchmark:
<details>
I think this ran the last time on JDK 19 or so
```
//Strings
//# Warmup Iteration 1: 2476.256 ns/op
//# Warmup Iteration 2: 2385.143 ns/op
//# Warmup Iteration 3: 2296.727 ns/op
//# Warmup Iteration 4: 2401.484 ns/op
//# Warmup Iteration 5: 2421.929 ns/op
//
//URIs
//# Warmup Iteration 1: 2657.392 ns/op
//# Warmup Iteration 2: 2493.757 ns/op
//# Warmup Iteration 3: 2411.478 ns/op
//# Warmup Iteration 4: 2483.226 ns/op
//# Warmup Iteration 5: 2504.854 ns/op
//
//URLs (web resources)
//# Warmup Iteration 1: 69965131912.000 ns/op
//# Warmup Iteration 2: 7502.561 ns/op
//# Warmup Iteration 3: 7339.799 ns/op
//# Warmup Iteration 4: 7034.253 ns/op
//# Warmup Iteration 5: 7331.328 ns/op
// URLs (files)
//# Warmup Iteration 1: 6775.436 ns/op
//# Warmup Iteration 2: 6719.117 ns/op
//# Warmup Iteration 3: 6349.700 ns/op
//# Warmup Iteration 4: 6754.676 ns/op
//# Warmup Iteration 5: 6851.270 ns/op
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists