edu.umd.cs.piccolox.swt
Class SWTGraphics2D

java.lang.Object
  extended byjava.awt.Graphics
      extended byjava.awt.Graphics2D
          extended byedu.umd.cs.piccolox.swt.SWTGraphics2D

public class SWTGraphics2D
extends java.awt.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 java.awt.image.BufferedImage BUFFER
           
protected static int CACHE_COUNT
           
protected static java.util.HashMap COLOR_CACHE
           
protected  org.eclipse.swt.graphics.Font curFont
           
protected  org.eclipse.swt.graphics.Device device
           
protected static java.util.HashMap FONT_CACHE
           
protected  org.eclipse.swt.graphics.GC gc
           
protected  double lineWidth
           
protected static java.util.HashMap SHAPE_CACHE
           
protected  java.awt.geom.AffineTransform transform
           
 
Constructor Summary
SWTGraphics2D(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Device device)
          Constructor for SWTGraphics2D.
 
Method Summary
 void addRenderingHints(java.util.Map hints)
           
 void clearRect(int x, int y, int width, int height)
           
 void clip(java.awt.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)
           
 java.awt.Graphics create()
           
static void decrementGCCount()
           
 void dispose()
          DO NOTHING - DISPOSED IN RENDERING CLASS
 void draw(java.awt.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(java.awt.font.GlyphVector g, float x, float y)
           
 void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
           
 boolean drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
           
 void drawImage(org.eclipse.swt.graphics.Image image, double x, double y)
           
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.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(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.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(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
           
 void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.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(java.text.AttributedCharacterIterator iterator, float x, float y)
           
 void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(java.lang.String str, double x, double y)
           
 void drawString(java.lang.String str, float x, float y)
           
 void drawString(java.lang.String str, int x, int y)
           
 void drawText(java.lang.String s, double x, double y)
           
 void drawText(java.lang.String s, double x, double y, int flags)
           
 void fill(java.awt.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)
           
 java.awt.Color getBackground()
           
 int getCharWidth(char ch)
           
 java.awt.Shape getClip()
           
 java.awt.Rectangle getClipBounds()
           
 java.awt.Color getColor()
           
 java.awt.Composite getComposite()
           
 java.awt.GraphicsConfiguration getDeviceConfiguration()
           
 java.awt.Font getFont()
           
 org.eclipse.swt.graphics.Font getFont(java.lang.String fontString)
           
 java.awt.FontMetrics getFontMetrics(java.awt.Font f)
           
 java.awt.font.FontRenderContext getFontRenderContext()
           
 java.awt.Paint getPaint()
           
 java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
           
 java.awt.RenderingHints getRenderingHints()
           
 java.awt.Stroke getStroke()
           
 org.eclipse.swt.graphics.Font getSWTFont()
           
 org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics()
           
 java.awt.geom.AffineTransform getTransform()
           
protected  org.eclipse.swt.graphics.Font getTransformedFont()
           
protected  int getTransformedLineWidth()
           
 boolean hit(java.awt.Rectangle rect, java.awt.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(java.awt.Color c)
           
 void setBackground(org.eclipse.swt.graphics.Color c)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(java.awt.Shape clip)
          This method isn't really supported by SWT - so will use the shape bounds
 void setColor(java.awt.Color c)
           
 void setColor(org.eclipse.swt.graphics.Color c)
           
 void setComposite(java.awt.Composite comp)
           
 void setFont(java.awt.Font font)
           
 void setFont(org.eclipse.swt.graphics.Font font)
           
 void setLineWidth(double lineWidth)
           
 void setPaint(java.awt.Paint paint)
           
 void setPaintMode()
           
 void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
           
 void setRenderingHints(java.util.Map hints)
           
 void setStroke(java.awt.Stroke s)
           
 void setTransform(java.awt.geom.AffineTransform Tx)
           
 void setXORMode(boolean xOr)
           
 void setXORMode(java.awt.Color c1)
           
 void shear(double shx, double shy)
           
 org.eclipse.swt.graphics.Point stringExtent(java.lang.String str)
           
 org.eclipse.swt.graphics.Point textExtent(java.lang.String str)
           
 org.eclipse.swt.graphics.Point textExtent(java.lang.String str, int flags)
           
 void transform(java.awt.geom.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 java.util.HashMap FONT_CACHE

COLOR_CACHE

protected static java.util.HashMap COLOR_CACHE

SHAPE_CACHE

protected static java.util.HashMap SHAPE_CACHE

BUFFER

protected static java.awt.image.BufferedImage BUFFER

gc

protected org.eclipse.swt.graphics.GC gc

device

protected org.eclipse.swt.graphics.Device device

transform

protected java.awt.geom.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 java.awt.Rectangle getClipBounds()
See Also:
Graphics.getClipBounds()

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)

clip

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


setClip

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


getClip

public java.awt.Shape getClip()

getDeviceConfiguration

public java.awt.GraphicsConfiguration getDeviceConfiguration()

getPaint

public java.awt.Paint getPaint()

setPaint

public void setPaint(java.awt.Paint paint)

getColor

public java.awt.Color getColor()

setColor

public void setColor(java.awt.Color c)

setColor

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

setBackground

public void setBackground(java.awt.Color c)

setBackground

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

getBackground

public java.awt.Color getBackground()

getSWTFont

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

getSWTFontMetrics

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

getFont

public java.awt.Font getFont()

setFont

public void setFont(java.awt.Font font)

setFont

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

getFont

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

getTransformedFont

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

translate

public void translate(int x,
                      int y)

translate

public void translate(double tx,
                      double ty)

rotate

public void rotate(double theta)

rotate

public void rotate(double theta,
                   double x,
                   double y)

scale

public void scale(double sx,
                  double sy)

shear

public void shear(double shx,
                  double shy)

transform

public void transform(java.awt.geom.AffineTransform Tx)

setTransform

public void setTransform(java.awt.geom.AffineTransform Tx)

getTransform

public java.awt.geom.AffineTransform getTransform()

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)

draw

public void draw(java.awt.Shape s)

fill

public void fill(java.awt.Shape s)

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)

drawPolyline

public void drawPolyline(double[] pts)

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)

fillPolygon

public void fillPolygon(double[] pts)

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)

