org.jfree.experimental.swt
Class SWTGraphics2D

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by org.jfree.experimental.swt.SWTGraphics2D

public class SWTGraphics2D
extends java.awt.Graphics2D

This is a class utility to draw Graphics2D stuff on a swt composite. It is presently developed to use JFreeChart with the Standard Widget Toolkit but may be of a wider use later.


Constructor Summary
SWTGraphics2D(GC gc)
          Creates a new instance.
 
Method Summary
 void addRenderingHints(java.util.Map hints)
          Adds the hints in the specified map to the graphics context, replacing any existing hints.
 void clearRect(int x, int y, int width, int height)
          Fills the specified rectangle with the current background colour.
 void clip(java.awt.Shape s)
           
 void clipRect(int x, int y, int width, int height)
           
 void copyArea(int x, int y, int width, int height, int dx, int dy)
           
 java.awt.Graphics create()
           
 void dispose()
           
 void draw(java.awt.Shape shape)
          Draws the outline of the specified shape using the current stroke and paint settings.
 void drawArc(int x, int y, int width, int height, int arcStart, int arcAngle)
          Draws an arc that is part of an ellipse that fits within the specified framing rectangle.
 void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
           
 void drawImage(java.awt.image.BufferedImage image, java.awt.image.BufferedImageOp op, int x, int y)
           
 boolean drawImage(java.awt.Image image, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
           
 boolean drawImage(java.awt.Image image, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image image, int x, int y, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image image, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image image, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
           
 boolean drawImage(java.awt.Image image, 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 image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
           
 void drawImage(org.eclipse.swt.graphics.Image image, int x, int y)
          Draws an image at (x, y).
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line from (x1, y1) to (x2, y2) using the current stroke and paint settings.
 void drawOval(int x, int y, int width, int height)
          Draws an oval that fits within the specified rectangular region.
 void drawPolygon(int[] xPoints, int[] yPoints, int npoints)
          Draws the outline of the polygon specified by the given points, using the current paint and stroke settings.
 void drawPolyline(int[] xPoints, int[] yPoints, int npoints)
          Draws a sequence of connected lines specified by the given points, using the current paint and stroke settings.
 void drawRenderableImage(java.awt.image.renderable.RenderableImage image, java.awt.geom.AffineTransform xform)
           
 void drawRenderedImage(java.awt.image.RenderedImage image, java.awt.geom.AffineTransform xform)
           
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a rectangle with rounded corners that fits within the specified framing rectangle.
 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 text, float x, float y)
           
 void drawString(java.lang.String text, int x, int y)
          Draws a string on the receiver. note that to be consistent with the awt method, the y has to be modified with the ascent of the font.
 void fill(java.awt.Shape shape)
          Fills the specified shape using the current paint.
 void fillArc(int x, int y, int width, int height, int arcStart, int arcAngle)
          Fills an arc that is part of an ellipse that fits within the specified framing rectangle.
 void fillOval(int x, int y, int width, int height)
          Fills an oval that fits within the specified rectangular region.
 void fillPolygon(int[] xPoints, int[] yPoints, int npoints)
           
 void fillRect(int x, int y, int width, int height)
          Fill a rectangle area on the swt graphic composite.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a rectangle with rounded corners that fits within the specified framing rectangle.
 java.awt.Color getBackground()
           
 java.awt.Shape getClip()
           
 java.awt.Rectangle getClipBounds()
           
 java.awt.Color getColor()
          Returns the current color for this graphics context.
 java.awt.Composite getComposite()
          Returns the current composite.
 java.awt.GraphicsConfiguration getDeviceConfiguration()
           
 java.awt.Font getFont()
          Returns the font in form of an awt font created with the parameters of the font of the swt graphic composite.
 java.awt.FontMetrics getFontMetrics(java.awt.Font font)
           
 java.awt.font.FontRenderContext getFontRenderContext()
           
 java.awt.Paint getPaint()
          Returns the current paint for this graphics context.
 java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
          Returns the current value for the specified hint key, or null if no value is set.
 java.awt.RenderingHints getRenderingHints()
          Returns a copy of the hints collection for this graphics context.
 java.awt.Stroke getStroke()
          Returns the current stroke for this graphics context.
 java.awt.geom.AffineTransform getTransform()
           
 boolean hit(java.awt.Rectangle rect, java.awt.Shape text, boolean onStroke)
           
 void rotate(double theta)
           
 void rotate(double theta, double x, double y)
           
 void scale(double scaleX, double scaleY)
           
 void setBackground(java.awt.Color color)
           
 void setClip(int x, int y, int width, int height)
           
 void setClip(java.awt.Shape clip)
           
 void setColor(java.awt.Color color)
          Sets the current color for this graphics context.
 void setComposite(java.awt.Composite comp)
          Sets the current composite.
 void setFont(java.awt.Font font)
          Set the font swt graphic composite from the specified awt font.
 void setPaint(java.awt.Paint paint)
          Sets the paint for this graphics context.
 void setPaintMode()
           
 void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
          Sets the value for a rendering hint.
 void setRenderingHints(java.util.Map hints)
          Replaces the existing hints with those contained in the specified map.
 void setStroke(java.awt.Stroke stroke)
          Sets the stroke for this graphics context.
 void setTransform(java.awt.geom.AffineTransform Tx)
           
 void setXORMode(java.awt.Color color)
           
 void shear(double shearX, double shearY)
           
 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, drawRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SWTGraphics2D

public SWTGraphics2D(GC gc)
Creates a new instance.

Parameters:
gc - the graphics context.
Method Detail

create

public java.awt.Graphics create()
Specified by:
create in class java.awt.Graphics

getDeviceConfiguration

public java.awt.GraphicsConfiguration getDeviceConfiguration()
Specified by:
getDeviceConfiguration in class java.awt.Graphics2D

getRenderingHint

public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
Returns the current value for the specified hint key, or null if no value is set.

Specified by:
getRenderingHint in class java.awt.Graphics2D
Parameters:
hintKey - the hint key (null permitted).
Returns:
The hint value, or null.
See Also:
#setRenderingHint(Key, Object)

setRenderingHint

public void setRenderingHint(java.awt.RenderingHints.Key hintKey,
                             java.lang.Object hintValue)
Sets the value for a rendering hint. For now, this graphics context ignores all hints.

Specified by:
setRenderingHint in class java.awt.Graphics2D
Parameters:
hintKey - the key (null not permitted).
hintValue - the value (must be compatible with the specified key).
Throws:
java.lang.IllegalArgumentException - if hintValue is not compatible with the hintKey.
See Also:
#getRenderingHint(Key)

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
Returns a copy of the hints collection for this graphics context.

Specified by:
getRenderingHints in class java.awt.Graphics2D
Returns:
A copy of the hints collection.

addRenderingHints

public void addRenderingHints(java.util.Map hints)
Adds the hints in the specified map to the graphics context, replacing any existing hints. For now, this graphics context ignores all hints.

Specified by:
addRenderingHints in class java.awt.Graphics2D
Parameters:
hints - the hints (null not permitted).
See Also:
setRenderingHints(Map)

setRenderingHints

public void setRenderingHints(java.util.Map hints)
Replaces the existing hints with those contained in the specified map. Note that, for now, this graphics context ignores all hints.

Specified by:
setRenderingHints in class java.awt.Graphics2D
Parameters:
hints - the hints (null not permitted).
See Also:
addRenderingHints(Map)

getPaint

public java.awt.Paint getPaint()
Returns the current paint for this graphics context.

Specified by:
getPaint in class java.awt.Graphics2D
Returns:
The current paint.
See Also:
setPaint(Paint)

setPaint

public void setPaint(java.awt.Paint paint)
Sets the paint for this graphics context. For now, this graphics context only supports instances of Color.

Specified by:
setPaint in class java.awt.Graphics2D
Parameters:
paint - the paint (null not permitted).
See Also:
getPaint(), setColor(Color)

getColor

public java.awt.Color getColor()
Returns the current color for this graphics context.

Specified by:
getColor in class java.awt.Graphics
Returns:
The current color.
See Also:
setColor(Color)

setColor

public void setColor(java.awt.Color color)
Sets the current color for this graphics context.

Specified by:
setColor in class java.awt.Graphics
Parameters:
color - the color.
See Also:
getColor()

setBackground

public void setBackground(java.awt.Color color)
Specified by:
setBackground in class java.awt.Graphics2D

getBackground

public java.awt.Color getBackground()
Specified by:
getBackground in class java.awt.Graphics2D

setPaintMode

public void setPaintMode()
Specified by:
setPaintMode in class java.awt.Graphics

setXORMode

public void setXORMode(java.awt.Color color)
Specified by:
setXORMode in class java.awt.Graphics

getComposite

public java.awt.Composite getComposite()
Returns the current composite.

Specified by:
getComposite in class java.awt.Graphics2D
Returns:
The current composite.
See Also:
setComposite(Composite)

setComposite

public void setComposite(java.awt.Composite comp)
Sets the current composite. This implementation currently supports only the AlphaComposite class.

Specified by:
setComposite in class java.awt.Graphics2D
Parameters:
comp - the composite.

getStroke

public java.awt.Stroke getStroke()
Returns the current stroke for this graphics context.

Specified by:
getStroke in class java.awt.Graphics2D
Returns:
The current stroke.
See Also:
setStroke(Stroke)

setStroke

public void setStroke(java.awt.Stroke stroke)
Sets the stroke for this graphics context. For now, this implementation only recognises the BasicStroke class.

Specified by:
setStroke in class java.awt.Graphics2D
Parameters:
stroke - the stroke (null not permitted).
See Also:
getStroke()

clip

public void clip(java.awt.Shape s)
Specified by:
clip in class java.awt.Graphics2D

getClipBounds

public java.awt.Rectangle getClipBounds()
Specified by:
getClipBounds in class java.awt.Graphics

clipRect

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

getClip

public java.awt.Shape getClip()
Specified by:
getClip in class java.awt.Graphics

setClip

public void setClip(java.awt.Shape clip)
Specified by:
setClip in class java.awt.Graphics

setClip

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

getTransform

public java.awt.geom.AffineTransform getTransform()
Specified by:
getTransform in class java.awt.Graphics2D

setTransform

public void setTransform(java.awt.geom.AffineTransform Tx)
Specified by:
setTransform in class java.awt.Graphics2D

transform

public void transform(java.awt.geom.AffineTransform Tx)
Specified by:
transform in class java.awt.Graphics2D

translate

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

translate

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

rotate

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

rotate

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

scale

public void scale(double scaleX,
                  double scaleY)
Specified by:
scale in class java.awt.Graphics2D

shear

public void shear(double shearX,
                  double shearY)
Specified by:
shear in class java.awt.Graphics2D

draw

public void draw(java.awt.Shape shape)
Draws the outline of the specified shape using the current stroke and paint settings.

Specified by:
draw in class java.awt.Graphics2D
Parameters:
shape - the shape (null not permitted).
See Also:
getPaint(), getStroke(), fill(Shape)

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line from (x1, y1) to (x2, y2) using the current stroke and paint settings.

Specified by:
drawLine in class java.awt.Graphics
Parameters:
x1 - the x-coordinate for the starting point.
y1 - the y-coordinate for the starting point.
x2 - the x-coordinate for the ending point.
y2 - the y-coordinate for the ending point.
See Also:
draw(Shape)

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int npoints)
Draws the outline of the polygon specified by the given points, using the current paint and stroke settings.

Specified by:
drawPolygon in class java.awt.Graphics
Parameters:
xPoints - the x-coordinates.
yPoints - the y-coordinates.
npoints - the number of points in the polygon.
See Also:
draw(Shape)

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int npoints)
Draws a sequence of connected lines specified by the given points, using the current paint and stroke settings.

