Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT equivalent of AWT's getGraphics()?
SWT equivalent of AWT's getGraphics()? [message #375357] Sun, 12 October 2003 09:50 Go to next message
Eclipse UserFriend
Hello all,
I am currently converting a routine written in AWT to SWT.

Here is the AWT snippet... (m_buffer is an Image)

public void paint(Graphics graphics)
{
Graphics myGraphics = m_buffer.getGraphics();
super.paint(myGraphics);
doWork(myGraphics);
graphics.drawImage(m_buffer, 0, 0, null);
}

I want to do the same thing in SWT (using draw2D)...

But, how do I get a "org.eclise.draw2d.Graphics" object from an
"org.eclipse.swt.graphics.Image" object?
I am not sure how to translate the "m_buffer.getGraphics()" portion...

Is there an SWT equivalent of AWT's getGraphics()?

Thx.
-M
Re: SWT equivalent of AWT's getGraphics()? [message #375359 is a reply to message #375357] Sun, 12 October 2003 10:53 Go to previous messageGo to next message
Eclipse UserFriend
Murali wrote:

> I want to do the same thing in SWT (using draw2D)...
>
> But, how do I get a "org.eclise.draw2d.Graphics" object from an
> "org.eclipse.swt.graphics.Image" object?
> I am not sure how to translate the "m_buffer.getGraphics()" portion...
>
> Is there an SWT equivalent of AWT's getGraphics()?

Use "new GC(m_buffer);" Don't forget to dispose the GC after you used
it. Your Swing code also lacks a call to "myGraphics.dispose()" - also
in AWT, you have to (should) dispose Graphics resources you create like
you need to dispose windows you create. There's probably a way to get a
draw2d Graphics object for an SWT GC object.


bye
--
Stefan Matthias Aust // "Ist es normal, nur weil alle es tun?" -F4
Re: SWT equivalent of AWT's getGraphics()? [message #375362 is a reply to message #375359] Sun, 12 October 2003 14:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Stefan,
Thank you for the tips!.
Yes, the new GC() works! ... and I dispose the objects correctly now...

I still am in the dark about getting a draw2d Graphics object for an SWT
GC object. I am going thro the draw2D examples to try to find out..
Thx.
- M


On Sun, 12 Oct 2003 16:53:28 +0200, Stefan Matthias Aust wrote:

> Subject: Re: SWT equivalent of AWT's getGraphics()?
> From: Stefan Matthias Aust <sma@3plus4.de>
> Newsgroups: eclipse.platform.swt
> Date: Sun, 12 Oct 2003 16:53:28 +0200
>
> Murali wrote:
>
>> I want to do the same thing in SWT (using draw2D)...
>>
>> But, how do I get a "org.eclise.draw2d.Graphics" object from an
>> "org.eclipse.swt.graphics.Image" object?
>> I am not sure how to translate the "m_buffer.getGraphics()" portion...
>>
>> Is there an SWT equivalent of AWT's getGraphics()?
>
> Use "new GC(m_buffer);" Don't forget to dispose the GC after you used
> it. Your Swing code also lacks a call to "myGraphics.dispose()" - also
> in AWT, you have to (should) dispose Graphics resources you create like
> you need to dispose windows you create. There's probably a way to get a
> draw2d Graphics object for an SWT GC object.
>
>
> bye
> --
> Stefan Matthias Aust // "Ist es normal, nur weil alle es tun?" -F4
Re: SWT equivalent of AWT's getGraphics()? [message #375363 is a reply to message #375362] Sun, 12 October 2003 15:41 Go to previous messageGo to next message
Eclipse UserFriend
Murali wrote:

> I still am in the dark about getting a draw2d Graphics object for an SWT
> GC object.

I assume you have a draw2d project in your workspace.

Type Ctrl+Shift+T (or pick Navigate|Open Type... from the menu) and
"Gra*" and choose org.eclipse.draw2d.Graphics from the list. An editor
with the Graphics.java source will open. Oops, it's an abstract class,
we need to find the leafs of the inheritance tree. So press F4 on the
word Graphics. In the Hierachy Viewer to the left, some more classes
are displayed, "SWTGraphics" looks promissing. Double click it. Another
editor for SWTGraphics.java opens. In the Outline viewer to the right,
look for public constructors, that is entries marked with a green dot
and a tiny C attached. There's only one:

public SWTGraphics(GC gc) ...

Might work... let's verify whether this method is used somewhere in the
Draw2D/GEF code that looks similiar to what you want to achieve. Type
Ctrl+Shift+G (or pick Search|References|Workspace from the menu)... I
get three hits, the one in "org.eclipse.draw2d.BufferedGraphicsSource -
getGraphics(Rectangle)" seems to be the best.

Oh, see, it's the code you're looking for...


bye
--
Stefan Matthias Aust // "Ist es normal, nur weil alle es tun?" -F4
Re: SWT equivalent of AWT's getGraphics()? [message #375386 is a reply to message #375363] Mon, 13 October 2003 13:50 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NO--SPAM.us.ibm.com

Also, since draw2d is in GEF, you would get a better response of draw2d
from the gef newsgroup, eclipse.tools.gef.

Rich
Previous Topic:SWT ComboList Question
Next Topic:Plugin to a program
Goto Forum:
  


Current Time: Tue Oct 28 09:58:40 EDT 2025

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

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

Back to the top