[Blindmath] Converting java.awt.Graphics2D graphics to an SWT Display format

Richard Baldwin baldwin at dickbaldwin.com
Sat Dec 31 16:47:42 UTC 2011


Thousands of programs and several complete libraries have been published
that use Sun's java.awt.Graphics2D class for the creation of graphic
information. I am personally responsible for publishing a few hundred of
those programs myself.

For reasons of accessibility, I am now programming using the SWT. I am
searching for a relatively painless way to convert programs that have been
developed using Sun's java.awt.Graphics2D class to a display format that
can be used with SWT.

ALTERNATIVE #1
On the Sun Java side, I can create an off-screen image of type
java.awt.Image and use any of the methods of the class named
java.awt.Graphics2D to draw or otherwise deposit pictures onto the Image
object. Normally then, I would call the drawImage method of the Graphics2D
class in an overridden paint method to draw that image onto a
java.awt.Canvas object for display in a java.awt.Frame or
javax.swing.JFrame object.

On the SWT Java side, apparently if I have an
org.eclipse.swt.graphics.Image object, I can call the drawImage method of
the GC class to display that image in a manner that is acceptable to SWT
with no requirement for a java.awt.Frame object or a javax.swing.JFrame
object.

Question: How can I transfer the image from a java.awt.Image object to an
org.eclipse.swt.graphics.Image object? A single method that receives
references to one object of each type and makes the transfer would be very
useful.

OTHER ALTERNATIVES
Question: Other than using code such as the following, does anyone know of
a relatively painless way to convert programs that have been developed
using Sun's Graphics2D class to a display format that can be used with SWT.

    Composite comp =  new Composite(drawingShell,SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(comp);

In other words, how can I take advantage of Sun's Graphics2D API without
including a java.awt.Frame object in my SWT program?

Thanks,
Dick Baldwin

-- 
Richard G. Baldwin (Dick Baldwin)
Home of Baldwin's on-line Java Tutorials
http://www.DickBaldwin.com

Professor of Computer Information Technology
Austin Community College
(512) 223-4758
mailto:Baldwin at DickBaldwin.com
http://www.austincc.edu/baldwin/



More information about the BlindMath mailing list