Specified by:
drawPolyline in class java.awt.Graphics
Parameters:
xPoints - the x-coordinates.
yPoints - the y-coordinates.
npoints - the number of points in the polygon.
See Also:
draw(Shape)

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draws an oval that fits within the specified rectangular region.

Specified by:
drawOval in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
See Also:
fillOval(int, int, int, int), draw(Shape)

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int arcStart,
                    int arcAngle)
Draws an arc that is part of an ellipse that fits within the specified framing rectangle.

Specified by:
drawArc in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
arcStart - the arc starting point, in degrees.
arcAngle - the extent of the arc.
See Also:
fillArc(int, int, int, int, int, int)

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a rectangle with rounded corners that fits within the specified framing rectangle.

Specified by:
drawRoundRect in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
arcWidth - the width of the arc defining the roundedness of the rectangle's corners.
arcHeight - the height of the arc defining the roundedness of the rectangle's corners.
See Also:
fillRoundRect(int, int, int, int, int, int)

fill

public void fill(java.awt.Shape shape)
Fills the specified shape using the current paint.

Specified by:
fill in class java.awt.Graphics2D
Parameters:
shape - the shape (null not permitted).
See Also:
getPaint(), draw(Shape)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fill a rectangle area on the swt graphic composite. The fillRectangle method of the GC class uses the background color so we must switch colors.

