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
          Buffer used to extract the graphics device.
protected static int CACHE_COUNT
          The number of Graphics Contexts active as determined by called to incrementGCCount and decrementGCCount.
protected static HashMap COLOR_CACHE
          Map from awt colors to swt colors.
protected  org.eclipse.swt.graphics.Font curFont
          The current font to use when drawing text.
protected  org.eclipse.swt.graphics.Device device
          Device onto which all graphics operations will ultimately take place.
protected static HashMap FONT_CACHE
          Map from font names to Fonts.
protected  org.eclipse.swt.graphics.GC gc
          The Underlying GraphicsContext provided by swt.
protected  double lineWidth
          The current stroke width to use when drawing lines.
protected static HashMap SHAPE_CACHE
          Map from awt shapess to swt Paths.
protected  AffineTransform transform
          The current transform to apply to drawing operations.
 
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)
          Copies the image to the specified position.
 void copyArea(int x, int y, int width, int height, int dx, int dy)
          
 Graphics create()
          
static void decrementGCCount()
          Decreases the number of uses of this graphics 2d object.
 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)
          Draws the outline of a circular or elliptical arc covering the specified rectangle.
 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)
          Draws the provided image at the position specified.
 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)
          Draws the source region from the image onto the destination region of the graphics context.
 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)
          Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
 void drawLine(int x1, int y1, int x2, int y2)
          
 void drawOval(double x, double y, double width, double height)
          Draws the outline of an oval.
 void drawOval(int x, int y, int width, int height)
          
 void drawPath(org.eclipse.swt.graphics.Path p)
          Draws the provided path.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          
 void drawPolyline(double[] pts)
          Draw a polyline from the specified double array of points.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
          
 void drawRect(double x, double y, double width, double height)
          Draws the outline of the specified rectangle.
 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)
          Draws an outlined round-cornered rectangle using this graphics context's current color.
 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)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void drawString(String str, double x, double y, boolean isTransparent)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void drawString(String str, float x, float y)
          
 void drawString(String str, int x, int y)
          
 void drawString(String str, int x, int y, boolean isTransparent)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void drawText(String str, double x, double y)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void drawText(String str, double x, double y, int flags)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void drawText(String str, int x, int y, int flags)
          Renders the text of the specified String, using the current text attribute state in the Graphics2D context.
 void fill(Shape s)
          
 void fillArc(double x, double y, double width, double height, double startAngle, double extent)
          Draws a filledArc with the options provided.
 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)
          Fills a gradient rectangle of in the direction specified.
 void fillOval(double x, double y, double width, double height)
          Fills an oval bounded by the specified rectangle with the current color.
 void fillOval(int x, int y, int width, int height)
          
 void fillPath(org.eclipse.swt.graphics.Path p)
          Draws a filled version of the provided path.
 void fillPolygon(double[] pts)
          Fill a polyline from the specified double array of points.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          
 void fillRect(double x, double y, double width, double height)
          Fills the specified rectangle.
 void fillRect(int x, int y, int width, int height)
          
 void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
          Fills the specified rounded corner rectangle with the current color.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          
 int getAdvanceWidth(char ch)
          Returns the advance width of the character provided in the current font.
 Color getBackground()
          
 int getCharWidth(char ch)
          Returns the width of the character provided in the current font.
 Shape getClip()
          
 Rectangle getClipBounds()
          
 Color getColor()
          
 Composite getComposite()
          
 GraphicsConfiguration getDeviceConfiguration()
          Returns a dummy device configuration.
 Font getFont()
          
 org.eclipse.swt.graphics.Font getFont(String fontString)
          Returns the SWT font matching the given font string.
 FontMetrics getFontMetrics(Font f)
          
 FontRenderContext getFontRenderContext()
          
 Paint getPaint()
          
 Object getRenderingHint(RenderingHints.Key hintKey)
          
 RenderingHints getRenderingHints()
          
 Stroke getStroke()
          
 org.eclipse.swt.graphics.Font getSWTFont()
          Returns the current swt font to use when drawing.
 org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics()
          Returns the font metrics of the current SWT font.
 AffineTransform getTransform()
          
protected  org.eclipse.swt.graphics.Font getTransformedFont()
          Deprecated.  
