edu.umd.cs.piccolox.swt
Class SWTGraphics2D

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by edu.umd.cs.piccolox.swt.SWTGraphics2D

public class SWTGraphics2D
extends Graphics2D

An extension to Graphics2D to support an SWT Piccolo Canvas with little modification to the current Piccolo architecture There is an outstanding SWT bug request #33319 for more efficient polyline/polygon rendering methods. It also appears that most of the code below could be made obselete by bug fix #6490 A lot of this may also be duplicated in GEF - the eclipse Graphical Editor Framework

Author:
Lance Good

Field Summary
protected static BufferedImage BUFFER
           
protected static int CACHE_COUNT
           
protected static HashMap COLOR_CACHE
           
protected  org.eclipse.swt.graphics.Font curFont
           
protected  org.eclipse.swt.graphics.Device device
           
protected static HashMap FONT_CACHE
           
protected  org.eclipse.swt.graphics.GC gc
           
(package private) static Rectangle2D LINE_RECT
           
protected  double lineWidth
           
(package private) static Point PT
           
(package private) static Rectangle2D RECT
           
protected static HashMap SHAPE_CACHE
           
(package private) static org.eclipse.swt.graphics.Rectangle SWT_RECT
           
protected  AffineTransform transform
           
 
Constructor Summary
SWTGraphics2D(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Device device)
          Constructor for SWTGraphics2D.
 
Method Summary
 void addRenderingHints(Map hints)
           
 void clearRect(int x, int y, int width, int height)
           
 void clip(Shape s)
          This method isn't really supported by SWT - so will use the shape bounds
 void clipRect(int x, int y, int width, int height)
           
 void copyArea(org.eclipse.swt.graphics.Image img, double x, double y)
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 Graphics create()
           