Specified by:
fillRect in class java.awt.Graphics
See Also:
Graphics.fillRect(int, int, int, int)

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Fills the specified rectangle with the current background colour.

Specified by:
clearRect in class java.awt.Graphics
Parameters:
x - the x-coordinate for the rectangle.
y - the y-coordinate for the rectangle.
width - the width.
height - the height.
See Also:
fillRect(int, int, int, int)

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int npoints)
Specified by:
fillPolygon in class java.awt.Graphics

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a rectangle with rounded corners that fits within the specified framing rectangle.

Specified by:
fillRoundRect in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
arcWidth - the width of the arc defining the roundedness of the rectangle's corners.
arcHeight - the height of the arc defining the roundedness of the rectangle's corners.
See Also:
drawRoundRect(int, int, int, int, int, int)

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fills an oval that fits within the specified rectangular region.

Specified by:
fillOval in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
See Also:
drawOval(int, int, int, int), fill(Shape)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int arcStart,
                    int arcAngle)
Fills an arc that is part of an ellipse that fits within the specified framing rectangle.

Specified by:
fillArc in class java.awt.Graphics
Parameters:
x - the x-coordinate.
y - the y-coordinate.
width - the frame width.
height - the frame height.
arcStart - the arc starting point, in degrees.
arcAngle - the extent of the arc.
See Also:
drawArc(int, int, int, int, int, int)

