Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Really bad hack, someone suggest something better please :)
Really bad hack, someone suggest something better please :) [message #442383] Thu, 02 September 2004 19:39 Go to next message
Andrew Brampton is currently offline Andrew BramptonFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

I was thinking of a control inspired from my Visual Basic days...

In VB I could set a AutoRedraw property to true, and anything I drew on my
form would be remembered... Such that I could draw, cover the form, bring it
back and voila my drawing is still there.



Now I considered having a similar thing in SWT. I wanted to alter something
like so:

GC gc = new GC(Canvas);

gc.drawSomething();

gc.dispose();



and on my canvas my drawing would appear... However cover up the canvas and
bring it back and doh the drawing had gone...



If I wanted custom drawing on my canvas I would normally listen for the
paint events and draw inside them, but I wanted this to be slightly
different.



I first created a new class that extended Canvas and had a private Image
variable which would store the actual drawing. Then anything outside would
draw to this image instead of the Canvas.. This worked, but I didn't like it
because I would have to do canvas.getImage() and draw on that... Instead I
wanted to just draw on the canvas and by some magic it would know and store
the drawing in the image.



I hacked up a pretty bad solution to this by overriding the internal_new_GC
and internal_dispose_GC methods to return image.internal_dispose_GC instead
of canvas.internal_dispose_GC. Now that didn't work to begin with because
when the canvas was drawn it would be drawing the image instead. So I made
it check the stack and see where the internal_dispose_GC was coming from. If
we were inside some SWT code, then return the canvas, otherwise return my
image.



This solution is working, but I wanted to ask if there is a proper nicer
solution? I fully understand this is not how I should be using SWT, and I
did notice the big warning in the SWT docs about internal_dispose_GC, but I
like giving myself challenges and finding solutions :)



If you wish to check my code out look here:

http://me.bramp.net/java/MemoryCanvas.java

http://me.bramp.net/java/PrinterTest.java



Thanks

Andrew
Re: Really bad hack, someone suggest something better please :) [message #442387 is a reply to message #442383] Thu, 02 September 2004 21:51 Go to previous message
Charlie Surface is currently offline Charlie SurfaceFriend
Messages: 40
Registered: July 2009
Member
I would ditch this code based solely on the statement: "So I made it check
the stack and see where the internal_dispose_GC was coming from." I think
you would be better off just using the simple double-buffering solution that
you tried originally. Of course, you could always poke around in the SWT or
JFace source to see if any of the custom widgets have implemented double
buffering.

Charlie


"Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
news:ch7snq$u45$1@eclipse.org...
> Hi,
>
> I was thinking of a control inspired from my Visual Basic days...
>
> In VB I could set a AutoRedraw property to true, and anything I drew on my
> form would be remembered... Such that I could draw, cover the form, bring
it
> back and voila my drawing is still there.
>
>
>
> Now I considered having a similar thing in SWT. I wanted to alter
something
> like so:
>
> GC gc = new GC(Canvas);
>
> gc.drawSomething();
>
> gc.dispose();
>
>
>
> and on my canvas my drawing would appear... However cover up the canvas
and
> bring it back and doh the drawing had gone...
>
>
>
> If I wanted custom drawing on my canvas I would normally listen for the
> paint events and draw inside them, but I wanted this to be slightly
> different.
>
>
>
> I first created a new class that extended Canvas and had a private Image
> variable which would store the actual drawing. Then anything outside would
> draw to this image instead of the Canvas.. This worked, but I didn't like
it
> because I would have to do canvas.getImage() and draw on that... Instead I
> wanted to just draw on the canvas and by some magic it would know and
store
> the drawing in the image.So I made
> it check the stack and see where the internal_dispose_GC was coming from.
>
>
>
> I hacked up a pretty bad solution to this by overriding the
internal_new_GC
> and internal_dispose_GC methods to return image.internal_dispose_GC
instead
> of canvas.internal_dispose_GC. Now that didn't work to begin with because
> when the canvas was drawn it would be drawing the image instead. If
> we were inside some SWT code, then return the canvas, otherwise return my
> image.
>
>
>
> This solution is working, but I wanted to ask if there is a proper nicer
> solution? I fully understand this is not how I should be using SWT, and I
> did notice the big warning in the SWT docs about internal_dispose_GC, but
I
> like giving myself challenges and finding solutions :)
>
>
>
> If you wish to check my code out look here:
>
> http://me.bramp.net/java/MemoryCanvas.java
>
> http://me.bramp.net/java/PrinterTest.java
>
>
>
> Thanks
>
> Andrew
>
>
>
>
Previous Topic:MenuManager prevents ApplicationWindow from closing properly
Next Topic:Problem with resetting the StyleRange background
Goto Forum:
  


Current Time: Fri Apr 26 14:39:35 GMT 2024

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

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

Back to the top