Skip to content

Commit

Permalink
ImageDescriptor API for creating based on the bundle
Browse files Browse the repository at this point in the history
Simplifies the access of an image in a bundle.

Test needs to be added, see FileImageDescriptorTest

For eclipse-platform#1177
  • Loading branch information
vogella committed Oct 18, 2023
1 parent 1c6f316 commit 85d8896
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.net.URL;
import java.util.function.Supplier;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;
Expand All @@ -26,6 +28,8 @@
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

/**
* An image descriptor is an object that knows how to create
Expand Down Expand Up @@ -87,6 +91,21 @@ public static ImageDescriptor createFromFile(Class<?> location, String filename)
return new FileImageDescriptor(location, filename);
}

/**
* Creates and returns a new image descriptor from a plug-in.
*
* @param location to determine the bundle which contains the file
* @param filePath path to the file relative in the bundle
* @return a new image descriptor
* @since 3.32
*/
public static ImageDescriptor createFromBundle(Class<?> location, String filePath) {
Bundle bundle = FrameworkUtil.getBundle(location);
URL url = FileLocator.find(bundle, IPath.fromOSString(filePath),
null);
return ImageDescriptor.createFromURL(url);
}

/**
* Creates and returns a new image descriptor given ImageData
* describing the image.
Expand Down

0 comments on commit 85d8896

Please sign in to comment.