protected  int getTransformedLineWidth()
          Computes the width of the line after it passes through the current transform.
 boolean hit(Rectangle rect, Shape s, boolean onStroke)
          Returns whether the given rect and shape touch.
static void incrementGCCount()
          Increases the number of uses of this graphics 2d object.
 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 backgroundColor)
          Sets the background color to the provided swt color.
 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 foregroundColor)
          Sets the foreground color to the provided swt color.
 void setComposite(Composite comp)
          
 void setFont(Font font)
          
 void setFont(org.eclipse.swt.graphics.Font font)
          Set the font for this SWTGraphics2D to font.
 void setLineWidth(double lineWidth)
          Sets the line width to use when drawing shapes.
 void setPaint(Paint paint)
          
 void setPaintMode()
          
 void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
          
 void setRenderingHints(Map hints)
          
 void setStroke(Stroke s)
          
 void setTransform(AffineTransform newTransform)
          
 void setXORMode(boolean xOr)
          Deprecated. since underlying method has been deprecated
 void setXORMode(Color c1)
          
 void shear(double shx, double shy)
          
 org.eclipse.swt.graphics.Point stringExtent(String str)
          Returns the extent of the provided string in the current font.
 org.eclipse.swt.graphics.Point textExtent(String str)
          Returns the extent of the provided text in the current font.
 org.eclipse.swt.graphics.Point textExtent(String str, int flags)
          Returns the extent of the provided text in the current font assuming the flags given.
 void transform(AffineTransform srcTransform)
          
 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
The number of Graphics Contexts active as determined by called to incrementGCCount and decrementGCCount.


FONT_CACHE

protected static HashMap FONT_CACHE
Map from font names to Fonts.


COLOR_CACHE

protected static HashMap COLOR_CACHE
Map from awt colors to swt colors.


SHAPE_CACHE

protected static HashMap SHAPE_CACHE
Map from awt shapess to swt Paths.


BUFFER

protected static BufferedImage BUFFER
Buffer used to extract the graphics device.


gc

protected org.eclipse.swt.graphics.GC gc
The Underlying GraphicsContext provided by swt.


device

protected org.eclipse.swt.graphics.Device device
Device onto which all graphics operations will ultimately take place.


transform

protected AffineTransform transform
The current transform to apply to drawing operations.


curFont

protected org.eclipse.swt.graphics.Font curFont
The current font to use when drawing text.


lineWidth

protected double lineWidth
The current stroke width to use when drawing lines.

Constructor Detail

SWTGraphics2D

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

Parameters:
gc - The Eclipse Graphics Context onto which all Graphics2D operations are delegating
device - Device onto which ultimately all gc operations are drawn onto
Method Detail

getClipBounds

public Rectangle getClipBounds()

Specified by:
getClipBounds in class Graphics

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
Parameters:
s - shape of the clipping region to apply to graphics operations

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
Parameters:
clip - the desired clipping region's shape, will be simplified to its bounds

getClip

public Shape getClip()

Specified by:
getClip in class Graphics

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Returns a dummy device configuration.

Specified by:
getDeviceConfiguration in class Graphics2D
Returns:
a dummy device configuration

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 foregroundColor)
Sets the foreground color to the provided swt color.

Parameters:
foregroundColor - new foreground color

setBackground

public void setBackground(Color c)

Specified by:
setBackground in class Graphics2D

setBackground

public void setBackground(org.eclipse.swt.graphics.Color backgroundColor)
Sets the background color to the provided swt color.

Parameters:
backgroundColor - new background color

getBackground

public Color getBackground()

Specified by:
getBackground in class Graphics2D

getSWTFont

public org.eclipse.swt.graphics.Font getSWTFont()
Returns the current swt font to use when drawing.

Returns:
current swt font

getSWTFontMetrics

public org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics()
Returns the font metrics of the current SWT font.

Returns:
font metrics of the current SWT font

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)
Set the font for this SWTGraphics2D to font.

Parameters:
font - font for this SWTGraphics2D

getFont

public org.eclipse.swt.graphics.Font getFont(String fontString)
Returns the SWT font matching the given font string.

Parameters:
fontString - description of the font desired
Returns:
matching font, or null if not found

