Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » SWTGraphics no longer draws on SWT Canvas in 3.1
SWTGraphics no longer draws on SWT Canvas in 3.1 [message #204815] Wed, 07 December 2005 20:52 Go to next message
Eclipse UserFriend
Originally posted by: kblanchard85.hotmail.com

I have a Viewpart in Eclipse that is just an SWT Canvas used for
drawing. When the user clicks the mouse on the Canvas, a line is drawn
at the current mouse coordinate with the current color. The code has NOT
been changed in nearly 2 months and will NOT work on 3.1 or 3.1.1 of
GEF. It works fine under 3.0.1 (with the latest version of Eclipse).
Here's the code:

public class CanvasView extends ViewPart

public void createPartControl(Composite parent) {
//create canvas
canvas = new Canvas(parent, SWT.BORDER | SWT.NO_REDRAW_RESIZE);

//set background color
canvas.setBackground(ColorConstants.white);

//create gc and graphics for canvas painting
gc = new GC(canvas);
graphics = new SWTGraphics(gc);

//set colors
graphics.setForegroundColor(ColorConstants.black);
}

public void attachListeners() {
//add mouse listener
canvas.addMouseListener(new MouseListener() {

public void mouseDoubleClick(MouseEvent e) { }

public void mouseDown(MouseEvent e) {

if (e.button == 1)
graphics.drawLine(e.x, e.y, e.x, e.y);
}
}
}

After drawing the line, I call graphics.dispose(), but in 3.0.1, it
works regardless. I don't understand why this would stop working with
3.1. Is there anything I should be aware of here? Any help is
appreciated...thanks!
Re: SWTGraphics no longer draws on SWT Canvas in 3.1 [message #204824 is a reply to message #204815] Thu, 08 December 2005 03:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

What you are doing is incorrect on any version of SWT. You are creating a GC
and painting on it. But that painting is not permanent. It can be erased at
any time by the default paint event, which your code is not handling.

It looks like you are drawing points and not lines. It would help if you had
a standalone draw2d application showing the problem.

"Kyle Blanchard" <kblanchard85@hotmail.com> wrote in message
news:dn7i3f$fo7$1@news.eclipse.org...
>I have a Viewpart in Eclipse that is just an SWT Canvas used for drawing.
>When the user clicks the mouse on the Canvas, a line is drawn at the
>current mouse coordinate with the current color. The code has NOT been
>changed in nearly 2 months and will NOT work on 3.1 or 3.1.1 of GEF. It
>works fine under 3.0.1 (with the latest version of Eclipse). Here's the
>code:
>
> public class CanvasView extends ViewPart
>
> public void createPartControl(Composite parent) {
> //create canvas
> canvas = new Canvas(parent, SWT.BORDER | SWT.NO_REDRAW_RESIZE);
>
> //set background color
> canvas.setBackground(ColorConstants.white);
>
> //create gc and graphics for canvas painting
> gc = new GC(canvas);
> graphics = new SWTGraphics(gc);
>
> //set colors
> graphics.setForegroundColor(ColorConstants.black);
> }
>
> public void attachListeners() {
> //add mouse listener
> canvas.addMouseListener(new MouseListener() {
>
> public void mouseDoubleClick(MouseEvent e) { }
>
> public void mouseDown(MouseEvent e) {
>
> if (e.button == 1)
> graphics.drawLine(e.x, e.y, e.x, e.y);
> }
> }
> }
>
> After drawing the line, I call graphics.dispose(), but in 3.0.1, it works
> regardless. I don't understand why this would stop working with 3.1. Is
> there anything I should be aware of here? Any help is
> appreciated...thanks!
Re: SWTGraphics no longer draws on SWT Canvas in 3.1 [message #204922 is a reply to message #204824] Thu, 08 December 2005 16:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kblanchard85.hotmail.com

Randy Hudson wrote:
> What you are doing is incorrect on any version of SWT. You are creating a GC
> and painting on it. But that painting is not permanent. It can be erased at
> any time by the default paint event, which your code is not handling.
>
> It looks like you are drawing points and not lines. It would help if you had
> a standalone draw2d application showing the problem.

I am drawing lines when the user drags the mouse--it connects the
previous point to the current event location. I simply chose not to put
that code in because it is irrelevent.

I am also handling the default paint event. Everytime a change is made
to the canvas/draw event occurs, an image of the canvas is saved. When
the paint event is called, the gc just draws the image back on the
canvas. So even if a resize of the canvas occurrs, all previous drawings
will remain.

Like I have stated, my code worked fine under GEF/Draw2D 3.0.1. I am
confused why a change in versions would cause it to cease functioning
correctly.

>
> "Kyle Blanchard" <kblanchard85@hotmail.com> wrote in message
> news:dn7i3f$fo7$1@news.eclipse.org...
>
>>I have a Viewpart in Eclipse that is just an SWT Canvas used for drawing.
>>When the user clicks the mouse on the Canvas, a line is drawn at the
>>current mouse coordinate with the current color. The code has NOT been
>>changed in nearly 2 months and will NOT work on 3.1 or 3.1.1 of GEF. It
>>works fine under 3.0.1 (with the latest version of Eclipse). Here's the
>>code:
>>
>>public class CanvasView extends ViewPart
>>
>>public void createPartControl(Composite parent) {
>>//create canvas
>>canvas = new Canvas(parent, SWT.BORDER | SWT.NO_REDRAW_RESIZE);
>>
>>//set background color
>>canvas.setBackground(ColorConstants.white);
>>
>>//create gc and graphics for canvas painting
>>gc = new GC(canvas);
>>graphics = new SWTGraphics(gc);
>>
>>//set colors
>>graphics.setForegroundColor(ColorConstants.black);
>>}
>>
>>public void attachListeners() {
>>//add mouse listener
>>canvas.addMouseListener(new MouseListener() {
>>
>>public void mouseDoubleClick(MouseEvent e) { }
>>
>>public void mouseDown(MouseEvent e) {
>>
>>if (e.button == 1)
>>graphics.drawLine(e.x, e.y, e.x, e.y);
>>}
>>}
>>}
>>
>>After drawing the line, I call graphics.dispose(), but in 3.0.1, it works
>>regardless. I don't understand why this would stop working with 3.1. Is
>>there anything I should be aware of here? Any help is
>>appreciated...thanks!
>
>
>
Re: SWTGraphics no longer draws on SWT Canvas in 3.1 [message #204937 is a reply to message #204922] Thu, 08 December 2005 17:25 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

I can not think of anything that would affect the scenario you have
described. You should start removing things until the problem is really
small (then post it) or goes away.

"Kyle Blanchard" <kblanchard85@hotmail.com> wrote in message
news:dn9lri$8v0$1@news.eclipse.org...
> Randy Hudson wrote:
>> What you are doing is incorrect on any version of SWT. You are creating a
>> GC and painting on it. But that painting is not permanent. It can be
>> erased at any time by the default paint event, which your code is not
>> handling.
>>
>> It looks like you are drawing points and not lines. It would help if you
>> had a standalone draw2d application showing the problem.
>
> I am drawing lines when the user drags the mouse--it connects the previous
> point to the current event location. I simply chose not to put that code
> in because it is irrelevent.
>
> I am also handling the default paint event. Everytime a change is made to
> the canvas/draw event occurs, an image of the canvas is saved. When the
> paint event is called, the gc just draws the image back on the canvas. So
> even if a resize of the canvas occurrs, all previous drawings will remain.
>
> Like I have stated, my code worked fine under GEF/Draw2D 3.0.1. I am
> confused why a change in versions would cause it to cease functioning
> correctly.
>
>>
>> "Kyle Blanchard" <kblanchard85@hotmail.com> wrote in message
>> news:dn7i3f$fo7$1@news.eclipse.org...
>>
>>>I have a Viewpart in Eclipse that is just an SWT Canvas used for drawing.
>>>When the user clicks the mouse on the Canvas, a line is drawn at the
>>>current mouse coordinate with the current color. The code has NOT been
>>>changed in nearly 2 months and will NOT work on 3.1 or 3.1.1 of GEF. It
>>>works fine under 3.0.1 (with the latest version of Eclipse). Here's the
>>>code:
>>>
>>>public class CanvasView extends ViewPart
>>>
>>>public void createPartControl(Composite parent) {
>>>//create canvas
>>>canvas = new Canvas(parent, SWT.BORDER | SWT.NO_REDRAW_RESIZE);
>>>
>>>//set background color
>>>canvas.setBackground(ColorConstants.white);
>>>
>>>//create gc and graphics for canvas painting
>>>gc = new GC(canvas);
>>>graphics = new SWTGraphics(gc);
>>>
>>>//set colors
>>>graphics.setForegroundColor(ColorConstants.black);
>>>}
>>>
>>>public void attachListeners() {
>>>//add mouse listener
>>>canvas.addMouseListener(new MouseListener() {
>>>
>>>public void mouseDoubleClick(MouseEvent e) { }
>>>
>>>public void mouseDown(MouseEvent e) {
>>>
>>>if (e.button == 1)
>>>graphics.drawLine(e.x, e.y, e.x, e.y);
>>>}
>>>}
>>>}
>>>
>>>After drawing the line, I call graphics.dispose(), but in 3.0.1, it works
>>>regardless. I don't understand why this would stop working with 3.1. Is
>>>there anything I should be aware of here? Any help is
>>>appreciated...thanks!
>>
>>
Previous Topic:Unexpected entries in the tool bar
Next Topic:back to default 'Select' tool after creating a connection
Goto Forum:
  


Current Time: Thu Apr 25 22:28:25 GMT 2024

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

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

Back to the top