static void decrementGCCount()
           
 void dispose()
          DO NOTHING - DISPOSED IN RENDERING CLASS
 void draw(Shape s)
           
 void drawArc(double x, double y, double width, double height, double startAngle, double extent)
           
 void drawArc(int x, int y, int width, int height, int startAngle, int extent)
           
 void drawGlyphVector(GlyphVector g, float x, float y)
           
 void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
           
 boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
           
 void drawImage(org.eclipse.swt.graphics.Image image, double x, double y)
           
 boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, ImageObserver observer)
           
 boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
           
 void drawImage(org.eclipse.swt.graphics.Image image, int srcX, int srcY, int srcW, int srcH, double destX, double destY, double destW, double destH)
           
 boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
           
 boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
           
 void drawLine(double x1, double y1, double x2, double y2)
           
 void drawLine(int x1, int y1, int x2, int y2)
           
 void drawOval(double x, double y, double width, double height)
           
 void drawOval(int x, int y, int width, int height)
           
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawPolyline(double[] pts)
           
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawRect(double x, double y, double width, double height)
           
 void drawRect(int x, int y, int width, int height)
           
 void drawRenderableImage(RenderableImage img, AffineTransform xform)
           
 void drawRenderedImage(RenderedImage img, AffineTransform xform)
           
 void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
           
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(AttributedCharacterIterator iterator, float x, float y)
           
 void drawString(AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(String str, double x, double y)
           
 void drawString(String str, float x, float y)
           
 void drawString(String str, int x, int y)
           
 void drawText(String s, double x, double y)
           
 void drawText(String s, double x, double y, int flags)
           
 void fill(Shape s)
           
 void fillArc(double x, double y, double width, double height, double startAngle, double extent)
           
 void fillArc(int x, int y, int width, int height, int startAngle, int extent)
           
 void fillGradientRectangle(double x, double y, double width, double height, boolean vertical)
           
 void fillOval(double x, double y, double width, double height)
           
 void fillOval(int x, int y, int width, int height)
           
 void fillPolygon(double[] pts)
           
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void fillRect(double x, double y, double width, double height)
           
 void fillRect(int x, int y, int width, int height)
           
 void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
           
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 int getAdvanceWidth(char ch)
           
 Color getBackground()
           
 int getCharWidth(char ch)
           
 Shape getClip()
           
 Rectangle getClipBounds()
           
 Color getColor()
           
 Composite getComposite()
           
 GraphicsConfiguration getDeviceConfiguration()
           
 Font getFont()
           
 org.eclipse.swt.graphics.Font getFont(String fontString)
           
 FontMetrics getFontMetrics(Font f)
           
 FontRenderContext getFontRenderContext()
           
 Paint getPaint()
           
 Object getRenderingHint(RenderingHints.Key hintKey)
           
 RenderingHints getRenderingHints()
           
 Stroke getStroke()
           
 org.eclipse.swt.graphics.Font getSWTFont()
           
 org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics()
           
 AffineTransform getTransform()
           
protected  org.eclipse.swt.graphics.Font getTransformedFont()
           
protected  int getTransformedLineWidth()
           
 boolean hit(Rectangle rect, Shape s, boolean onStroke)
           
static void incrementGCCount()
           
 void rotate(double theta)
           
 void rotate(double theta, double x, double y)
           
 void scale(double sx, double sy)
           
 void setBackground(Color c)
           
 void setBackground(org.eclipse.swt.graphics.Color c)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(Shape clip)
          This method isn't really supported by SWT - so will use the shape bounds
 void setColor(Color c)
           
 void setColor(org.eclipse.swt.graphics.Color c)
           
 void setComposite(Composite comp)
           
 void setFont(Font font)
           
 void setFont(org.eclipse.swt.graphics.Font font)
           
 void setLineWidth(double lineWidth)
           
 void setPaint(Paint paint)
           
 void setPaintMode()
           
 void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
           
 void setRenderingHints(Map hints)
           
 void setStroke(Stroke s)
           
 void setTransform(AffineTransform Tx)
           
 void setXORMode(boolean xOr)
           
 void setXORMode(Color c1)
           
 void shear(double shx, double shy)
           
 org.eclipse.swt.graphics.Point stringExtent(String str)
           
 org.eclipse.swt.graphics.Point textExtent(String str)
           
 org.eclipse.swt.graphics.Point textExtent(String str, int flags)
           
 void transform(AffineTransform Tx)
           
 void translate(double tx, double ty)
           
 void translate(int x, int y)
           
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CACHE_COUNT

protected static int CACHE_COUNT

FONT_CACHE

protected static HashMap FONT_CACHE

COLOR_CACHE

protected static HashMap COLOR_CACHE

SHAPE_CACHE

protected static HashMap SHAPE_CACHE

BUFFER

protected static BufferedImage BUFFER

PT

static Point PT

RECT

static Rectangle2D RECT

LINE_RECT

static Rectangle2D LINE_RECT

SWT_RECT

static org.eclipse.swt.graphics.Rectangle SWT_RECT

gc

protected org.eclipse.swt.graphics.GC gc

device

protected org.eclipse.swt.graphics.Device device

transform

protected AffineTransform transform

curFont

protected org.eclipse.swt.graphics.Font curFont

lineWidth

protected double lineWidth
Constructor Detail

SWTGraphics2D

public SWTGraphics2D(org.eclipse.swt.graphics.GC gc,
                     org.eclipse.swt.graphics.Device device)
Constructor for SWTGraphics2D.

Method Detail

getClipBounds

public Rectangle getClipBounds()
Specified by:
getClipBounds in class Graphics
See Also:
Graphics.getClipBounds()

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
clipRect in class Graphics

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Specified by:
setClip in class Graphics

clip

public void clip(Shape s)
This method isn't really supported by SWT - so will use the shape bounds

Specified by:
clip in class Graphics2D

setClip

public void setClip(Shape clip)
This method isn't really supported by SWT - so will use the shape bounds

Specified by:
setClip in class Graphics

getClip

public Shape getClip()
Specified by:
getClip in class Graphics

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Specified by:
getDeviceConfiguration in class Graphics2D

getPaint

public Paint getPaint()
Specified by:
getPaint in class Graphics2D

setPaint

public void setPaint(Paint paint)
Specified by:
setPaint in class Graphics2D

getColor

public Color getColor()
Specified by:
getColor in class Graphics

setColor

public void setColor(Color c)
Specified by:
setColor in class Graphics

setColor

public void setColor(org.eclipse.swt.graphics.Color c)

setBackground

public void setBackground(Color c)
Specified by:
setBackground in class Graphics2D

setBackground

public void setBackground(org.eclipse.swt.graphics.Color c)

getBackground

public Color getBackground()
Specified by:
getBackground in class Graphics2D

getSWTFont

public org.eclipse.swt.graphics.Font getSWTFont()

getSWTFontMetrics

public org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics()

getFont

public Font getFont()
Specified by:
getFont in class Graphics

setFont

public void setFont(Font font)
Specified by:
setFont in class Graphics

setFont

public void setFont(org.eclipse.swt.graphics.Font font)

getFont

public org.eclipse.swt.graphics.Font getFont(String fontString)

getTransformedFont

protected org.eclipse.swt.graphics.Font getTransformedFont()

translate

public void translate(int x,
                      int y)
Specified by:
translate in class Graphics2D

translate

public void translate(double tx,
                      double ty)
Specified by:
translate in class Graphics2D

rotate

public void rotate(double theta)
Specified by:
rotate in class Graphics2D

rotate

public void rotate(double theta,
                   double x,
                   double y)
Specified by:
rotate in class Graphics2D

scale

public void scale(double sx,
                  double sy)
Specified by:
scale in class Graphics2D

shear

public void shear(double shx,
                  double shy)
Specified by:
shear in class Graphics2D

transform

public void transform(AffineTransform Tx)
Specified by:
transform in class Graphics2D

setTransform

public void setTransform(AffineTransform Tx)
Specified by:
setTransform in class Graphics2D

getTransform

public AffineTransform getTransform()
Specified by:
getTransform in class Graphics2D

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Specified by:
clearRect in class Graphics

draw

public void draw(Shape s)
Specified by:
draw in class Graphics2D

fill

public void fill(Shape s)
Specified by:
fill in class Graphics2D

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)
Specified by:
drawPolyline in class Graphics

