Class GraphicsGC


  • public class GraphicsGC
    extends java.lang.Object
    Class to transpose a Graphics2D onto an SWT Graphics Context (GC). This class is not thread safe. The class retains the buffered images for AWT and SWT if possible so they can be reused. The class must be disposed of by calling dispose.
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static org.eclipse.swt.graphics.PaletteDataPALETTE_DATA 
    • Constructor Summary

      Constructors 
      ConstructorDescription
      GraphicsGC()
      Constructs the Graphics to GC transfer for images without transparency.
      GraphicsGC​(int color)
      Constructs the Graphics to GC transfer for images with specified transparency color.
      GraphicsGC​(int width, int height)
      Constructs the Graphics to GC transfer for use with getImage().
      GraphicsGC​(int width, int height, int color)
      Constructs the Graphics to GC transfer for use with getImage().
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voiddispose()
      Dispose the resources for this instance.
      java.awt.Graphics2DgetGraphics()
      Returns the Graphics2D context to use.
      org.eclipse.swt.graphics.ImagegetImage()
      Gets an SWT Image for what is drawn.
      voidinitialize​(int x, int y, int cx, int cy)
      Initialize the AWT off-screen image for the drawing of the rectangle.
      voidinitialize​(org.eclipse.swt.graphics.GC gc)
      Initialize drawing on a SWT graphics context.
      voidinitialize​(org.eclipse.swt.graphics.Rectangle r)
      Initialize the AWT off-screen image for the drawing of the rectangle.
      voidtransfer​(org.eclipse.swt.graphics.GC gc)
      Transfer the Graphics2D data onto the SWT Graphics Context.
      voidtransfer​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect)
      Transfer the Graphics2D data onto the SWT Graphics Context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PALETTE_DATA

        public static final org.eclipse.swt.graphics.PaletteData PALETTE_DATA
    • Constructor Detail

      • GraphicsGC

        public GraphicsGC()
        Constructs the Graphics to GC transfer for images without transparency.
      • GraphicsGC

        public GraphicsGC​(int color)
        Constructs the Graphics to GC transfer for images with specified transparency color.
        Parameters:
        color - RGB value to use as transparent color for SWT, -1 for none.
      • GraphicsGC

        public GraphicsGC​(int width,
                          int height)
        Constructs the Graphics to GC transfer for use with getImage().
        Parameters:
        width - The width of the image.
        height - The height of the image.
      • GraphicsGC

        public GraphicsGC​(int width,
                          int height,
                          int color)
        Constructs the Graphics to GC transfer for use with getImage().
        Parameters:
        width - The width of the image.
        height - The height of the image.
        color - RGB value to use as transparent color for SWT, -1 for none.
    • Method Detail

      • initialize

        public void initialize​(org.eclipse.swt.graphics.GC gc)
        Initialize drawing on a SWT graphics context.
      • initialize

        public void initialize​(org.eclipse.swt.graphics.Rectangle r)
        Initialize the AWT off-screen image for the drawing of the rectangle.
      • initialize

        public void initialize​(int x,
                               int y,
                               int cx,
                               int cy)
        Initialize the AWT off-screen image for the drawing of the rectangle.
      • getGraphics

        public java.awt.Graphics2D getGraphics()
        Returns the Graphics2D context to use.
      • transfer

        public void transfer​(org.eclipse.swt.graphics.GC gc)
        Transfer the Graphics2D data onto the SWT Graphics Context.
      • transfer

        public void transfer​(org.eclipse.swt.graphics.GC gc,
                             org.eclipse.swt.graphics.Rectangle rect)
        Transfer the Graphics2D data onto the SWT Graphics Context.
      • getImage

        public org.eclipse.swt.graphics.Image getImage()
        Gets an SWT Image for what is drawn. Note that the image must be disposed of. This call can only be done once, and once called, this instance is disposed of.
        Returns:
        The SWT Image, or null if called a second time.
      • dispose

        public void dispose()
        Dispose the resources for this instance.