eirikbakke commented on a change in pull request #1278: [NETBEANS-2604] Support
SVG icon loading from ImageUtilities
URL: https://github.com/apache/netbeans/pull/1278#discussion_r291396584
##########
File path: platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
##########
@@ -353,62 +429,122 @@ public static Icon createDisabledIcon(Icon icon) {
*/
public static Image createDisabledImage(Image image) {
Parameters.notNull("image", image);
- return LazyDisabledIcon.createDisabledImage(image);
+ // Go through FilteredIcon to preserve scalable icons.
+ return icon2Image(createDisabledIcon(image2Icon(image)));
+ }
+
+ /**
+ * Get an SVG icon loader, if the appropriate service provider module is
installed. To ensure
+ * lazy loading of the SVG loader module, this method should only be
called when there actually
+ * exists an SVG file to load. The result is cached.
+ *
+ * @return may be null
+ */
+ private static SVGLoader getSVGLoader() {
+ /* "Objects contained in the default lookup are instantiated lazily
when first requested."
+ ( http://wiki.netbeans.org/DevFaqLookupDefault ) So the SVGLoader
implementation module will
+ only be loaded the first time an SVG file is actually encountered for
loading, rather than,
+ for instance, when the startup splash screen initializes
ImageUtilities to load its PNG
+ image. This was confirmed by printing a debugging message from a
static initializer in
+ SVGLoaderImpl in the implementation module; the message appears well
after the splash
+ screen's PNG graphics first becomes visible. */
+ return svgLoaderLoader.getLoader();
}
/**
* Get the class loader from lookup.
* Since this is done very frequently, it is wasteful to query lookup each
time.
* Instead, remember the last result and just listen for changes.
*/
- static ClassLoader getLoader() {
- Object is = currentLoader;
- if (is instanceof ClassLoader) {
- return (ClassLoader)is;
- }
-
- currentLoader = Thread.currentThread();
-
- if (loaderQuery == null) {
- loaderQuery = Lookup.getDefault().lookup(new
Lookup.Template<ClassLoader>(ClassLoader.class));
- loaderQuery.addLookupListener(
- new LookupListener() {
- public void resultChanged(LookupEvent ev) {
- ERR.fine("Loader cleared"); // NOI18N
- currentLoader = null;
- }
- }
- );
+ static ClassLoader getClassLoader() {
+ return classLoaderLoader.getLoader();
+ }
+
+ private static final class CachedLookupLoader<T> {
Review comment:
Yeah, the existing code seems to assume that doing a lookup is a really
expensive thing to do. And there even was a race condition bug in the past,
indicating that the lookup did sometimes take a fair bit of time to complete
(the longer it takes, the higher the chance of concurrent executions). My bet
is that this is something that is, or was, expensive primarily at boot time,
when lots of different classes are being loaded and nothing has been JITed yet.
I read over the new code again, and I think it basically preserves the old
behavior, whether or not it is still needed.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
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