drawPolyline

public void drawPolyline(double[] pts)

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Specified by:
drawPolygon in class Graphics

fillPolygon

public void fillPolygon(double[] pts)

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Specified by:
fillPolygon in class Graphics

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Specified by:
drawLine in class Graphics

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)

copyArea

public void copyArea(org.eclipse.swt.graphics.Image img,
                     double x,
                     double y)

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Specified by:
copyArea in class Graphics

drawString

public void drawString(String str,
                       double x,
                       double y)

drawString

public void drawString(String str,
                       int x,
                       int y)
Specified by:
drawString in class Graphics2D

drawString

public void drawString(String str,
                       float x,
                       float y)
Specified by:
drawString in class Graphics2D

drawText

public void drawText(String s,
                     double x,
                     double y)

drawText

public void drawText(String s,
                     double x,
                     double y,
                     int flags)

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Overrides:
drawRect in class Graphics

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillRect in class Graphics

fillRect

public void fillRect(double x,
                     double y,
                     double width,
                     double height)

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
drawRoundRect in class Graphics

drawRoundRect

public void drawRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
fillRoundRect in class Graphics

fillRoundRect

public void fillRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawOval in class Graphics

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height)

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillOval in class Graphics

fillOval

public void fillOval(double x,
                     double y,
                     double width,
                     double height)

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int extent)
Specified by:
drawArc in class Graphics

drawArc

public void drawArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double extent)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int extent)
Specified by:
fillArc in class Graphics

fillArc

public void fillArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double extent)

drawImage

public void drawImage(org.eclipse.swt.graphics.Image image,
                      double x,
                      double y)

drawImage

public void drawImage(org.eclipse.swt.graphics.Image image,
                      int srcX,
                      int srcY,
                      int srcW,
                      int srcH,
                      double destX,
                      double destY,
                      double destW,
                      double destH)

setLineWidth

public void setLineWidth(double lineWidth)

getTransformedLineWidth

protected int getTransformedLineWidth()

fillGradientRectangle

public void fillGradientRectangle(double x,
                                  double y,
                                  double width,
                                  double height,
                                  boolean vertical)

setXORMode

public void setXORMode(boolean xOr)

getAdvanceWidth

public int getAdvanceWidth(char ch)

getCharWidth

public int getCharWidth(char ch)

stringExtent

public org.eclipse.swt.graphics.Point stringExtent(String str)

textExtent

public org.eclipse.swt.graphics.Point textExtent(String str)

textExtent

public org.eclipse.swt.graphics.Point textExtent(String str,
                                                 int flags)

drawString

public void drawString(AttributedCharacterIterator iterator,
                       int x,
                       int y)
Specified by:
drawString in class Graphics2D
See Also:
Graphics.drawString(AttributedCharacterIterator, int, int)

drawString