getFont

public java.awt.Font getFont()
Returns the font in form of an awt font created with the parameters of the font of the swt graphic composite.

Specified by:
getFont in class java.awt.Graphics
See Also:
Graphics.getFont()

setFont

public void setFont(java.awt.Font font)
Set the font swt graphic composite from the specified awt font. Be careful that the newly created swt font must be disposed separately.

Specified by:
setFont in class java.awt.Graphics
See Also:
Graphics.setFont(java.awt.Font)

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Specified by:
getFontMetrics in class java.awt.Graphics

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
Specified by:
getFontRenderContext in class java.awt.Graphics2D

drawGlyphVector

public void drawGlyphVector(java.awt.font.GlyphVector g,
                            float x,
                            float y)
Specified by:
drawGlyphVector in class java.awt.Graphics2D

drawString

public void drawString(java.lang.String text,
                       int x,
                       int y)
Draws a string on the receiver. note that to be consistent with the awt method, the y has to be modified with the ascent of the font.

Specified by:
drawString in class java.awt.Graphics2D
See Also:
Graphics.drawString(java.lang.String, int, int)

drawString

public void drawString(java.lang.String text,
                       float x,
                       float y)
Specified by:
drawString in class java.awt.Graphics2D

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
Specified by:
drawString in class java.awt.Graphics2D

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       float x,
                       float y)
Specified by:
drawString in class java.awt.Graphics2D

hit

public boolean hit(java.awt.Rectangle rect,
                   java.awt.Shape text,
                   boolean onStroke)
Specified by:
hit in class java.awt.Graphics2D

copyArea

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

drawImage

public boolean drawImage(java.awt.Image image,
                         java.awt.geom.AffineTransform xform,
                         java.awt.image.ImageObserver obs)
Specified by:
drawImage in class java.awt.Graphics2D

drawImage

public void drawImage(java.awt.image.BufferedImage image,
                      java.awt.image.BufferedImageOp op,
                      int x,
                      int y)
Specified by:
drawImage in class java.awt.Graphics2D

drawImage

public void drawImage(org.eclipse.swt.graphics.Image image,
                      int x,
                      int y)
Draws an image at (x, y).

Parameters:
image - the image.
x - the x-coordinate.
y - the y-coordinate.

drawRenderedImage

public void drawRenderedImage(java.awt.image.RenderedImage image,
                              java.awt.geom.AffineTransform xform)
Specified by:
drawRenderedImage in class java.awt.Graphics2D

drawRenderableImage

public void drawRenderableImage(java.awt.image.renderable.RenderableImage image,
                                java.awt.geom.AffineTransform xform)
Specified by:
drawRenderableImage in class java.awt.Graphics2D

drawImage

public boolean drawImage(java.awt.Image image,
                         int x,
                         int y,
                         java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int x,
                         int y,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

public boolean drawImage(java.awt.Image image,
                         int x,
                         int y,
                         int width,
                         int height,
                         java.awt.Color bgcolor,
                         java.awt.image.ImageObserver observer)
Specified by:
drawImage in class java.awt.Graphics

drawImage

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

drawImage

public boolean drawImage(java.awt.Image image,
                         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)
Specified by:
drawImage in class java.awt.Graphics

dispose

public void dispose()
Specified by:
dispose in class java.awt.Graphics