Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.util.function.Supplier;

import org.eclipse.jface.util.Policy;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;
Expand Down Expand Up @@ -76,6 +78,9 @@ protected ImageDescriptor() {
ImageDescriptor(boolean shouldBeCached) {
super(shouldBeCached);
}

private static final ImageDescriptor NULL_IMAGE = createFromImageDataProvider(z -> null);

/**
* Creates and returns a new image descriptor from a file.
*
Expand All @@ -84,7 +89,21 @@ protected ImageDescriptor() {
* @return a new image descriptor
*/
public static ImageDescriptor createFromFile(Class<?> location, String filename) {
return new FileImageDescriptor(location, filename);
URL url;
if (location == null) {
try {
url = Path.of(filename).toUri().toURL();
} catch (MalformedURLException e) {
Policy.logException(e);
url = null;
}
} else {
url = location.getResource(filename);
}
if (url == null) {
return NULL_IMAGE; // Defer failure to the time when the image is created
}
return new URLImageDescriptor(url);
}

/**
Expand Down
Loading
Loading