public void drawString(AttributedCharacterIterator iterator,
                       float x,
                       float y)
Specified by:
drawString in class Graphics2D
See Also:
Graphics2D.drawString(AttributedCharacterIterator, float, float)

drawGlyphVector

public void drawGlyphVector(GlyphVector g,
                            float x,
                            float y)
Specified by:
drawGlyphVector in class Graphics2D
See Also:
Graphics2D.drawGlyphVector(GlyphVector, float, float)

hit

public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke)
Specified by:
hit in class Graphics2D
See Also:
Graphics2D.hit(Rectangle, Shape, boolean)

setComposite

public void setComposite(Composite comp)
Specified by:
setComposite in class Graphics2D
See Also:
Graphics2D.setComposite(Composite)

setStroke

public void setStroke(Stroke s)
Specified by:
setStroke in class Graphics2D
See Also:
Graphics2D.setStroke(Stroke)

setRenderingHint

public void setRenderingHint(RenderingHints.Key hintKey,
                             Object hintValue)
Specified by:
setRenderingHint in class Graphics2D

getRenderingHint

public Object getRenderingHint(RenderingHints.Key hintKey)
Specified by:
getRenderingHint in class Graphics2D

setRenderingHints

public void setRenderingHints(Map hints)
Specified by:
setRenderingHints in class Graphics2D
See Also:
Graphics2D.setRenderingHints(Map)

addRenderingHints

public void addRenderingHints(Map hints)
Specified by:
addRenderingHints in class Graphics2D
See Also:
Graphics2D.addRenderingHints(Map)

getRenderingHints

public RenderingHints getRenderingHints()
Specified by:
getRenderingHints in class Graphics2D
See Also:
Graphics2D.getRenderingHints()

getComposite

public Composite getComposite()
Specified by:
getComposite in class Graphics2D
See Also:
Graphics2D.getComposite()

getStroke

public Stroke getStroke()
Specified by:
getStroke in class Graphics2D
See Also:
Graphics2D.getStroke()

getFontRenderContext

public FontRenderContext getFontRenderContext()
Specified by:
getFontRenderContext in class Graphics2D
See Also:
Graphics2D.getFontRenderContext()

create

public Graphics create()
Specified by:
create in class Graphics
See Also:
Graphics.create()

setPaintMode

public void setPaintMode()
Specified by:
setPaintMode in class Graphics
See Also:
Graphics.setPaintMode()

setXORMode

public void setXORMode(Color c1)
Specified by:
setXORMode in class Graphics
See Also:
Graphics.setXORMode(Color)

getFontMetrics

public FontMetrics getFontMetrics(Font f)
Specified by:
getFontMetrics in class Graphics
See Also:
Graphics.getFontMetrics(Font)

drawImage

public boolean drawImage(Image img,
                         AffineTransform xform,
                         ImageObserver obs)
Specified by:
drawImage in class Graphics2D
See Also:
Graphics2D.drawImage(Image, AffineTransform, ImageObserver)

drawImage

public void drawImage(BufferedImage img,
                      BufferedImageOp op,
                      int x,
                      int y)
Specified by:
drawImage in class Graphics2D
See Also:
Graphics2D.drawImage(BufferedImage, BufferedImageOp, int, int)

drawRenderedImage

public void drawRenderedImage(RenderedImage img,
                              AffineTransform xform)
Specified by:
drawRenderedImage in class Graphics2D
See Also:
Graphics2D.drawRenderedImage(RenderedImage, AffineTransform)

drawRenderableImage

public void drawRenderableImage(RenderableImage img,
                                AffineTransform xform)
Specified by:
drawRenderableImage in class Graphics2D
See Also:
Graphics2D.drawRenderableImage(RenderableImage, AffineTransform)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, int, int, ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, Color, ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, int, int, Color, ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, int, int, int, int, int, int, ImageObserver)

drawImage

public boolean drawImage(Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         Color bgcolor,
                         ImageObserver observer)
Specified by:
drawImage in class Graphics
See Also:
Graphics.drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)

dispose

public void dispose()
DO NOTHING - DISPOSED IN RENDERING CLASS

Specified by:
dispose in class Graphics

incrementGCCount

public static void incrementGCCount()

decrementGCCount

public static void decrementGCCount()


Copyright © 1995-2011 Piccolo2D. All Rights Reserved.