Usage of Figure#revalidate and Figure#repaint [message #8613] |
Fri, 07 June 2002 09:02  |
Eclipse User |
|
|
|
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 09:35   |
Eclipse User |
|
|
|
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 #8712 is a reply to message #8701] |
Sat, 08 June 2002 23:49  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.02555 seconds