Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Painting figures with SWTGraphics does not work any longer.
Painting figures with SWTGraphics does not work any longer. [message #231243] Thu, 01 March 2007 14:41 Go to next message
Thomas Maier is currently offline Thomas MaierFriend
Messages: 117
Registered: July 2009
Senior Member
Hi all,

in my code I used to have a loop that painted a set of figures to an
org.eclipse.swt.graphics.Image:

Image image = new Image(Display.getDefault(), imageSize.width, imageSize.height);
for (IFigure figure: previewedFigures)
{
GC gc = new GC(image);
gc.setAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
gc.setTextAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
Graphics graphics = new SWTGraphics(gc);
graphics.translate(selectionBounds.getLocation().negate());
figure.paint(graphics);
graphics.dispose();
gc.dispose ();
}


It worked fine with Eclipse 3.1. With 3.2 it does not work any longer.
I get a white image and no figures are drawn. Actually they seem to be
drawn because to check I overrode a couple of draw methods and they are
really called, even with sane parameters. However, the image is plain
white. Strangely, when I add a draw in the loop myself, like e.g.

graphics.setForegroundColor(ColorConstants.green);
graphics.drawRectangle(3, 4, imageSize.width-6, imageSize.height-8);


the rectangle is there. Is there anything I am doing wrong here (which
just _happened_ to work in earlier versions)? Should that actually be
posted on the SWT list?

Thanks and regards, Thomas.
Re: Painting figures with SWTGraphics does not work any longer. [message #231289 is a reply to message #231243] Fri, 02 March 2007 15:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

I bet all your figures are sized 0,0. They used to have a default size of
60x40 or something, and that default size was changed to be 0,0 afterwards.

"Thomas Maier" <Thomas.Maier@uni-kassel.de> wrote in message
news:45E6E602.1070601@uni-kassel.de...
> Hi all,
>
> in my code I used to have a loop that painted a set of figures to an
> org.eclipse.swt.graphics.Image:
>
> Image image = new Image(Display.getDefault(), imageSize.width,
> imageSize.height);
> for (IFigure figure: previewedFigures)
> {
> GC gc = new GC(image);
> gc.setAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
> gc.setTextAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
> Graphics graphics = new SWTGraphics(gc);
> graphics.translate(selectionBounds.getLocation().negate());
> figure.paint(graphics);
> graphics.dispose();
> gc.dispose ();
> }
>
>
> It worked fine with Eclipse 3.1. With 3.2 it does not work any longer.
> I get a white image and no figures are drawn. Actually they seem to be
> drawn because to check I overrode a couple of draw methods and they are
> really called, even with sane parameters. However, the image is plain
> white. Strangely, when I add a draw in the loop myself, like e.g.
>
> graphics.setForegroundColor(ColorConstants.green);
> graphics.drawRectangle(3, 4, imageSize.width-6, imageSize.height-8);
>
>
> the rectangle is there. Is there anything I am doing wrong here (which
> just _happened_ to work in earlier versions)? Should that actually be
> posted on the SWT list?
>
> Thanks and regards, Thomas.
Re: Painting figures with SWTGraphics does not work any longer. [message #231367 is a reply to message #231289] Wed, 07 March 2007 10:57 Go to previous messageGo to next message
Thomas Maier is currently offline Thomas MaierFriend
Messages: 117
Registered: July 2009
Senior Member
Hi Pratik,

thanks for the followup. I just added a System.out.println to print the
bounds and the size of each figure. Looks fine. Another thing I have
observed is that connections are drawn, while the nodes are not. And it
is only a problem with the SWTGraphics/GC. As soon as I use another
graphics object (PDF, SVG, EPS), it works (everything is drawn). Any
other ideas?

Thanks, Thomas.


Pratik Shah wrote:
> I bet all your figures are sized 0,0. They used to have a default size of
> 60x40 or something, and that default size was changed to be 0,0 afterwards.
>
> "Thomas Maier" <Thomas.Maier@uni-kassel.de> wrote in message
> news:45E6E602.1070601@uni-kassel.de...
>
>> Hi all,
>>
>> in my code I used to have a loop that painted a set of figures to an
>> org.eclipse.swt.graphics.Image:
>>
>> Image image = new Image(Display.getDefault(), imageSize.width,
>> imageSize.height);
>> for (IFigure figure: previewedFigures)
>> {
>> GC gc = new GC(image);
>> gc.setAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
>> gc.setTextAntialias(isAntialiasing() ? SWT.ON : SWT.OFF);
>> Graphics graphics = new SWTGraphics(gc);
>> graphics.translate(selectionBounds.getLocation().negate());
>> figure.paint(graphics);
>> graphics.dispose();
>> gc.dispose ();
>> }
>>
>>
>> It worked fine with Eclipse 3.1. With 3.2 it does not work any longer.
>> I get a white image and no figures are drawn. Actually they seem to be
>> drawn because to check I overrode a couple of draw methods and they are
>> really called, even with sane parameters. However, the image is plain
>> white. Strangely, when I add a draw in the loop myself, like e.g.
>>
>> graphics.setForegroundColor(ColorConstants.green);
>> graphics.drawRectangle(3, 4, imageSize.width-6, imageSize.height-8);
>>
>>
>> the rectangle is there. Is there anything I am doing wrong here (which
>> just _happened_ to work in earlier versions)? Should that actually be
>> posted on the SWT list?
>>
>> Thanks and regards, Thomas.
>>
Re: Painting figures with SWTGraphics does not work any longer. [message #231552 is a reply to message #231367] Sat, 10 March 2007 13:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

I seem to remember a bug in SWT where the paint event contained an empty
rectangle instead of the damaged region. Have you tried using different
builds or platforms?

"Thomas Maier" <Thomas.Maier@uni-kassel.de> wrote in message
news:45EE9A8D.9060605@uni-kassel.de...
> Hi Pratik,
>
> thanks for the followup. I just added a System.out.println to print the
> bounds and the size of each figure. Looks fine. Another thing I have
> observed is that connections are drawn, while the nodes are not. And it
> is only a problem with the SWTGraphics/GC. As soon as I use another
> graphics object (PDF, SVG, EPS), it works (everything is drawn). Any
> other ideas?
>
> Thanks, Thomas.
Re: Painting figures with SWTGraphics does not work any longer. [message #231598 is a reply to message #231552] Mon, 12 March 2007 20:29 Go to previous message
Thomas Maier is currently offline Thomas MaierFriend
Messages: 117
Registered: July 2009
Senior Member
Hi Randy, good point, thanks. We tried it on MacOS and it works fine there.

Unfortunately, the bug occurs on my main development platform: Linux
(Ubuntu Edgy), Eclipse Version: 3.2.2 Build id: M20070212-1330. Do you
remember a workaround for the bug?

Fortunately, I ordered a MacBook Pro last week ;).


Randy Hudson wrote:
> I seem to remember a bug in SWT where the paint event contained an empty
> rectangle instead of the damaged region. Have you tried using different
> builds or platforms?
>
> "Thomas Maier" <Thomas.Maier@uni-kassel.de> wrote in message
> news:45EE9A8D.9060605@uni-kassel.de...
>
>> Hi Pratik,
>>
>> thanks for the followup. I just added a System.out.println to print the
>> bounds and the size of each figure. Looks fine. Another thing I have
>> observed is that connections are drawn, while the nodes are not. And it
>> is only a problem with the SWTGraphics/GC. As soon as I use another
>> graphics object (PDF, SVG, EPS), it works (everything is drawn). Any
>> other ideas?
>>
>> Thanks, Thomas.
Previous Topic:REQ_MOVE and overlapping Layers problem
Next Topic:JUnit testing of GEF application
Goto Forum:
  


Current Time: Thu Apr 25 12:27:30 GMT 2024

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

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

Back to the top