--- a/openide.util.ui/src/org/openide/util/ImageUtilities.java +++ a/openide.util.ui/src/org/openide/util/ImageUtilities.java @@ -118,6 +118,35 @@ private static final Logger ERR = Logger.getLogger(ImageUtilities.class.getName()); private static final String DARK_LAF_SUFFIX = "_dark"; //NOI18N + + /** + * Finds image for given resource.
+ * If a DarkLAF is enabed, then find images with '_dark' suffix first.
+ * If such an image cannot be found, then find the image using its original file name.
+ *
+ * @param name name of the resource
+ * @param loader classloader to use for locating it, or null to use classpath
+ * @param localizedQuery whether the name contains some localization suffix
+ * and is not optimized/interned
+ */
+ private static Image getIconWithDarkLaFSupport(String resource, ClassLoader loader, boolean localizedQuery) {
+ Image i = null;
+ if (isDarkLaF()) {
+ // NOTE: apply the '_dark' suffix as the very last suffix to support
+ // languages and brandings from NbBundle.getLocalizingSuffixes() like before:
+ //
+ // Example:
+ // a) request 'about.png'
+ // b) apply branding 'nb' -> about_nb.png
+ // c) apply language 'en' -> about_nb_en.png
+ // d) apply dark suffix '_dark' -> about_nb_en_dark.png
+ i = getIcon(addDarkSuffix(resource), loader, localizedQuery);
+ }
+ if (i == null) {
+ i = getIcon(resource, loader, localizedQuery);
+ }
+ return i;
+ }
private ImageUtilities() {
}
@@ -160,13 +189,7 @@
* @return icon's Image or null if the icon cannot be loaded
*/
public static final Image loadImage(String resource, boolean localized) {
- Image image = null;
- if( isDarkLaF() ) {
- image = getIcon(addDarkSuffix(resource), localized);
- }
- if( null == image )
- image = getIcon( resource, localized );
- return image;
+ return getIcon(resource, localized);
}
/**
@@ -184,21 +207,10 @@
* @since 7.22
*/
public static final ImageIcon loadImageIcon( String resource, boolean localized ) {
- Image image = null;
- if( isDarkLaF() ) {
- image = getIcon(addDarkSuffix(resource), localized);
- if( null != image ) {
- return ( ImageIcon ) image2Icon( image );
- }
- }
- image = getIcon( resource, localized );
+ Image image = getIcon(resource, localized);
if( image == null ) {
return null;
}
- RGBImageFilter imageFilter = getImageIconFilter();
- if( null != imageFilter ) {
- image = Toolkit.getDefaultToolkit().createImage( new FilteredImageSource( image.getSource(), imageFilter ) );
- }
return ( ImageIcon ) image2Icon( image );
}
@@ -219,6 +231,19 @@
}
return resourceName + DARK_LAF_SUFFIX;
}
+
+ private static boolean hasDarkSuffix(String resourceName) {
+ if (null == resourceName) {
+ return false;
+ }
+ // f.e. checks for '_dark' in 'about_nb_dark.png'
+ // f.e. checks for '_dark' in 'about_nb_dark'
+ int dotIndex = resourceName.lastIndexOf('.');
+ if (dotIndex > 0) {
+ return resourceName.substring(0, dotIndex).endsWith(DARK_LAF_SUFFIX);
+ }
+ return resourceName.endsWith(DARK_LAF_SUFFIX);
+ }
private static RGBImageFilter getImageIconFilter() {
if( null == imageIconFilter ) {
@@ -470,9 +495,9 @@
Image i;
if (suffix.length() == 0) {
- i = getIcon(resource, loader, false);
+ i = getIconWithDarkLaFSupport(resource, loader, false);
} else {
- i = getIcon(base + suffix + ext, loader, true);
+ i = getIconWithDarkLaFSupport(base + suffix + ext, loader, true);
}
if (i != null) {
@@ -601,6 +626,14 @@
}
name = new String(name).intern(); // NOPMD
result = ToolTipImage.createNew("", result, url);
+ if (isDarkLaF() && hasDarkSuffix(name)) {
+ // a resource with '_dark' suffix like about_dark.png has been found, so no image filter necessary
+ // DO NOT FILTER
+ } else {
+ // apply image filter, if set in UIManager at 'nb.imageicon.filter'
+ // f.e. DarkMetalLAF/DarculaLAF use it to invert icon colors
+ result = applyIconFilter(result);
+ }
cache.put(name, new ActiveRef