Skip to content

Commit 1f8f8eb

Browse files
committed
Merge FileImageDescriptor into URLImageDescriptor and clean it up
In it's core the FileImageDescriptor queries the given context class for a resource at the given path and then operates on the returned URL or directly fetches the resource's stream. By optaining the resource's URL immediately and using an URLImageDescriptor with it a lot of similar code and logic from the FileImageDescriptor can be saved. Additionally apply a few minor code clean-ups and remove a unused internal method.
1 parent 9a586ab commit 1f8f8eb

File tree

3 files changed

+75
-406
lines changed

3 files changed

+75
-406
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java

-313
This file was deleted.

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ImageDescriptor.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ protected ImageDescriptor() {
7676
ImageDescriptor(boolean shouldBeCached) {
7777
super(shouldBeCached);
7878
}
79+
80+
private static final ImageDescriptor NULL_IMAGE = createFromImageDataProvider(z -> null);
81+
7982
/**
8083
* Creates and returns a new image descriptor from a file.
8184
*
@@ -84,7 +87,11 @@ protected ImageDescriptor() {
8487
* @return a new image descriptor
8588
*/
8689
public static ImageDescriptor createFromFile(Class<?> location, String filename) {
87-
return new FileImageDescriptor(location, filename);
90+
URL url = location != null ? location.getResource(filename) : null;
91+
if (url == null) {
92+
return NULL_IMAGE; // Defer failure to the time when the image is created
93+
}
94+
return new URLImageDescriptor(url);
8895
}
8996

9097
/**

0 commit comments

Comments
 (0)