drawLine

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

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)

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y)

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)

drawString

public void drawString(java.lang.String str,
                       float x,
                       float y)

drawText

public void drawText(java.lang.String s,
                     double x,
                     double y)

drawText

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

drawRect

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

drawRect

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

fillRect

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

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)

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)

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)

drawOval

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

fillOval

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

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)

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)

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(java.lang.String str)

textExtent

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

textExtent

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

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
See Also:
Graphics.drawString(AttributedCharacterIterator, int, int)

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       float x,
                       float y)
See Also:
Graphics2D.drawString(AttributedCharacterIterator, float, float)

drawGlyphVector

public void drawGlyphVector(java.awt.font.GlyphVector g,
                            float x,
                            float y)
See Also:
Graphics2D.drawGlyphVector(GlyphVector, float, float)

hit

public boolean hit(java.awt.Rectangle rect,
                   java.awt.Shape s,
                   boolean onStroke)
See Also:
Graphics2D.hit(Rectangle, Shape, boolean)

setComposite

public void setComposite(java.awt.Composite comp)
See Also:
Graphics2D.setComposite(Composite)

setStroke

public void setStroke(java.awt.Stroke s)
See Also:
Graphics2D.setStroke(Stroke)

setRenderingHint

public void setRenderingHint(java.awt.RenderingHints.Key hintKey,
                             java.lang.Object hintValue)

getRenderingHint

public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)

setRenderingHints

public void setRenderingHints(java.util.Map hints)
See Also:
Graphics2D.setRenderingHints(Map)

addRenderingHints

public void addRenderingHints(java.util.Map hints)
See Also:
Graphics2D.addRenderingHints(Map)

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
See Also:
Graphics2D.getRenderingHints()

getComposite

public java.awt.Composite getComposite()
See Also:
Graphics2D.getComposite()

getStroke

public java.awt.Stroke getStroke()
See Also:
Graphics2D.getStroke()

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
See Also:
Graphics2D.getFontRenderContext()

create

public java.awt.Graphics create()
See Also:
Graphics.create()

setPaintMode

public void setPaintMode()
See Also:
Graphics.setPaintMode()

setXORMode

public void setXORMode(java.awt.Color c1)
See Also:
Graphics.setXORMode(Color)

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
See Also:
Graphics.getFontMetrics(Font)

drawImage

public boolean drawImage(java.awt.Image img,
                         java.awt.geom.AffineTransform xform,
                         java.awt.image.ImageObserver obs)
See Also:
Graphics2D.drawImage(Image, AffineTransform, ImageObserver)

drawImage

public void drawImage(java.awt.image.BufferedImage img,
                      java.awt.image.BufferedImageOp op,
                      int x,
                      int y)
See Also:
Graphics2D.drawImage(BufferedImage, BufferedImageOp, int, int)

drawRenderedImage

public void drawRenderedImage(java.awt.image.RenderedImage img,
                              java.awt.geom.AffineTransform xform)
See Also:
Graphics2D.drawRenderedImage(RenderedImage, AffineTransform)

drawRenderableImage

public void drawRenderableImage(java.awt.image.renderable.RenderableImage img,
                                java.awt.geom.AffineTransform xform)
See Also:
Graphics2D.drawRenderableImage(RenderableImage, AffineTransform)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.image.ImageObserver observer)
See Also:
Graphics.drawImage(Image, int, int, ImageObserver)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.image.ImageObserver observer)
See Also:
Graphics.drawImage(Image, int, int, int, int, ImageObserver)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
See Also:
Graphics.drawImage(Image, int, int, Color, ImageObserver)

drawImage

public boolean drawImage(java.awt.Image img,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
See Also:
Graphics.drawImage(Image, int, int, int, int, Color, ImageObserver)

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.image.ImageObserver observer)
See Also:
Graphics.drawImage(Image, int, int, int, int, int, int, int, int, ImageObserver)

drawImage

public boolean drawImage(java.awt.Image img,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
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


incrementGCCount

public static void incrementGCCount()

decrementGCCount

public static void decrementGCCount()


Copyright © 2004 by University of Maryland, College Park, MD 20742, USA All rights reserved.

Web Accessibility