getTransformedFont

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

Deprecated since SWT now handles this.

Returns:
font that's been transformed by the current transform

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 srcTransform)

Specified by:
transform in class Graphics2D

setTransform

public void setTransform(AffineTransform newTransform)

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)
Draw a polyline from the specified double array of points.

Parameters:
pts - double array of points

drawPolygon

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

Specified by:
drawPolygon in class Graphics

fillPolygon

public void fillPolygon(double[] pts)
Fill a polyline from the specified double array of points.

Parameters:
pts - double array of points

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)
Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Parameters:
x1 - the first point's x coordinate.
y1 - the first point's y coordinate.
x2 - the second point's x coordinate.
y2 - the second point's y coordinate.

copyArea

public void copyArea(org.eclipse.swt.graphics.Image img,
                     double x,
                     double y)
Copies the image to the specified position.

Parameters:
img - swt image to be copied
x - x component of position
y - y component of position

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,
                       int x,
                       int y,
                       boolean isTransparent)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered
isTransparent - whether a background should be painted behind the text

drawString

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

Specified by:
drawString in class Graphics2D

drawString

public void drawString(String str,
                       double x,
                       double y)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered

drawString

public void drawString(String str,
                       double x,
                       double y,
                       boolean isTransparent)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered
isTransparent - whether a background should be painted behind the text

drawString

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

Specified by:
drawString in class Graphics2D

drawText

public void drawText(String str,
                     double x,
                     double y)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered

drawText

public void drawText(String str,
                     double x,
                     double y,
                     int flags)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered
flags - flags to apply to the string as defined by SWT

drawText

public void drawText(String str,
                     int x,
                     int y,
                     int flags)
Renders the text of the specified String, using the current text attribute state in the Graphics2D context. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.

Parameters:
str - the string to be rendered
x - the x coordinate of the location where the String should be rendered
y - the y coordinate of the location where the String should be rendered
flags - flags to apply to the string as defined by SWT

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)
Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the graphics context's current color.

Parameters:
x - the x coordinate of the rectangle to be drawn.
y - the y coordinate of the rectangle to be drawn.
width - the width of the rectangle to be drawn.
height - the height of the rectangle to be drawn.

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)
Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.

Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.

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)
Draws an outlined round-cornered rectangle using this graphics context's current color. The left and right edges of the rectangle are at x and x + width, respectively. The top and bottom edges of the rectangle are at y and y + height.

Parameters:
x - the x coordinate of the rectangle to be drawn.
y - the y coordinate of the rectangle to be drawn.
width - the width of the rectangle to be drawn.
height - the height of the rectangle to be drawn.
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners.

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)
Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are at x and x + width - 1, respectively. The top and bottom edges of the rectangle are at y and y + height - 1.

Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners.

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)
Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments. The oval covers an area that is width + 1 pixels wide and height + 1 pixels tall.

Parameters:
x - the x coordinate of the upper left corner of the oval to be drawn.
y - the y coordinate of the upper left corner of the oval to be drawn.
width - the width of the oval to be drawn.
height - the height of the oval to be drawn.

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)
Fills an oval bounded by the specified rectangle with the current color.

Parameters:
x - the x coordinate of the upper left corner of the oval to be filled.
y - the y coordinate of the upper left corner of the oval to be filled.
width - the width of the oval to be filled.
height - the height of the oval to be filled.

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)
Draws the outline of a circular or elliptical arc covering the specified rectangle. The resulting arc begins at startAngle and extends for arcAngle degrees, using the current color. Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation. The center of the arc is the center of the rectangle whose origin is (x, y) and whose size is specified by the width and height arguments. The resulting arc covers an area width + 1 pixels wide by height + 1 pixels tall. The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.

Parameters:
x - the x coordinate of the upper-left corner of the arc to be drawn.
y - the y coordinate of the upper-left corner of the arc to be drawn.
width - the width of the arc to be drawn.
height - the height of the arc to be drawn.
startAngle - the beginning angle.
extent - the angular extent of the arc, relative to the start angle.

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)
Draws a filledArc with the options provided.

