Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Question about SWT Image, ImageDescriptor, ImageData in the context of GEF
Question about SWT Image, ImageDescriptor, ImageData in the context of GEF [message #179140] Mon, 25 April 2005 17:00 Go to next message
Eclipse UserFriend
Originally posted by: d.ozsen.blueyonder.co.uk

Hello there,

I have a question regarding SWT Images.

I am developing a graphical editor plug-in using the GEF. Currently I am
working on the editor's palette (using the GEF one). Now when I create a
PaletteDrawer and entries, I have to supply the icons I want the to use
in the form of an ImageDescriptor object.

I am creating an SWT Image object for each of these icons anyway for use
elsewhere, and I am reusing some of these objects several times (this is
ok, as they are never dynamically changed). The Image objects are stored
in a central place in a "cache" like collection, so that they can be
disposed of when the plug-in is stopped. In order to do that I just call
the dispose method on all the Images in the collection from the stop()
method of my plug-in's AbstractUIPlugin subclass.

So far, so good. Now to get back to the Palette entries, I use my own
subclass of ImageDescriptor in order to pass the icon image for each
Palette category/entry. I do this by passing an SWT Image that already
exists to the constructor of my ImageDescriptor subclass and then
passing the ImageDescriptor object to the PaletteDrawer constructor. See
the code below this e-mail.

My question is this: Is it safe to do this with respect to Image memory
management? Or could there be a problem with this once I am disposing
the Image objects (in the plugin class's stop() method)? I am assuming
that it shouldn't be a problem because the ImageData object (which the
ImageDescriptor object holds a reference to) should exist even with the
Image disposed. But then again, I am not 100% sure.
Any comment would be appreciated!

Regards,

Deniz

------------------------------------------------------------ --------

Code that creates a PaletteDrawer:

PaletteDrawer drawer = new PaletteDrawer(
VIEWCOMPS_DRAWER_LABEL,
new ExistingImageDescriptor(
MyPlugin.createImage(ImageConstants.CATEGORY_VIEW)));

Note: MyPlugin is my plug-in's AbstractUIPlugin class, which manages the
Image cache. The method creatImage(...) returns an SWT Image object.

------------------------------------------------------------ --------

My own ImageDescriptor subclass:

public class ExistingImageDescriptor extends ImageDescriptor
{
private ImageData iImageData = null;

/**
* Creates a new ExistingImageDescriptor, taking the specified Image
* object's ImageData as this descriptor's image data
*/
public ExistingImageDescriptor(Image aImage)
{
super();
iImageData = aImage.getImageData();
}

/**
* @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
*/
public ImageData getImageData() { return iImageData; }

}
Re: Question about SWT Image, ImageDescriptor, ImageData in the context of GEF [message #179152 is a reply to message #179140] Mon, 25 April 2005 17:12 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

I think that what you are doing is fine. If your plug-in is stopping, there
should not be any editors opened.
Disposing the images on workbench shutdown is not really necessary since the
OS will reclaim all resource for a process that has completed. But, you'd
want to be sure that plug-in stop == process termination.

"Deniz Ozsen" <d.ozsen@blueyonder.co.uk> wrote in message
news:d4j7qr$s22$1@news.eclipse.org...
> Hello there,
>
> I have a question regarding SWT Images.
>
> I am developing a graphical editor plug-in using the GEF. Currently I am
> working on the editor's palette (using the GEF one). Now when I create a
> PaletteDrawer and entries, I have to supply the icons I want the to use in
> the form of an ImageDescriptor object.
>
> I am creating an SWT Image object for each of these icons anyway for use
> elsewhere, and I am reusing some of these objects several times (this is
> ok, as they are never dynamically changed). The Image objects are stored
> in a central place in a "cache" like collection, so that they can be
> disposed of when the plug-in is stopped. In order to do that I just call
> the dispose method on all the Images in the collection from the stop()
> method of my plug-in's AbstractUIPlugin subclass.
>
> So far, so good. Now to get back to the Palette entries, I use my own
> subclass of ImageDescriptor in order to pass the icon image for each
> Palette category/entry. I do this by passing an SWT Image that already
> exists to the constructor of my ImageDescriptor subclass and then passing
> the ImageDescriptor object to the PaletteDrawer constructor. See the code
> below this e-mail.
>
> My question is this: Is it safe to do this with respect to Image memory
> management? Or could there be a problem with this once I am disposing the
> Image objects (in the plugin class's stop() method)? I am assuming that it
> shouldn't be a problem because the ImageData object (which the
> ImageDescriptor object holds a reference to) should exist even with the
> Image disposed. But then again, I am not 100% sure.
> Any comment would be appreciated!
>
> Regards,
>
> Deniz
>
> ------------------------------------------------------------ --------
>
> Code that creates a PaletteDrawer:
>
> PaletteDrawer drawer = new PaletteDrawer(
> VIEWCOMPS_DRAWER_LABEL,
> new ExistingImageDescriptor(
> MyPlugin.createImage(ImageConstants.CATEGORY_VIEW)));
>
> Note: MyPlugin is my plug-in's AbstractUIPlugin class, which manages the
> Image cache. The method creatImage(...) returns an SWT Image object.
>
> ------------------------------------------------------------ --------
>
> My own ImageDescriptor subclass:
>
> public class ExistingImageDescriptor extends ImageDescriptor
> {
> private ImageData iImageData = null;
>
> /**
> * Creates a new ExistingImageDescriptor, taking the specified Image
> * object's ImageData as this descriptor's image data
> */
> public ExistingImageDescriptor(Image aImage)
> {
> super();
> iImageData = aImage.getImageData();
> }
>
> /**
> * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
> */
> public ImageData getImageData() { return iImageData; }
>
> }
Previous Topic:How to refresh/redraw the whole of the container edit part
Next Topic:Custom selection frame
Goto Forum:
  


Current Time: Tue Apr 23 08:23:08 GMT 2024

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

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

Back to the top