Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problems with Thumbnail
Problems with Thumbnail [message #133616] Fri, 21 May 2004 18:38 Go to next message
Jose M Beleta is currently offline Jose M BeletaFriend
Messages: 70
Registered: July 2009
Member
I want to setp up a palette with Icons representing a small image of a
Figure. For doing so I use an ImageDescriptor that returns the image built
by a Thumbnail.

This is the class I wrote:

public class FigureThumbnailImageDescriptor extends ImageDescriptor
{
private class MyThumbnail extends Thumbnail
{
public MyThumbnail(IFigure figure, int size)
{
setSize(size, size);
if (figure.getFont() == null)
figure.setFont(JFaceResources.getDefaultFont());
setSource(figure);
}

protected IFigure getSource()
{
return super.getSource();
}

protected Image getThumbnailImage()
{
return super.getThumbnailImage();
}
}

private MyThumbnail thumbnail;

public FigureThumbnailImageDescriptor(IFigure figure, int icon)
{
thumbnail = new MyThumbnail(figure, (icon == SMALL_ICON) ? 16 : 24);
}

public ImageData getImageData()
{
return thumbnail.getThumbnailImage().getImageData();
}

public IFigure getSource()
{
return thumbnail.getSource();
}

public Image createImage(boolean returnMissingImageOnError, Device device)
{
return thumbnail.getThumbnailImage();
}
}


Things go quite well but I have some very anoying problems:

1) When the editor comes up the correct Icon is not shown in the palette
entry until I hover the mouse cursor over the corresponding entry, until
that only a white square is shown. See attached Fig1.jpg.

2) The background color of the source figure fills all the image not simply
the figure. See attached Fig2.jpg.

3) If the figure has a null font a NullPointerException is thown.

Any hint to solve at least the first problem.

Thank you in advance

Jose M Beleta




  • Attachment: Fig1.jpg
    (Size: 44.99KB, Downloaded 107 times)
  • Attachment: Fig2.jpg
    (Size: 45.91KB, Downloaded 98 times)
