Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Usage of Figure#revalidate and Figure#repaint
Usage of Figure#revalidate and Figure#repaint [message #8613] Fri, 07 June 2002 13:02 Go to next message
Eclipse UserFriend
Originally posted by: g.wagenknecht.intershop.de

Hi!

I have created the following figure.

------------------------------------------------------------ ------
public class MyFigure extends Figure
{
private Label myLabel;

// MyCompositeImageDescriptor inherits from
// org.eclipse.jface.resource.CompositeImageDescriptor
private MyCompositeImageDescriptor myCompositeImageDescriptor;

public MyFigure( ImageDescriptor image )
{
super();

setLayoutManager(new StackLayout());

myCompositeImageDescriptor = new MyCompositeImageDescriptor(image);
myLabel = new Label( myCompositeImageDescriptor.createImage() );
add(myLabel);
}

protected void setBaseImage( ImageDescriptor image )
{
myCompositeImageDescriptor.setBaseImage( image );
}
}
------------------------------------------------------------ ------

Now, if I call #setBaseImage the new image is set, but not shown. (Maybe
this
a bug, but I think this happens because of design.)

I have to tell myLabel to use the new image. For that I must call
"myLabel.setIcon(myCompositeImageDescriptor.createImage())".

If I do this in #setBaseImage, everything is fine. But I want a more generic
solution because I don't want inherited figures to do this manually.

Is there a better way of doing this? Should I
overwrite repaint() or revalidate() method of the figure?

Cu, Gunnar
Re: Usage of Figure#revalidate and Figure#repaint [message #8624 is a reply to message #8613] Fri, 07 June 2002 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

Calling myCompositeImageDescriptor.setBaseImage() does *NOT* update the
Image that was returned by compDesc.createImage(). Unless you've done
something in your subclass.

CompositeImageDescriptor is a workaround for the fact that SWT Tree/Table
can only have a single Icon. It has limitations. For example, if you have
1 base Image and 8 different decorators, this leads to 256 Images, which
takes up 256 OS resource handles. In draw2d you could acheive the same
thing by calling graphics.drawImage() a few times with the various
decorators. IMO, there is no motivation to compose the Image.

What are you trying to create? An Icon with a few decorations or ports on
it?

"Gunnar Wagenknecht" <g.wagenknecht@intershop.de> wrote in message
news:adq9ov$f13$1@rogue.oti.com...
> Hi!
>
> I have created the following figure.
>
> ------------------------------------------------------------ ------
> public class MyFigure extends Figure
> {
> private Label myLabel;
>
> // MyCompositeImageDescriptor inherits from
> // org.eclipse.jface.resource.CompositeImageDescriptor
> private MyCompositeImageDescriptor myCompositeImageDescriptor;
>
> public MyFigure( ImageDescriptor image )
> {
> super();
>
> setLayoutManager(new StackLayout());
>
> myCompositeImageDescriptor = new
MyCompositeImageDescriptor(image);
> myLabel = new Label( myCompositeImageDescriptor.createImage() );
> add(myLabel);
> }
>
> protected void setBaseImage( ImageDescriptor image )
> {
> myCompositeImageDescriptor.setBaseImage( image );
> }
> }
> ------------------------------------------------------------ ------
>
> Now, if I call #setBaseImage the new image is set, but not shown. (Maybe
> this
> a bug, but I think this happens because of design.)
>
> I have to tell myLabel to use the new image. For that I must call
> "myLabel.setIcon(myCompositeImageDescriptor.createImage())".
>
> If I do this in #setBaseImage, everything is fine. But I want a more
generic
> solution because I don't want inherited figures to do this manually.
>
> Is there a better way of doing this? Should I
> overwrite repaint() or revalidate() method of the figure?
>
> Cu, Gunnar
>
>
>
Re: Usage of Figure#revalidate and Figure#repaint [message #8651 is a reply to message #8624] Fri, 07 June 2002 15:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: g.wagenknecht.intershop.de

Hi!

