net.refractions.udig.ui.graphics
Class AWTSWTImageUtils

java.lang.Object
  extended by net.refractions.udig.ui.graphics.AWTSWTImageUtils

public final class AWTSWTImageUtils
extends java.lang.Object

Provides a bunch of Utility methods for converting between AWT and SWT

Since:
1.1.0
Author:
jesse

Constructor Summary
AWTSWTImageUtils()
           
 
Method Summary
static org.eclipse.swt.graphics.Font awtFontToSwt(java.awt.Font font, FontRegistry fontRegistry)
          Converts an AWTFont to a SWT Font
static ImageDescriptor awtIcon2ImageDescriptor(javax.swing.Icon icon)
          Converts a Swing Icon to an ImageDescriptor
static java.awt.image.BufferedImage convertToAWT(Image image)
          Convert an SWT Image to a BufferedImage - this one rips the ImageData out of the live Image; and then copies it into a BufferedImage.
static Path convertToPath(java.awt.Shape shape, Device device)
          Converts the shape to a path object.
static Image convertToSWTImage(java.awt.image.BufferedImage image)
          Converts a BufferedImage to an SWT Image.
static java.awt.image.BufferedImage createBufferedImage(int w, int h)
          Create a buffered image that can be be converted to SWTland later
static Image createDefaultImage(Device device, int width, int height)
          Creates an image with a depth of 24 and has a transparency channel.
static ImageData createImageData(java.awt.image.BufferedImage image)
          Creates an ImageData from the 0,0,width,height section of the source BufferedImage.
static ImageData createImageData(java.awt.image.RenderedImage image)
          Creates an ImageData from the source RenderedImage.
static ImageData createImageData(java.awt.image.RenderedImage image, boolean transparent)
           
static ImageDescriptor createImageDescriptor(java.awt.image.BufferedImage image)
          Creates an image descriptor that from the source image.
static ImageDescriptor createImageDescriptor(java.awt.image.RenderedImage image, boolean transparent)
           
static Path createPath(java.awt.geom.PathIterator p, Device device)
           
static Image createSWTImage(java.awt.image.RenderedImage image)
          Converts a RenderedImage to an SWT Image.
static Image createSWTImage(java.awt.image.RenderedImage image, boolean transparent)
           
static javax.swing.Icon imageDescriptor2awtIcon(ImageDescriptor imageDescriptor)
           
static java.awt.Color swtColor2awtColor(GC gc, Color swt)
           
static java.awt.Font swtFontToAwt(FontData fontData)
          Converts SWT FontData to a AWT Font
static int toFontStyle(java.awt.Font f)
          Takes an AWT Font.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AWTSWTImageUtils

public AWTSWTImageUtils()
Method Detail

convertToAWT

public static java.awt.image.BufferedImage convertToAWT(Image image)
Convert an SWT Image to a BufferedImage - this one rips the ImageData out of the live Image; and then copies it into a BufferedImage.


convertToPath

public static Path convertToPath(java.awt.Shape shape,
                                 Device device)
Converts the shape to a path object. Remember to dispose of the path object when done.

Parameters:
shape -
Returns:
the shape converted to a Path object.

createPath

public static Path createPath(java.awt.geom.PathIterator p,
                              Device device)

createDefaultImage

public static Image createDefaultImage(Device device,
                                       int width,
                                       int height)
Creates an image with a depth of 24 and has a transparency channel.

Parameters:
device - device to use for creating the image
width - the width of the final image
height - the height of the final image
Returns:
an image with a depth of 24 and has a transparency channel.

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(int w,
                                                               int h)
Create a buffered image that can be be converted to SWTland later


createSWTImage

public static Image createSWTImage(java.awt.image.RenderedImage image,
                                   boolean transparent)

createImageData

public static ImageData createImageData(java.awt.image.RenderedImage image,
                                        boolean transparent)

createImageDescriptor

public static ImageDescriptor createImageDescriptor(java.awt.image.RenderedImage image,
                                                    boolean transparent)

createImageDescriptor

public static ImageDescriptor createImageDescriptor(java.awt.image.BufferedImage image)
Creates an image descriptor that from the source image.

Parameters:
image - source image
Returns:
an image descriptor that from the source image.

convertToSWTImage

public static Image convertToSWTImage(java.awt.image.BufferedImage image)
Converts a BufferedImage to an SWT Image. You are responsible for disposing the created image. This method is faster than creating a SWT image from a RenderedImage so use this method if possible.

Parameters:
image - source image.
Returns:
a swtimage showing the source image.

createImageData

public static ImageData createImageData(java.awt.image.BufferedImage image)
Creates an ImageData from the 0,0,width,height section of the source BufferedImage.

This method is faster than creating the ImageData from a RenderedImage so use this method if possible.

Parameters:
image - source image.
Returns:
an ImageData from the 0,0,width,height section of the source BufferedImage

createSWTImage

public static Image createSWTImage(java.awt.image.RenderedImage image)
Converts a RenderedImage to an SWT Image. You are responsible for disposing the created image. This method is slower than calling SWTGraphics#createSWTImage(BufferedImage, int, int).

Parameters:
image - source image.
width - the width of the final image
height - the height of the final image
Returns:
a swtimage showing the 0,0,width,height rectangle of the source image.

createImageData

public static ImageData createImageData(java.awt.image.RenderedImage image)
Creates an ImageData from the source RenderedImage.

This method is slower than using createImageData.

Parameters:
image - source image.
Returns:
an ImageData from the source RenderedImage.

swtColor2awtColor

public static java.awt.Color swtColor2awtColor(GC gc,
                                               Color swt)

swtFontToAwt

public static java.awt.Font swtFontToAwt(FontData fontData)
Converts SWT FontData to a AWT Font

Parameters:
fontData - the font data
Returns:
the equivalent AWT font

awtFontToSwt

public static org.eclipse.swt.graphics.Font awtFontToSwt(java.awt.Font font,
                                                         FontRegistry fontRegistry)
Converts an AWTFont to a SWT Font

Parameters:
font - and AWT Font
fontRegistry -
Returns:
the equivalent SWT Font

toFontStyle

public static int toFontStyle(java.awt.Font f)
Takes an AWT Font.

Parameters:
style -
Returns:

imageDescriptor2awtIcon

public static javax.swing.Icon imageDescriptor2awtIcon(ImageDescriptor imageDescriptor)

awtIcon2ImageDescriptor

public static ImageDescriptor awtIcon2ImageDescriptor(javax.swing.Icon icon)
Converts a Swing Icon to an ImageDescriptor

Parameters:
icon - icon to convert
Returns:
an ImageDescriptor