Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » path to images?
path to images? [message #448952] Sun, 16 January 2005 17:02 Go to next message
David Black is currently offline David BlackFriend
Messages: 5
Registered: July 2009
Junior Member
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 #448953 is a reply to message #448952] Sun, 16 January 2005 20:31 Go to previous messageGo to next message
Bo Majewski is currently offline Bo MajewskiFriend
Messages: 17
Registered: July 2009
Junior Member
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.
Re: path to images? [message #449021 is a reply to message #448953] Mon, 17 January 2005 21:34 Go to previous message
David Black is currently offline David BlackFriend
Messages: 5
Registered: July 2009
Junior Member
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
Previous Topic:SWT Stylesheets
Next Topic:View refresh problem
Goto Forum:
  


Current Time: Thu Apr 25 00:31:10 GMT 2024

Powered by FUDForum. Page generated in 0.03139 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top