path to images? [message #448952] |
Sun, 16 January 2005 12:02  |
Eclipse User |
|
|
|
Hi,
Can anyone tell me what the path (for loading etc.) to any image files I
have in my plugin?
e.g. if I have a directory icons in my plugin project, what is the path to
icons/mypic.gif
?? I cannot get anything other than a hardcoded full path to work.
cheers
David
|
|
|
|
Re: path to images? [message #449021 is a reply to message #448953] |
Mon, 17 January 2005 16:34  |
Eclipse User |
|
|
|
Bo Majewski wrote:
> On Sun, 16 Jan 2005 17:02:27 +0000, David Black wrote:
>
>
>>Can anyone tell me what the path (for loading etc.) to any image files I
>>have in my plugin?
>
>
> While the following solution is not the simplest, I prefer it to other
> options. Create the following plug-in
>
> public class MyPlugin extends AbstractUIPlugin {
> private static MyPlugin instance;
>
> public MyPlugin() {
> MyPlugin.instance = this;
> }
>
> public static MyPlugin getDefault() {
> return MyPlugin.instance;
> }
>
> public String getPluginId() {
> return (this.getBundle().getSymbolicName());
> }
>
> public Image getImage(String path) {
> Image img = this.getImageRegistry().get(path);
>
> if (img == null) {
> img = getImageDescriptor(path).createImage();
> this.getImageRegistry().put(path, img);
> }
>
> return (img);
> }
>
> public ImageDescriptor getImageDescriptor(String path) {
> ImageDescriptor desc =
> AbstractUIPlugin.imageDescriptorFromPlugin(this.getPluginId( ), path);
> return (desc == null? ImageDescriptor.getMissingImageDescriptor() : desc);
> }
> }
>
> Now, in your code, you load images using the following code:
>
> Image img = MyPlugin.getDefault().getImage("path/to/my/image.gif");
>
> Images must be stored in your plug-in folder or in sub-folder. The added
> benefit of this solution is that your plug-in manages loaded images and
> you do not need to dispose() them. It also makes easy to load image
> descriptors.
>
cheers, that works great
thanks
|
|
|
Powered by
FUDForum. Page generated in 0.11451 seconds