Re: Problems with Thumbnail [message #133634 is a reply to message #133616] Fri, 21 May 2004 20:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Some figure have to have a font obviously. If you don't put them in a
canvas, they won't have one because they won't inherit it from their parent
chain.
You can set the font to avoid having to put them in a canvas.


"Jose M Beleta" <beleta@attglobal.net> wrote in message
news:c8lhta$9k3$1@eclipse.org...
> I want to setp up a palette with Icons representing a small image of a
> Figure. For doing so I use an ImageDescriptor that returns the image built
> by a Thumbnail.
>
> This is the class I wrote:
>
> public class FigureThumbnailImageDescriptor extends ImageDescriptor
> {
> private class MyThumbnail extends Thumbnail
> {
> public MyThumbnail(IFigure figure, int size)
> {
> setSize(size, size);
> if (figure.getFont() == null)
> figure.setFont(JFaceResources.getDefaultFont());
> setSource(figure);
> }
>
> protected IFigure getSource()
> {
> return super.getSource();
> }
>
> protected Image getThumbnailImage()
> {
> return super.getThumbnailImage();
> }
> }
>
> private MyThumbnail thumbnail;
>
> public FigureThumbnailImageDescriptor(IFigure figure, int icon)
> {
> thumbnail = new MyThumbnail(figure, (icon == SMALL_ICON) ? 16 : 24);
> }
>
> public ImageData getImageData()
> {
> return thumbnail.getThumbnailImage().getImageData();
> }
>
> public IFigure getSource()
> {
> return thumbnail.getSource();
> }
>
> public Image createImage(boolean returnMissingImageOnError, Device
device)
> {
> return thumbnail.getThumbnailImage();
> }
> }
>
>
> Things go quite well but I have some very anoying problems:
>
> 1) When the editor comes up the correct Icon is not shown in the palette
> entry until I hover the mouse cursor over the corresponding entry, until
> that only a white square is shown. See attached Fig1.jpg.
>
> 2) The background color of the source figure fills all the image not
simply
> the figure. See attached Fig2.jpg.
>
> 3) If the figure has a null font a NullPointerException is thown.
>
> Any hint to solve at least the first problem.
>
> Thank you in advance
>
> Jose M Beleta
>
>
>
>
Re: Problems with Thumbnail [message #133701 is a reply to message #133634] Fri, 21 May 2004 23:19 Go to previous messageGo to next message
Jose M Beleta is currently offline Jose M BeletaFriend
Messages: 70
Registered: July 2009
Member
Yes I realized that, if your look at my code you will note that I set the
font.

> > if (figure.getFont() == null)
> > figure.setFont(JFaceResources.getDefaultFont());

But, what about the other questions?

Jose M Beleta

"Randy Hudson" <none@us.ibm.com> escribi
Re: Problems with Thumbnail [message #133913 is a reply to message #133616] Mon, 24 May 2004 18:59 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
> 1) When the editor comes up the correct Icon is not shown in the palette
> entry until I hover the mouse cursor over the corresponding entry, until
> that only a white square is shown. See attached Fig1.jpg.

There are certain triggers (repainting of the original figure might be
one....you can look at Thumbnail and figure it out) that cause the thumbnail
to update. My conjecture is that no such trigger is fired once the
Thumbnail is created, and hence the image is not yet painted upon. You can
simply try invoking thumbnail.repaint() once it is created, or you can
manually set off one of those triggers that would cause the thumbnail to
update.

"Jose M Beleta" <beleta@attglobal.net> wrote in message
news:c8lhta$9k3$1@eclipse.org...
> I want to setp up a palette with Icons representing a small image of a
> Figure. For doing so I use an ImageDescriptor that returns the image built
> by a Thumbnail.
>
> This is the class I wrote:
>
> public class FigureThumbnailImageDescriptor extends ImageDescriptor
> {
> private class MyThumbnail extends Thumbnail
> {
> public MyThumbnail(IFigure figure, int size)
> {
> setSize(size, size);
> if (figure.getFont() == null)
> figure.setFont(JFaceResources.getDefaultFont());
> setSource(figure);
> }
>
> protected IFigure getSource()
> {
> return super.getSource();
> }
>
> protected Image getThumbnailImage()
> {
> return super.getThumbnailImage();
> }
> }
>
> private MyThumbnail thumbnail;
>
> public FigureThumbnailImageDescriptor(IFigure figure, int icon)
> {
> thumbnail = new MyThumbnail(figure, (icon == SMALL_ICON) ? 16 : 24);
> }
>
> public ImageData getImageData()
> {
> return thumbnail.getThumbnailImage().getImageData();
> }
>
> public IFigure getSource()
> {
> return thumbnail.getSource();
> }
>
> public Image createImage(boolean returnMissingImageOnError, Device
device)
> {
> return thumbnail.getThumbnailImage();
> }
> }
>
>
> Things go quite well but I have some very anoying problems:
>
> 1) When the editor comes up the correct Icon is not shown in the palette
> entry until I hover the mouse cursor over the corresponding entry, until
> that only a white square is shown. See attached Fig1.jpg.
>
> 2) The background color of the source figure fills all the image not
simply
> the figure. See attached Fig2.jpg.
>
> 3) If the figure has a null font a NullPointerException is thown.
>
> Any hint to solve at least the first problem.
>
> Thank you in advance
>
> Jose M Beleta
>
>
>
>
Re: Problems with Thumbnail [message #134143 is a reply to message #133913] Tue, 25 May 2004 18:58 Go to previous messageGo to next message
Jose M Beleta is currently offline Jose M BeletaFriend
Messages: 70
Registered: July 2009
Member
Thank you Pratik for your response, but after looking at your code It seems
that your Thumbnail class is clearly intented to setup a dynamic miniature
overview and not to simply make a static image from a IFigure, that was what
I thought after reading the docs.

Now my class looks this way:

public class FigureThumbnailImageDescriptor extends ImageDescriptor
{
private ImageData imageData;

public FigureThumbnailImageDescriptor(IFigure figure, int size)
{
Image thumbnailImage = new Image(Display.getDefault(), size, size);
GC thumbnailGC = new GC(thumbnailImage);
SWTGraphics thumbnailGraphics = new SWTGraphics(thumbnailGC);
thumbnailGraphics.setBackgroundColor(ColorConstants.button);
thumbnailGraphics.fillRectangle(new Rectangle(0, 0, size, size));
int margin = (size - figure.getSize().width) / 2;
thumbnailGraphics.translate(margin, margin);
figure.paint(thumbnailGraphics);
imageData = thumbnailImage.getImageData();
imageData.transparentPixel = imageData.getPixel(0, 0);
thumbnailGraphics.dispose();
thumbnailGC.dispose();
}

public ImageData getImageData()
{
return imageData;
}
}

By the way calling: image.setBackground(someValue) on the image created from
the descriptor throws an java.lang.ArrayIndexOutOfBoundsException because
the transparent pixel.

Best regards,

Jose M Beleta
"Pratik Shah" <ppshah@us.ibm.com> escribi
Re: Problems with Thumbnail [message #134194 is a reply to message #134143] Tue, 25 May 2004 20:53 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

"Jose M Beleta" <beleta@attglobal.net> wrote in message
news:c904is$dgo$1@eclipse.org...
> Thank you Pratik for your response, but after looking at your code It
seems
> that your Thumbnail class is clearly intented to setup a dynamic miniature
> overview and not to simply make a static image from a IFigure, that was
what

Good point. You should probably just create your own ScaledGraphics and
paint directly onto an Image rather than reusing a figure which isn't even
in a lightweight system. Feel free to open enhancement bugzillas if you
have utility suggestions.
Previous Topic:Help required.
Next Topic:Connection end labels + feedback
Goto Forum:
  


Current Time: Thu Jul 18 03:27:34 GMT 2024

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

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

Back to the top