"Randy Hudson" <none@ibm.com> schrieb im Newsbeitrag
news:adqbp3$g6k$1@rogue.oti.com...
> Calling myCompositeImageDescriptor.setBaseImage() does *NOT* update the
> Image that was returned by compDesc.createImage(). Unless you've done
> something in your subclass.

#setBaseImage is a new method in MyCompositeImageDescriptor.

> CompositeImageDescriptor is a workaround for the fact that SWT Tree/Table
> can only have a single Icon. It has limitations. For example, if you
have
> 1 base Image and 8 different decorators, this leads to 256 Images, which
> takes up 256 OS resource handles. In draw2d you could acheive the same
> thing by calling graphics.drawImage() a few times with the various
> decorators. IMO, there is no motivation to compose the Image.

Mhm. Initial idea was reuse. MyCompositeImageDescriptor was implemented for
a SWT Tree/Table. A figure with such a image is used for EditParts.

Where do I use "graphics.drawImage()" (which mehtod to overwrite in which
class)?

> What are you trying to create? An Icon with a few decorations or ports on
> it?

Exactly.

Cu, Gunnar
Re: Usage of Figure#revalidate and Figure#repaint [message #8677 is a reply to message #8651] Fri, 07 June 2002 18:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

"Gunnar Wagenknecht" <g.wagenknecht@intershop.de> wrote in message
news:adqh1i$jkt$1@rogue.oti.com...
> Hi!
>
> "Randy Hudson" <none@ibm.com> schrieb im Newsbeitrag
> news:adqbp3$g6k$1@rogue.oti.com...
> > Calling myCompositeImageDescriptor.setBaseImage() does *NOT* update the
> > Image that was returned by compDesc.createImage(). Unless you've done
> > something in your subclass.
>
> #setBaseImage is a new method in MyCompositeImageDescriptor.

right, but the image returned by compDesc.getImage() will not be updated.
look at your method impl. Unless you are creating a GC, and repainting the
descriptor on the Image, it is basically 'immutable'.

So. do this:

protected void setBaseImage( ImageDescriptor image )
{
myCompositeImageDescriptor.setBaseImage( image );
myLabel.setImage(myCompositeImageDescriptor.createImage();
}

You should not that this is porbably a memory *LEAK*. I believe composite
ImageDescriptor will hold onto the original composed Image from the previous
time you called setBaseImage(). So, every time you change the base you will
be leaking one Image
Re: Usage of Figure#revalidate and Figure#repaint [message #8701 is a reply to message #8677] Sat, 08 June 2002 07:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: g.wagenknecht.planet-wagenknecht.de

Hi!

"Randy Hudson" <none@ibm.com> schrieb im Newsbeitrag
news:adqsq1$q44$1@rogue.oti.com...

> You should not that this is porbably a memory *LEAK*. I believe composite
> ImageDescriptor will hold onto the original composed Image from the
previous
> time you called setBaseImage(). So, every time you change the base you
will
> be leaking one Image

So what do you suggest?? You mentiond I could draw the images myself
(graphics#drawImage). Where do I have do this? I'm not sure.

Cu, Gunnar
Re: Usage of Figure#revalidate and Figure#repaint [message #8712 is a reply to message #8701] Sun, 09 June 2002 03:49 Go to previous message
Eclipse UserFriend
Originally posted by: none.ibm.com

> > You should not that this is porbably a memory *LEAK*. I believe
composite
> > ImageDescriptor will hold onto the original composed Image from the
> previous
> > time you called setBaseImage(). So, every time you change the base you
> will
> > be leaking one Image
>
> So what do you suggest?? You mentiond I could draw the images myself
> (graphics#drawImage). Where do I have do this? I'm not sure.

Actually, ComposedImageDescriptor doesn't cache Images because Descriptors
by definition don't manage an Image. So, when you change the base image
*you* have to dispose the old one. It's your Image at that point, so there
should be no leak.

The caches I was thinking of are in ActionContributionItem and some
Decorator class.
Previous Topic:F1(GTK) and GEF
Next Topic:Warning about using new features in GEF
Goto Forum:
  


Current Time: Sat Jul 27 14:05:03 GMT 2024

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

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

Back to the top