public class SWTGraphics extends Graphics
Graphics using an SWT
GC. There are 2 states contained in this graphics class -- the
applied state which is the actual state of the GC and the current state which
is the current state of this graphics object. Certain properties can be
changed multiple times and the GC won't be updated until it's actually used.
WARNING: This class is not intended to be subclassed.
LINE_CUSTOM, LINE_DASH, LINE_DASHDOT, LINE_DASHDOTDOT, LINE_DOT, LINE_SOLID| Constructor and Description |
|---|
SWTGraphics(GC gc)
Constructs a new SWTGraphics that draws to the Canvas using the given GC.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkFill()
If the background color has changed, this change will be pushed to the
GC.
|
protected void |
checkGC()
If the rendering hints or the clip region has changed, these changes will
be pushed to the GC.
|
protected void |
checkPaint()
If the line width, line style, foreground or background colors have
changed, these changes will be pushed to the GC.
|
protected void |
checkText()
If the font has changed, this change will be pushed to the GC.
|
void |
clipPath(Path path)
Simple implementation of clipping a Path within the context of current
clipping rectangle for now (not region) Note that this method wipes
out the clipping rectangle area, hence if clients need to reset it call
restoreState() |
void |
clipRect(Rectangle rect)
Sets the clip region to the given rectangle.
|
static LineAttributes |
clone(LineAttributes src)
Countermeasure against LineAttributes class not having its own clone()
method.
|
static void |
copyLineAttributes(LineAttributes dest,
LineAttributes src)
Countermeasure against LineAttributes class not having a copy by value
function.
|
void |
dispose()
Disposes this object, releasing any resources.
|
void |
drawArc(int x,
int y,
int width,
int height,
int offset,
int length)
Draws the outline of an arc located at (x,y) with width w and
height h.
|
void |
drawFocus(int x,
int y,
int w,
int h)
Draws a focus rectangle.
|
void |
drawImage(Image srcImage,
int x,
int y)
Draws the given Image at the location (x,y).
|
void |
drawImage(Image srcImage,
int x1,
int y1,
int w1,
int h1,
int x2,
int y2,
int w2,
int h2)
Draws a rectangular section of the given Image to the specified
rectangular reagion on the canvas.
|
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line between the points
(x1,y1) and
(x2,y2) using the foreground color. |
void |
drawOval(int x,
int y,
int width,
int height)
Draws the outline of an ellipse that fits inside the rectangle with the
given properties using the foreground color.
|
void |
drawPath(Path path)
This method requires advanced graphics support.
|
void |
drawPoint(int x,
int y)
Draws a pixel, using the foreground color, at the specified point (
x, y). |
void |
drawPolygon(int[] points)
Draws a closed polygon defined by the given Integer array containing the
vertices in x,y order.
|
void |
drawPolygon(PointList points)
Draws a closed polygon defined by the given
PointList
containing the vertices. |
void |
drawPolyline(int[] points)
Draws a polyline defined by the given Integer array containing the
vertices in x,y order.
|
void |
drawPolyline(PointList points)
Draws a polyline defined by the given
PointList containing
the vertices. |
void |
drawRectangle(int x,
int y,
int width,
int height)
Draws a rectangle whose top-left corner is located at the point (x,y)
with the given width and height.
|
void |
drawRoundRectangle(Rectangle r,
int arcWidth,
int arcHeight)
Draws a rectangle with rounded corners using the foreground color.
|
void |
drawString(java.lang.String s,
int x,
int y)
Draws the given string using the current font and foreground color.
|
void |
drawText(java.lang.String s,
int x,
int y)
Draws the given string using the current font and foreground color.
|
void |
drawTextLayout(TextLayout layout,
int x,
int y,
int selectionStart,
int selectionEnd,
Color selectionForeground,
Color selectionBackground) |
void |
fillArc(int x,
int y,
int width,
int height,
int offset,
int length)
Fills the interior of an arc located at (x,y) with width
w and height h.
|
void |
fillGradient(int x,
int y,
int w,
int h,
boolean vertical)
Fills the the given rectangle with a gradient from the foreground color
to the background color.
|
void |
fillOval(int x,
int y,
int width,
int height)
Fills an ellipse that fits inside the rectangle with the given properties
using the background color.
|
void |
fillPath(Path path)
This method requires advanced graphics support.
|
void |
fillPolygon(int[] points)
Fills a closed polygon defined by the given Integer array containing the
vertices in x,y order.
|
void |
fillPolygon(PointList points)
Fills a closed polygon defined by the given
PointList
containing the vertices. |
void |
fillRectangle(int x,
int y,
int width,
int height)
Fills a rectangle whose top-left corner is located at the point (x,y)
with the given width and height.
|
void |
fillRoundRectangle(Rectangle r,
int arcWidth,
int arcHeight)
Fills a rectangle with rounded corners using the background color.
|
void |
fillString(java.lang.String s,
int x,
int y)
Draws the given string using the current font and foreground color.
|
void |
fillText(java.lang.String s,
int x,
int y)
Draws the given string using the current font and foreground color.
|
boolean |
getAdvanced() |
int |
getAlpha()
Returns the current alpha value of the graphics.
|
int |
getAntialias()
Returns the anti-aliasing setting value, which will be one of
SWT.DEFAULT, SWT.OFF or SWT.ON. |
Color |
getBackgroundColor()
Returns the background color used for filling.
|
Rectangle |
getClip(Rectangle rect)
Modifies the given rectangle to match the clip region and returns that
rectangle.
|
int |
getFillRule()
Returns the fill rule, which will be one of
SWT.FILL_EVEN_ODD or SWT.FILL_WINDING. |
Font |
getFont()
Returns the font used to draw and fill text.
|
FontMetrics |
getFontMetrics()
Returns the font metrics for the current font.
|
Color |
getForegroundColor()
Returns the foreground color used to draw lines and text.
|
int |
getInterpolation()
Returns the interpolation setting.
|
void |
getLineAttributes(LineAttributes lineAttributes) |
int |
getLineCap()
Returns the current line cap style.
|
float[] |
getLineDash() |
float |
getLineDashOffset() |
int |
getLineJoin()
Returns the line join style.
|
float |
getLineMiterLimit()
Returns the line miter limit.
|
int |
getLineStyle()
Returns the line style.
|
int |
getLineWidth()
Returns the current line width.
|
float |
getLineWidthFloat()
Returns the current line width.
|
int |
getTextAntialias()
Returns the textual anti-aliasing setting value, which will be one of
SWT.DEFAULT, SWT.OFF or SWT.ON. |
boolean |
getXORMode()
Returns
true if this graphics object should use XOR mode
with painting. |
protected void |
init()
Called by constructor, initializes all State information for currentState
|
void |
popState()
Pops the previous state of this graphics object off the stack (if
Graphics.pushState() has previously been called) and restores the current
state to that popped state. |
void |
pushState()
Pushes the current state of this graphics object onto a stack.
|
void |
restoreState()
Restores the previous state of this graphics object.
|
protected void |
restoreState(org.eclipse.draw2d.SWTGraphics.State s)
Sets all State information to that of the given State, called by
restoreState()
|
void |
rotate(float degrees)
This method requires advanced graphics support.
|
void |
scale(double factor)
Scales this graphics object by the given amount.
|
void |
scale(float horizontal,
float vertical)
This method requires advanced graphics support.
|
void |
setAdvanced(boolean value)
Turns advanced graphics mode on or off.
|
void |
setAlpha(int alpha)
This method requires advanced graphics support.
|
void |
setAntialias(int value)
This method requires advanced graphics support.
|
void |
setBackgroundColor(Color color)
Sets the background color.
|
void |
setBackgroundPattern(Pattern pattern)
Sets the pattern used for fill-type graphics operations.
|
void |
setClip(Path path)
This method requires advanced graphics support.
|
void |
setClip(Rectangle rect)
Sets the clip rectangle.
|
void |
setFillRule(int rule)
Sets the fill rule to the given value, which must be one of
SWT.FILL_EVEN_ODD or SWT.FILL_WINDING. |
void |
setFont(Font f)
Sets the font.
|
void |
setForegroundColor(Color color)
Sets the foreground color.
|
void |
setForegroundPattern(Pattern pattern)
Sets the foreground pattern for draw and text operations.
|
void |
setInterpolation(int interpolation)
This method requires advanced graphics support.
|
void |
setLineAttributes(LineAttributes lineAttributes)
Sets all line attributes together
|
void |
setLineCap(int value)
Sets the line cap style to the argument, which must be one of the
constants
SWT.CAP_FLAT, SWT.CAP_ROUND, or
SWT.CAP_SQUARE. |
void |
setLineDash(float[] value)
Sets the dash pattern when the custom line style is in use.
|
void |
setLineDash(int[] dashes)
Sets the dash pattern when the custom line style is in use.
|
void |
setLineDashOffset(float value)
Sets the line dash offset.
|
void |
setLineJoin(int value)
Sets the line join style to the argument, which must be one of the
constants
SWT.JOIN_MITER, SWT.JOIN_ROUND, or
SWT.JOIN_BEVEL. |
void |
setLineMiterLimit(float value) |
void |
setLineStyle(int value)
Sets the line style to the argument, which must be one of the constants
SWT.LINE_SOLID, SWT.LINE_DASH,
SWT.LINE_DOT, SWT.LINE_DASHDOT or
SWT.LINE_DASHDOTDOT. |
void |
setLineWidth(int width)
Sets the line width.
|
void |
setLineWidthFloat(float value)
Sets the line width.
|
void |
setTextAntialias(int value)
This method requires advanced graphics support.
|
void |
setXORMode(boolean xor)
Sets the XOR mode.
|
void |
shear(float horz,
float vert)
This method requires advanced graphics support.
|
void |
translate(float dx,
float dy)
This method requires advanced graphics support.
|
void |
translate(int dx,
int dy)
This method may require advanced graphics support if using a transform,
in this case, a check should be made to ensure advanced graphics is
supported in the user's environment before calling this method.
|
drawArc, drawFocus, drawImage, drawImage, drawLine, drawOval, drawRectangle, drawString, drawText, drawText, drawText, drawTextLayout, fillArc, fillGradient, fillOval, fillRectangle, fillString, fillText, getAbsoluteScale, getLineAttributes, translatepublic SWTGraphics(GC gc)
gc - the GCprotected final void checkFill()
checkGC().protected final void checkGC()
protected final void checkPaint()
checkGC().protected final void checkText()
checkPaint() and checkFill().public void clipRect(Rectangle rect)
GraphicsclipRect in class Graphicsrect - the clip rectangleGraphics.clipRect(Rectangle)public void dispose()
Graphicsdispose in class GraphicsGraphics.dispose()public void drawArc(int x,
int y,
int width,
int height,
int offset,
int length)
GraphicsdrawArc in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightoffset - the start anglelength - the length of the arcGraphics.drawArc(int, int, int, int, int, int)public void drawFocus(int x,
int y,
int w,
int h)
GraphicsdrawFocus in class Graphicsx - the x coordinatey - the y coordinatew - the widthh - the heightGraphics.drawFocus(int, int, int, int)public void drawImage(Image srcImage, int x, int y)
GraphicsdrawImage in class GraphicssrcImage - the Imagex - the x coordinatey - the y coordinateGraphics.drawImage(Image, int, int)public void drawImage(Image srcImage, int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
GraphicsdrawImage in class GraphicssrcImage - the imagex1 - the x coordinate of the sourcey1 - the y coordinate of the sourcew1 - the width of the sourceh1 - the height of the sourcex2 - the x coordinate of the destinationy2 - the y coordinate of the destinationw2 - the width of the destinationh2 - the height of the destinationGraphics.drawImage(Image, int, int, int, int, int, int, int, int)public void drawLine(int x1,
int y1,
int x2,
int y2)
Graphics(x1,y1) and
(x2,y2) using the foreground color.drawLine in class Graphicsx1 - the x coordinate for the first pointy1 - the y coordinate for the first pointx2 - the x coordinate for the second pointy2 - the y coordinate for the second pointGraphics.drawLine(int, int, int, int)public void drawOval(int x,
int y,
int width,
int height)
GraphicsdrawOval in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightGraphics.drawOval(int, int, int, int)public void drawPath(Path path)
GC.getAdvanced().drawPath in class Graphicspath - the path to drawGraphics.drawPath(Path)public void drawPoint(int x,
int y)
Graphicsx, y).
Note that the current line attributes do not affect this operation.
drawPoint in class Graphicsx - the point's x coordinatey - the point's y coordinateGraphics.drawPoint(int, int)public void drawPolygon(int[] points)
GraphicsdrawPolygon in class Graphicspoints - the verticesGraphics.drawPolygon(int[])public void drawPolygon(PointList points)
GraphicsPointList
containing the vertices. The first and last points in the list will be
connected.drawPolygon in class Graphicspoints - the verticesGraphics.drawPolygon(PointList)public void drawPolyline(int[] points)
GraphicsdrawPolyline in class Graphicspoints - the verticesGraphics.drawPolyline(int[])public void drawPolyline(PointList points)
GraphicsPointList containing
the vertices. The first and last points in the list will not be
connected.drawPolyline in class Graphicspoints - the verticesGraphics.drawPolyline(PointList)public void drawRectangle(int x,
int y,
int width,
int height)
GraphicsdrawRectangle in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightGraphics.drawRectangle(int, int, int, int)public void drawRoundRectangle(Rectangle r, int arcWidth, int arcHeight)
GraphicsdrawRoundRectangle in class Graphicsr - the rectanglearcWidth - the arc widtharcHeight - the arc heightGraphics.drawRoundRectangle(Rectangle, int, int)public void drawString(java.lang.String s,
int x,
int y)
GraphicsdrawString in class Graphicss - the stringx - the x coordinatey - the y coordinateGraphics.drawString(String, int, int)public void drawText(java.lang.String s,
int x,
int y)
GraphicsdrawText in class Graphicss - the textx - the x coordinatey - the y coordinateGraphics.drawText(String, int, int)public void drawTextLayout(TextLayout layout, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
drawTextLayout in class Graphicslayout - the TextLayout being renderedx - the x locationy - the y locationselectionStart - the start of selectionselectionEnd - the end of selectionselectionForeground - the foreground selection colorselectionBackground - the background selection colorGraphics.drawTextLayout(TextLayout, int, int, int, int, Color,
Color)public void fillArc(int x,
int y,
int width,
int height,
int offset,
int length)
GraphicsfillArc in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightoffset - the start anglelength - the length of the arcGraphics.fillArc(int, int, int, int, int, int)public void fillGradient(int x,
int y,
int w,
int h,
boolean vertical)
Graphicstrue, the
gradient will go from top to bottom. Otherwise, it will go from left to
right. background color.fillGradient in class Graphicsx - the x coordinatey - the y coordinatew - the widthh - the heightvertical - whether the gradient should be verticalGraphics.fillGradient(int, int, int, int, boolean)public void fillOval(int x,
int y,
int width,
int height)
GraphicsfillOval in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightGraphics.fillOval(int, int, int, int)public void fillPath(Path path)
GC.getAdvanced().fillPath in class Graphicspath - the path to fillGraphics.fillPath(Path)public void fillPolygon(int[] points)
GraphicsfillPolygon in class Graphicspoints - the verticesGraphics.fillPolygon(int[])public void fillPolygon(PointList points)
GraphicsPointList
containing the vertices. The first and last points in the list will be
connected.fillPolygon in class Graphicspoints - the verticesGraphics.fillPolygon(PointList)public void fillRectangle(int x,
int y,
int width,
int height)
GraphicsfillRectangle in class Graphicsx - the x coordinatey - the y coordinatewidth - the widthheight - the heightGraphics.fillRectangle(int, int, int, int)public void fillRoundRectangle(Rectangle r, int arcWidth, int arcHeight)
GraphicsfillRoundRectangle in class Graphicsr - the rectanglearcWidth - the arc widtharcHeight - the arc heightGraphics.fillRoundRectangle(Rectangle, int, int)public void fillString(java.lang.String s,
int x,
int y)
GraphicsfillString in class Graphicss - the stringx - the x coordinatey - the y coordinateGraphics.fillString(String, int, int)public void fillText(java.lang.String s,
int x,
int y)
GraphicsfillText in class Graphicss - the textx - the x coordinatey - the y coordinateGraphics.fillText(String, int, int)public int getAlpha()
GraphicsgetAlpha in class GraphicsGraphics.getAlpha()public int getAntialias()
GraphicsSWT.DEFAULT, SWT.OFF or SWT.ON.
Note that this controls anti-aliasing for all non-text drawing
operations.getAntialias in class GraphicsGraphics.getAntialias()public boolean getAdvanced()
getAdvanced in class Graphicspublic Color getBackgroundColor()
GraphicsgetBackgroundColor in class GraphicsGraphics.getBackgroundColor()public Rectangle getClip(Rectangle rect)
GraphicsgetClip in class Graphicsrect - the rectangle to hold the clip regionGraphics.getClip(Rectangle)public int getFillRule()
GraphicsSWT.FILL_EVEN_ODD or SWT.FILL_WINDING.getFillRule in class GraphicsGraphics.getFillRule()public Font getFont()
GraphicsgetFont in class GraphicsGraphics.getFont()public FontMetrics getFontMetrics()
GraphicsgetFontMetrics in class GraphicsGraphics.getFontMetrics()public Color getForegroundColor()
GraphicsgetForegroundColor in class GraphicsGraphics.getForegroundColor()public int getInterpolation()
GraphicsgetInterpolation in class GraphicsGraphics.getInterpolation()public void getLineAttributes(LineAttributes lineAttributes)
public int getLineCap()
GraphicsgetLineCap in class GraphicsGraphics.getLineCap()public int getLineJoin()
GraphicsgetLineJoin in class GraphicsGraphics.getLineJoin()public int getLineStyle()
GraphicsgetLineStyle in class GraphicsGraphics.getLineStyle()public int getLineWidth()
GraphicsgetLineWidth in class GraphicsGraphics.getLineWidth()public float getLineWidthFloat()
GraphicsgetLineWidthFloat in class GraphicsLineAttributes.widthpublic float getLineMiterLimit()
GraphicsgetLineMiterLimit in class GraphicsLineAttributes.miterLimitpublic float[] getLineDash()
public float getLineDashOffset()
public int getTextAntialias()
GraphicsSWT.DEFAULT, SWT.OFF or SWT.ON.
Note that this controls anti-aliasing only for text drawing
operations.getTextAntialias in class GraphicsGraphics.getTextAntialias()public boolean getXORMode()
Graphicstrue if this graphics object should use XOR mode
with painting.getXORMode in class GraphicsGraphics.getXORMode()protected void init()
public void popState()
GraphicsGraphics.pushState() has previously been called) and restores the current
state to that popped state.popState in class GraphicsGraphics.popState()public void pushState()
GraphicspushState in class GraphicsGraphics.pushState()public void restoreState()
GraphicsrestoreState in class GraphicsGraphics.restoreState()protected void restoreState(org.eclipse.draw2d.SWTGraphics.State s)
s - the Statepublic void rotate(float degrees)
GC.getAdvanced().rotate in class Graphicsdegrees - the degrees to rotateGraphics.rotate(float)public void scale(double factor)
Graphicsscale in class Graphicsfactor - the scale factorGraphics.scale(double)public void scale(float horizontal,
float vertical)
GC.getAdvanced().scale in class Graphicshorizontal - the horizontal scaling factorvertical - the vertical scaling factorGraphics.scale(float, float)public void setAlpha(int alpha)
GC.getAdvanced().setAlpha in class Graphicsalpha - an alpha value (0-255)Graphics.setAlpha(int)public void setAntialias(int value)
GC.getAdvanced().setAntialias in class Graphicsvalue - the anti-alias valueGraphics.setAntialias(int)public void setAdvanced(boolean value)
GraphicssetAdvanced in class Graphicspublic void setBackgroundColor(Color color)
GraphicssetBackgroundColor in class Graphicscolor - the new background colorGraphics.setBackgroundColor(Color)public void setBackgroundPattern(Pattern pattern)
GraphicssetBackgroundPattern in class Graphicspattern - the background patternGraphics.setBackgroundPattern(Pattern)public void setClip(Path path)
GC.getAdvanced().setClip in class Graphicspath - the clipping pathGraphics.setClip(Path)public void clipPath(Path path)
restoreState()clipPath in class Graphicspath - the clip pathGraphics.clipPath(org.eclipse.swt.graphics.Path)public void setClip(Rectangle rect)
GraphicssetClip in class Graphicsrect - the new clip rectangleGraphics.setClip(Rectangle)public void setFillRule(int rule)
GraphicsSWT.FILL_EVEN_ODD or SWT.FILL_WINDING.setFillRule in class Graphicsrule - the fill ruleGraphics.setFillRule(int)public void setFont(Font f)
GraphicssetFont in class Graphicsf - the new fontGraphics.setFont(Font)public void setForegroundColor(Color color)
GraphicssetForegroundColor in class Graphicscolor - the new foreground colorGraphics.setForegroundColor(Color)public void setForegroundPattern(Pattern pattern)
GraphicssetForegroundPattern in class Graphicspattern - the foreground patternGraphics.setForegroundPattern(Pattern)public void setInterpolation(int interpolation)
GC.getAdvanced().setInterpolation in class Graphicsinterpolation - the interpolationGraphics.setInterpolation(int)public void setLineAttributes(LineAttributes lineAttributes)
GraphicssetLineAttributes in class GraphicslineAttributes - the line attributespublic void setLineCap(int value)
GraphicsSWT.CAP_FLAT, SWT.CAP_ROUND, or
SWT.CAP_SQUARE.setLineCap in class Graphicsvalue - the line capGraphics.setLineCap(int)public void setLineDash(int[] dashes)
GraphicsGraphics.pushState() and Graphics.popState().setLineDash in class Graphicsdashes - the pixel patternGraphics.setLineDash(int[])public void setLineDash(float[] value)
GraphicssetLineDash in class Graphicsvalue - public void setLineDashOffset(float value)
GraphicssetLineDashOffset in class Graphicspublic void setLineJoin(int value)
GraphicsSWT.JOIN_MITER, SWT.JOIN_ROUND, or
SWT.JOIN_BEVEL.setLineJoin in class Graphicsvalue - the join typeGraphics.setLineJoin(int)public void setLineStyle(int value)
GraphicsSWT.LINE_SOLID, SWT.LINE_DASH,
SWT.LINE_DOT, SWT.LINE_DASHDOT or
SWT.LINE_DASHDOTDOT.setLineStyle in class Graphicsvalue - the new styleGraphics.setLineStyle(int)public void setLineWidth(int width)
GraphicssetLineWidth in class Graphicswidth - the new widthGraphics.setLineWidth(int)public void setLineWidthFloat(float value)
GraphicssetLineWidthFloat in class Graphicsvalue - the new widthpublic void setLineMiterLimit(float value)
setLineMiterLimit in class Graphicspublic void setTextAntialias(int value)
GC.getAdvanced().setTextAntialias in class Graphicsvalue - the textual anti-alias settingGraphics.setTextAntialias(int)public void setXORMode(boolean xor)
GraphicssetXORMode in class Graphicsxor - the new XOR modeGraphics.setXORMode(boolean)public void shear(float horz,
float vert)
GC.getAdvanced().shear in class Graphicshorz - the horizontal shearing amountvert - the vertical shearing amountGraphics.shear(float, float)public void translate(int dx,
int dy)
GC.getAdvanced().translate in class Graphicsdx - the horizontal offsetdy - the vertical offsetGraphics.translate(int, int)public void translate(float dx,
float dy)
GC.getAdvanced().translate in class Graphicsdx - the horizontal offsetdy - the vertical offsetGraphics.translate(float, float)public static LineAttributes clone(LineAttributes src)
public static void copyLineAttributes(LineAttributes dest, LineAttributes src)
Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.