Parameters:
x - the x coordinate of the upper-left corner of the arc to be filled.
y - the y coordinate of the upper-left corner of the arc to be filled.
width - the width of the arc to be filled.
height - the height of the arc to be filled.
startAngle - the beginning angle.
extent - the angular extent of the arc, relative to the start angle.

drawPath

public void drawPath(org.eclipse.swt.graphics.Path p)
Draws the provided path.

Parameters:
p - path to draw

fillPath

public void fillPath(org.eclipse.swt.graphics.Path p)
Draws a filled version of the provided path.

Parameters:
p - path to draw filled

drawImage

public void drawImage(org.eclipse.swt.graphics.Image image,
                      double x,
                      double y)
Draws the provided image at the position specified.

Parameters:
image - image to draw
x - x component of the position
y - y component of the position

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)
Draws the source region from the image onto the destination region of the graphics context. Stretching if necessary.

Parameters:
image - image from which to copy
srcX - the left of the source region
srcY - the top of the source region
srcW - the width of the source region
srcH - the height of the source region
destX - the left of the destination region
destY - the top of the destination region
destW - the width of the destination region
destH - the height of the destination region

setLineWidth

public void setLineWidth(double lineWidth)
Sets the line width to use when drawing shapes.

Parameters:
lineWidth - width of line when drawing shapes

getTransformedLineWidth

protected int getTransformedLineWidth()
Computes the width of the line after it passes through the current transform.

Returns:
resulting width of line after being transform

fillGradientRectangle

public void fillGradientRectangle(double x,
                                  double y,
                                  double width,
                                  double height,
                                  boolean vertical)
Fills a gradient rectangle of in the direction specified.

Parameters:
x - left of resulting rectangle
y - top of resulting rectangle
width - width of resulting rectangle
height - height of resulting rectangle
vertical - whether the gradient should be drawn vertically or horizontally

setXORMode

public void setXORMode(boolean xOr)
Deprecated. since underlying method has been deprecated

Parameters:
xOr - whether to be in xOr mode

getAdvanceWidth

public int getAdvanceWidth(char ch)
Returns the advance width of the character provided in the current font.

Parameters:
ch - character to calculate the advance width of.
Returns:
advance width of the character in the current font

getCharWidth

public int getCharWidth(char ch)
Returns the width of the character provided in the current font.

Parameters:
ch - character to calculate the width of.
Returns:
width of the character in the current font

stringExtent

public org.eclipse.swt.graphics.Point stringExtent(String str)
Returns the extent of the provided string in the current font.

Parameters:
str - string to calculate the extent of.
Returns:
extent of the string in the current font

textExtent

public org.eclipse.swt.graphics.Point textExtent(String str)
Returns the extent of the provided text in the current font.

Parameters:
str - string to calculate the extent of.
Returns:
extent of the string in the current font

textExtent

public org.eclipse.swt.graphics.Point textExtent(String str,
                                                 int flags)
Returns the extent of the provided text in the current font assuming the flags given.

Parameters:
str - string to calculate the extent of
flags - flags to apply to the rendered font before calculation of extent takes place
Returns:
extent of the string in the current font assuming flags provided

drawString

public void drawString(AttributedCharacterIterator iterator,
                       int x,
                       int y)

Specified by:
drawString in class Graphics2D

drawString

public void drawString(AttributedCharacterIterator iterator,
                       float x,
                       float y)

Specified by:
drawString in class Graphics2D

drawGlyphVector

public void drawGlyphVector(GlyphVector g,
                            float x,
                            float y)

Specified by:
drawGlyphVector in class Graphics2D

hit

public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke)
Returns whether the given rect and shape touch. If onStroke = true then it'll include the width of the stroke when calculating.

Specified by:
hit in class Graphics2D
Parameters:
rect - rect to test
s - shape to test
onStroke - whether to consider the width of the stroke
Returns:
true if they touch

setComposite

public void setComposite(Composite comp)

Specified by:
setComposite in class Graphics2D

setStroke

public void setStroke(Stroke s)

Specified by:
setStroke in class Graphics2D

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()
Increases the number of uses of this graphics 2d object.


decrementGCCount

public static void decrementGCCount()
Decreases the number of uses of this graphics 2d object.



Copyright © 1995-2011 Piccolo2D. All Rights Reserved.