Lines 118-123
Link Here
|
118 |
private static final Logger ERR = Logger.getLogger(ImageUtilities.class.getName()); |
118 |
private static final Logger ERR = Logger.getLogger(ImageUtilities.class.getName()); |
119 |
|
119 |
|
120 |
private static final String DARK_LAF_SUFFIX = "_dark"; //NOI18N |
120 |
private static final String DARK_LAF_SUFFIX = "_dark"; //NOI18N |
|
|
121 |
|
122 |
/** |
123 |
* Finds image for given resource.<p> |
124 |
* If a DarkLAF is enabed, then find images with '_dark' suffix first. |
125 |
* If such an image cannot be found, then find the image using its original file name. |
126 |
* |
127 |
* @param name name of the resource |
128 |
* @param loader classloader to use for locating it, or null to use classpath |
129 |
* @param localizedQuery whether the name contains some localization suffix |
130 |
* and is not optimized/interned |
131 |
*/ |
132 |
private static Image getIconWithDarkLaFSupport(String resource, ClassLoader loader, boolean localizedQuery) { |
133 |
Image i = null; |
134 |
if (isDarkLaF()) { |
135 |
// NOTE: apply the '_dark' suffix as the very last suffix to support |
136 |
// languages and brandings from NbBundle.getLocalizingSuffixes() like before: |
137 |
// |
138 |
// Example: |
139 |
// a) request 'about.png' |
140 |
// b) apply branding 'nb' -> about_nb.png |
141 |
// c) apply language 'en' -> about_nb_en.png |
142 |
// d) apply dark suffix '_dark' -> about_nb_en_dark.png |
143 |
i = getIcon(addDarkSuffix(resource), loader, localizedQuery); |
144 |
} |
145 |
if (i == null) { |
146 |
i = getIcon(resource, loader, localizedQuery); |
147 |
} |
148 |
return i; |
149 |
} |
121 |
|
150 |
|
122 |
private ImageUtilities() { |
151 |
private ImageUtilities() { |
123 |
} |
152 |
} |
Lines 160-172
Link Here
|
160 |
* @return icon's Image or null if the icon cannot be loaded |
189 |
* @return icon's Image or null if the icon cannot be loaded |
161 |
*/ |
190 |
*/ |
162 |
public static final Image loadImage(String resource, boolean localized) { |
191 |
public static final Image loadImage(String resource, boolean localized) { |
163 |
Image image = null; |
192 |
return getIcon(resource, localized); |
164 |
if( isDarkLaF() ) { |
|
|
165 |
image = getIcon(addDarkSuffix(resource), localized); |
166 |
} |
167 |
if( null == image ) |
168 |
image = getIcon( resource, localized ); |
169 |
return image; |
170 |
} |
193 |
} |
171 |
|
194 |
|
172 |
/** |
195 |
/** |
Lines 184-204
Link Here
|
184 |
* @since 7.22 |
207 |
* @since 7.22 |
185 |
*/ |
208 |
*/ |
186 |
public static final ImageIcon loadImageIcon( String resource, boolean localized ) { |
209 |
public static final ImageIcon loadImageIcon( String resource, boolean localized ) { |
187 |
Image image = null; |
210 |
Image image = getIcon(resource, localized); |
188 |
if( isDarkLaF() ) { |
|
|
189 |
image = getIcon(addDarkSuffix(resource), localized); |
190 |
if( null != image ) { |
191 |
return ( ImageIcon ) image2Icon( image ); |
192 |
} |
193 |
} |
194 |
image = getIcon( resource, localized ); |
195 |
if( image == null ) { |
211 |
if( image == null ) { |
196 |
return null; |
212 |
return null; |
197 |
} |
213 |
} |
198 |
RGBImageFilter imageFilter = getImageIconFilter(); |
|
|
199 |
if( null != imageFilter ) { |
200 |
image = Toolkit.getDefaultToolkit().createImage( new FilteredImageSource( image.getSource(), imageFilter ) ); |
201 |
} |
202 |
return ( ImageIcon ) image2Icon( image ); |
214 |
return ( ImageIcon ) image2Icon( image ); |
203 |
} |
215 |
} |
204 |
|
216 |
|
Lines 219-224
Link Here
|
219 |
} |
231 |
} |
220 |
return resourceName + DARK_LAF_SUFFIX; |
232 |
return resourceName + DARK_LAF_SUFFIX; |
221 |
} |
233 |
} |
|
|
234 |
|
235 |
private static boolean hasDarkSuffix(String resourceName) { |
236 |
if (null == resourceName) { |
237 |
return false; |
238 |
} |
239 |
// f.e. checks for '_dark' in 'about_nb_dark.png' |
240 |
// f.e. checks for '_dark' in 'about_nb_dark' |
241 |
int dotIndex = resourceName.lastIndexOf('.'); |
242 |
if (dotIndex > 0) { |
243 |
return resourceName.substring(0, dotIndex).endsWith(DARK_LAF_SUFFIX); |
244 |
} |
245 |
return resourceName.endsWith(DARK_LAF_SUFFIX); |
246 |
} |
222 |
|
247 |
|
223 |
private static RGBImageFilter getImageIconFilter() { |
248 |
private static RGBImageFilter getImageIconFilter() { |
224 |
if( null == imageIconFilter ) { |
249 |
if( null == imageIconFilter ) { |
Lines 470-478
Link Here
|
470 |
Image i; |
495 |
Image i; |
471 |
|
496 |
|
472 |
if (suffix.length() == 0) { |
497 |
if (suffix.length() == 0) { |
473 |
i = getIcon(resource, loader, false); |
498 |
i = getIconWithDarkLaFSupport(resource, loader, false); |
474 |
} else { |
499 |
} else { |
475 |
i = getIcon(base + suffix + ext, loader, true); |
500 |
i = getIconWithDarkLaFSupport(base + suffix + ext, loader, true); |
476 |
} |
501 |
} |
477 |
|
502 |
|
478 |
if (i != null) { |
503 |
if (i != null) { |
Lines 601-606
Link Here
|
601 |
} |
626 |
} |
602 |
name = new String(name).intern(); // NOPMD |
627 |
name = new String(name).intern(); // NOPMD |
603 |
result = ToolTipImage.createNew("", result, url); |
628 |
result = ToolTipImage.createNew("", result, url); |
|
|
629 |
if (isDarkLaF() && hasDarkSuffix(name)) { |
630 |
// a resource with '_dark' suffix like about_dark.png has been found, so no image filter necessary |
631 |
// DO NOT FILTER |
632 |
} else { |
633 |
// apply image filter, if set in UIManager at 'nb.imageicon.filter' |
634 |
// f.e. DarkMetalLAF/DarculaLAF use it to invert icon colors |
635 |
result = applyIconFilter(result); |
636 |
} |
604 |
cache.put(name, new ActiveRef<String>(result, cache, name)); |
637 |
cache.put(name, new ActiveRef<String>(result, cache, name)); |
605 |
return result; |
638 |
return result; |
606 |
} else { // no icon found |
639 |
} else { // no icon found |
Lines 649-659
Link Here
|
649 |
System.out.println("INTERRUPTED while loading Image"); |
682 |
System.out.println("INTERRUPTED while loading Image"); |
650 |
} |
683 |
} |
651 |
|
684 |
|
652 |
assert (tracker.statusID(id, false) == MediaTracker.COMPLETE) : "Image loaded"; |
685 |
// #262804 assertation disabled because of error, when using ImageFilter |
|
|
686 |
// assert (tracker.statusID(id, false) == MediaTracker.COMPLETE) : "Image loaded"; |
653 |
tracker.removeImage(image, id); |
687 |
tracker.removeImage(image, id); |
654 |
} |
688 |
} |
655 |
} |
689 |
} |
656 |
|
690 |
|
|
|
691 |
private static Image applyIconFilter(Image image) { |
692 |
if (image == null) { |
693 |
return null; |
694 |
} |
695 |
RGBImageFilter imageFilter = getImageIconFilter(); |
696 |
if (imageFilter != null) { |
697 |
return Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), imageFilter)); |
698 |
} |
699 |
return image; |
700 |
} |
701 |
|
657 |
private static final Image doMergeImages(Image image1, Image image2, int x, int y) { |
702 |
private static final Image doMergeImages(Image image1, Image image2, int x, int y) { |
658 |
ensureLoaded(image1); |
703 |
ensureLoaded(image1); |
659 |
ensureLoaded(image2); |
704 |
ensureLoaded(image2); |