|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.swt.graphics.GC
Class GC
is where all of the drawing capabilities that are
supported by SWT are located. Instances are used to draw on either an
Image
, a Control
, or directly on a Display
.
The SWT drawing coordinate system is the two-dimensional space with the origin (0,0) at the top left corner of the drawing area and with (x,y) values increasing to the right and downward respectively.
Application code must explicitly invoke the GC.dispose()
method to release the operating system resources managed by each instance
when those instances are no longer required. This is particularly
important on Windows95 and Windows98 where the operating system has a limited
number of device contexts available.
Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
PaintEvent
Constructor Summary | |
GC(Drawable drawable)
Constructs a new instance of this class which has been configured to draw on the specified drawable. |
|
GC(Drawable drawable,
int style)
Constructs a new instance of this class which has been configured to draw on the specified drawable. |
Method Summary | |
void |
copyArea(Image image,
int x,
int y)
Copies a rectangular area of the receiver at the specified position into the image, which must be of type SWT.BITMAP . |
void |
copyArea(int srcX,
int srcY,
int width,
int height,
int destX,
int destY)
Copies a rectangular area of the receiver at the source position onto the receiver at the destination position. |
void |
dispose()
Disposes of the operating system resources associated with the graphics context. |
void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws the outline of a circular or elliptical arc within the specified rectangular area. |
void |
drawFocus(int x,
int y,
int width,
int height)
Draws a rectangle, based on the specified arguments, which has the appearance of the platform's focus rectangle if the platform supports such a notion, and otherwise draws a simple rectangle in the receiver's foreground color. |
void |
drawImage(Image image,
int x,
int y)
Draws the given image in the receiver at the specified coordinates. |
void |
drawImage(Image image,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
int destX,
int destY,
int destWidth,
int destHeight)
Copies a rectangular area from the source image into a (potentially different sized) rectangular area in the receiver. |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line, using the foreground color, between the points ( x1 , y1 ) and (x2 , y2 ). |
void |
drawOval(int x,
int y,
int width,
int height)
Draws the outline of an oval, using the foreground color, within the specified rectangular area. |
void |
drawPoint(int x,
int y)
Draws a pixel, using the foreground color, at the specified point ( x , y ). |
void |
drawPolygon(int[] pointArray)
Draws the closed polygon which is defined by the specified array of integer coordinates, using the receiver's foreground color. |
void |
drawPolyline(int[] pointArray)
Draws the polyline which is defined by the specified array of integer coordinates, using the receiver's foreground color. |
void |
drawRectangle(int x,
int y,
int width,
int height)
Draws the outline of the rectangle specified by the arguments, using the receiver's foreground color. |
void |
drawRectangle(Rectangle rect)
Draws the outline of the specified rectangle, using the receiver's foreground color. |
void |
drawRoundRectangle(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws the outline of the round-cornered rectangle specified by the arguments, using the receiver's foreground color. |
void |
drawString(java.lang.String string,
int x,
int y)
Draws the given string, using the receiver's current font and foreground color. |
void |
drawString(java.lang.String string,
int x,
int y,
boolean isTransparent)
Draws the given string, using the receiver's current font and foreground color. |
void |
drawText(java.lang.String string,
int x,
int y)
Draws the given string, using the receiver's current font and foreground color. |
void |
drawText(java.lang.String string,
int x,
int y,
int flags)
Draws the given string, using the receiver's current font and foreground color. |
boolean |
equals(java.lang.Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison. |
void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Fills the interior of a circular or elliptical arc within the specified rectangular area, with the receiver's background color. |
void |
fillGradientRectangle(int x,
int y,
int width,
int height,
boolean vertical)
Fills the interior of the specified rectangle with a gradient sweeping from left to right or top to bottom progressing from the receiver's foreground color to its background color. |
void |
fillOval(int x,
int y,
int width,
int height)
Fills the interior of an oval, within the specified rectangular area, with the receiver's background color. |
void |
fillPolygon(int[] pointArray)
Fills the interior of the closed polygon which is defined by the specified array of integer coordinates, using the receiver's background color. |
void |
fillRectangle(int x,
int y,
int width,
int height)
Fills the interior of the rectangle specified by the arguments, using the receiver's background color. |
void |
fillRectangle(Rectangle rect)
Fills the interior of the specified rectangle, using the receiver's background color. |
void |
fillRoundRectangle(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Fills the interior of the round-cornered rectangle specified by the arguments, using the receiver's background color. |
int |
getAdvanceWidth(char ch)
Returns the advance width of the specified character in the font which is currently selected into the receiver. |
int |
getAlpha()
Returns the receiver's alpha value. |
Color |
getBackground()
Returns the background color. |
int |
getCharWidth(char ch)
Returns the width of the specified character in the font selected into the receiver. |
Rectangle |
getClipping()
Returns the bounding rectangle of the receiver's clipping region. |
Font |
getFont()
Returns the font currently being used by the receiver to draw and measure text. |
FontMetrics |
getFontMetrics()
Returns a FontMetrics which contains information about the font currently being used by the receiver to draw and measure text. |
Color |
getForeground()
Returns the receiver's foreground color. |
int |
getLineStyle()
Returns the receiver's line style, which will be one of the constants SWT.LINE_SOLID , SWT.LINE_DASH ,
SWT.LINE_DOT , SWT.LINE_DASHDOT or
SWT.LINE_DASHDOTDOT . |
int |
getLineWidth()
Returns the width that will be used when drawing lines for all of the figure drawing operations (that is, drawLine , drawRectangle ,
drawPolyline , and so forth. |
int |
getStyle()
Returns the receiver's style information. |
boolean |
getXORMode()
Returns true if this GC is drawing in the mode
where the resulting color in the destination is the
exclusive or of the color values in the source
and the destination, and false if it is
drawing in the mode where the destination color is being
replaced with the source color value. |
int |
hashCode()
Returns an integer hash code for the receiver. |
boolean |
isClipped()
Returns true if the receiver has a clipping
region set into it, and false otherwise. |
boolean |
isDisposed()
Returns true if the GC has been disposed,
and false otherwise. |
void |
setAlpha(int alpha)
Sets the receiver's alpha value. |
void |
setBackground(Color color)
Sets the background color. |
void |
setClipping(int x,
int y,
int width,
int height)
Sets the area of the receiver which can be changed by drawing operations to the rectangular area specified by the arguments. |
void |
setClipping(Rectangle rect)
Sets the area of the receiver which can be changed by drawing operations to the rectangular area specified by the argument. |
void |
setFont(Font font)
Sets the font which will be used by the receiver to draw and measure text to the argument. |
void |
setForeground(Color color)
Sets the foreground color. |
void |
setLineStyle(int lineStyle)
Sets the receiver's 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 lineWidth)
Sets the width that will be used when drawing lines for all of the figure drawing operations (that is, drawLine , drawRectangle ,
drawPolyline , and so forth. |
void |
setXORMode(boolean xor)
If the argument is true , puts the receiver
in a drawing mode where the resulting color in the destination
is the exclusive or of the color values in the source
and the destination, and if the argument is false ,
puts the receiver in a drawing mode where the destination color
is replaced with the source color value. |
Point |
stringExtent(java.lang.String string)
Returns the extent of the given string. |
Point |
textExtent(java.lang.String string)
Returns the extent of the given string. |
Point |
textExtent(java.lang.String string,
int flags)
Returns the extent of the given string. |
java.lang.String |
toString()
Returns a string containing a concise, human-readable description of the receiver. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public GC(Drawable drawable)
You must dispose the graphics context when it is no longer required.
drawable
- the drawable to draw on
java.lang.IllegalArgumentException
- SWTError
- public GC(Drawable drawable, int style)
You must dispose the graphics context when it is no longer required.
drawable
- the drawable to draw onstyle
- the style of GC to construct
java.lang.IllegalArgumentException
- SWTError
- Method Detail |
public void copyArea(Image image, int x, int y)
SWT.BITMAP
.
image
- the image to copy intox
- the x coordinate in the receiver of the area to be copiedy
- the y coordinate in the receiver of the area to be copied
java.lang.IllegalArgumentException
- SWTException
- public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY)
srcX
- the x coordinate in the receiver of the area to be copiedsrcY
- the y coordinate in the receiver of the area to be copiedwidth
- the width of the area to copyheight
- the height of the area to copydestX
- the x coordinate in the receiver of the area to copy todestY
- the y coordinate in the receiver of the area to copy to
SWTException
- public void dispose()
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
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.
x
- the x coordinate of the upper-left corner of the arc to be drawny
- the y coordinate of the upper-left corner of the arc to be drawnwidth
- the width of the arc to be drawnheight
- the height of the arc to be drawnstartAngle
- the beginning anglearcAngle
- the angular extent of the arc, relative to the start angle
SWTException
- public void drawFocus(int x, int y, int width, int height)
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle
SWTException
- drawRectangle(int, int, int, int)
public void drawImage(Image image, int x, int y)
image
- the image to drawx
- the x coordinate of where to drawy
- the y coordinate of where to draw
java.lang.IllegalArgumentException
- SWTException
- SWTError
- public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight)
image
- the source imagesrcX
- the x coordinate in the source image to copy fromsrcY
- the y coordinate in the source image to copy fromsrcWidth
- the width in pixels to copy from the sourcesrcHeight
- the height in pixels to copy from the sourcedestX
- the x coordinate in the destination to copy todestY
- the y coordinate in the destination to copy todestWidth
- the width in pixels of the destination rectangledestHeight
- the height in pixels of the destination rectangle
java.lang.IllegalArgumentException
- SWTException
- SWTError
- public void drawLine(int x1, int y1, int x2, int y2)
x1
, y1
) and (x2
, y2
).
x1
- the first point's x coordinatey1
- the first point's y coordinatex2
- the second point's x coordinatey2
- the second point's y coordinate
SWTException
- public void drawOval(int x, int y, int width, int height)
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.
x
- the x coordinate of the upper left corner of the oval to be drawny
- the y coordinate of the upper left corner of the oval to be drawnwidth
- the width of the oval to be drawnheight
- the height of the oval to be drawn
SWTException
- public void drawPoint(int x, int y)
x
, y
).
Note that the receiver's line attributes do not affect this operation.
x
- the point's x coordinatey
- the point's y coordinate
SWTException
- public void drawPolygon(int[] pointArray)
pointArray
- an array of alternating x and y values which are the vertices of the polygon
java.lang.IllegalArgumentException
- SWTException
- public void drawPolyline(int[] pointArray)
pointArray
- an array of alternating x and y values which are the corners of the polyline
java.lang.IllegalArgumentException
- SWTException
- public void drawRectangle(int x, int y, int width, int height)
x
and x + width
.
The top and bottom edges are at y
and y + height
.
x
- the x coordinate of the rectangle to be drawny
- the y coordinate of the rectangle to be drawnwidth
- the width of the rectangle to be drawnheight
- the height of the rectangle to be drawn
SWTException
- public void drawRectangle(Rectangle rect)
rect.x
and rect.x + rect.width
. The top
and bottom edges are at rect.y
and
rect.y + rect.height
.
rect
- the rectangle to draw
java.lang.IllegalArgumentException
- SWTException
- public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
and x + width
.
The top and bottom edges are at y
and y + height
.
The roundness of the corners is specified by the
arcWidth
and arcHeight
arguments, which
are respectively the width and height of the ellipse used to draw
the corners.
x
- the x coordinate of the rectangle to be drawny
- the y coordinate of the rectangle to be drawnwidth
- the width of the rectangle to be drawnheight
- the height of the rectangle to be drawnarcWidth
- the width of the arcarcHeight
- the height of the arc
SWTException
- public void drawString(java.lang.String string, int x, int y)
string
- the string to be drawnx
- the x coordinate of the top left corner of the rectangular area where the string is to be drawny
- the y coordinate of the top left corner of the rectangular area where the string is to be drawn
java.lang.IllegalArgumentException
- SWTException
- public void drawString(java.lang.String string, int x, int y, boolean isTransparent)
isTransparent
is true
,
then the background of the rectangular area where the string is being
drawn will not be modified, otherwise it will be filled with the
receiver's background color.
string
- the string to be drawnx
- the x coordinate of the top left corner of the rectangular area where the string is to be drawny
- the y coordinate of the top left corner of the rectangular area where the string is to be drawnisTransparent
- if true
the background will be transparent, otherwise it will be opaque
java.lang.IllegalArgumentException
- SWTException
- public void drawText(java.lang.String string, int x, int y)
string
- the string to be drawnx
- the x coordinate of the top left corner of the rectangular area where the text is to be drawny
- the y coordinate of the top left corner of the rectangular area where the text is to be drawn
java.lang.IllegalArgumentException
- SWTException
- public void drawText(java.lang.String string, int x, int y, int flags)
flags
includes DRAW_TRANSPARENT
,
then the background of the rectangular area where the text is being
drawn will not be modified, otherwise it will be filled with the
receiver's background color.
The parameter flags
may be a combination of:
string
- the string to be drawnx
- the x coordinate of the top left corner of the rectangular area where the text is to be drawny
- the y coordinate of the top left corner of the rectangular area where the text is to be drawnflags
- the flags specifing how to process the text
java.lang.IllegalArgumentException
- SWTException
- public boolean equals(java.lang.Object object)
object
- the object to compare with this object
true
if the object is the same as this object and false
otherwisehashCode()
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
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.
x
- the x coordinate of the upper-left corner of the arc to be filledy
- the y coordinate of the upper-left corner of the arc to be filledwidth
- the width of the arc to be filledheight
- the height of the arc to be filledstartAngle
- the beginning anglearcAngle
- the angular extent of the arc, relative to the start angle
SWTException
- drawArc(int, int, int, int, int, int)
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical)
x
- the x coordinate of the rectangle to be filledy
- the y coordinate of the rectangle to be filledwidth
- the width of the rectangle to be filled, may be negative
(inverts direction of gradient if horizontal)height
- the height of the rectangle to be filled, may be negative
(inverts direction of gradient if vertical)vertical
- if true sweeps from top to bottom, else
sweeps from left to right
SWTException
- drawRectangle(int, int, int, int)
public void fillOval(int x, int y, int width, int height)
x
- the x coordinate of the upper left corner of the oval to be filledy
- the y coordinate of the upper left corner of the oval to be filledwidth
- the width of the oval to be filledheight
- the height of the oval to be filled
SWTException
- drawOval(int, int, int, int)
public void fillPolygon(int[] pointArray)
pointArray
- an array of alternating x and y values which are the vertices of the polygon
java.lang.IllegalArgumentException
- SWTException
- drawPolygon(int[])
public void fillRectangle(int x, int y, int width, int height)
x
- the x coordinate of the rectangle to be filledy
- the y coordinate of the rectangle to be filledwidth
- the width of the rectangle to be filledheight
- the height of the rectangle to be filled
SWTException
- drawRectangle(int, int, int, int)
public void fillRectangle(Rectangle rect)
rect
- the rectangle to be filled
java.lang.IllegalArgumentException
- SWTException
- drawRectangle(int, int, int, int)
public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
- the x coordinate of the rectangle to be filledy
- the y coordinate of the rectangle to be filledwidth
- the width of the rectangle to be filledheight
- the height of the rectangle to be filledarcWidth
- the width of the arcarcHeight
- the height of the arc
SWTException
- drawRoundRectangle(int, int, int, int, int, int)
public int getAdvanceWidth(char ch)
The advance width is defined as the horizontal distance the cursor should move after printing the character in the selected font.
ch
- the character to measure
SWTException
- public int getAlpha()
SWTException
- public Color getBackground()
SWTException
- public int getCharWidth(char ch)
The width is defined as the space taken up by the actual character, not including the leading and tailing whitespace or overhang.
ch
- the character to measure
SWTException
- public Rectangle getClipping()
SWTException
- public Font getFont()
SWTException
- public FontMetrics getFontMetrics()
SWTException
- public Color getForeground()
SWTException
- public int getLineStyle()
SWT.LINE_SOLID
, SWT.LINE_DASH
,
SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
SWT.LINE_DASHDOTDOT
.
SWTException
- public int getLineWidth()
drawLine
, drawRectangle
,
drawPolyline
, and so forth.
SWTException
- public int getStyle()
Note that the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles.
SWTException
- public boolean getXORMode()
true
if this GC is drawing in the mode
where the resulting color in the destination is the
exclusive or of the color values in the source
and the destination, and false
if it is
drawing in the mode where the destination color is being
replaced with the source color value.
true
true if the receiver is in XOR mode, and false otherwise
SWTException
- public int hashCode()
true
when passed to
equals
must return the same value for this
method.
SWTException
- equals(java.lang.Object)
public boolean isClipped()
true
if the receiver has a clipping
region set into it, and false
otherwise.
If this method returns false, the receiver will draw on all
available space in the destination. If it returns true,
it will draw only in the area that is covered by the region
that can be accessed with getClipping(region)
.
true
if the GC has a clipping region, and false
otherwise
SWTException
- public boolean isDisposed()
true
if the GC has been disposed,
and false
otherwise.
This method gets the dispose state for the GC. When a GC has been disposed, it is an error to invoke any other method using the GC.
true
when the GC is disposed and false
otherwisepublic void setAlpha(int alpha)
alpha
- the alpha value
SWTException
- public void setBackground(Color color)
color
- the new background color for the receiver
java.lang.IllegalArgumentException
- SWTException
- public void setClipping(int x, int y, int width, int height)
x
- the x coordinate of the clipping rectangley
- the y coordinate of the clipping rectanglewidth
- the width of the clipping rectangleheight
- the height of the clipping rectangle
SWTException
- public void setClipping(Rectangle rect)
rect
- the clipping rectangle
SWTException
- public void setFont(Font font)
font
- the new font for the receiver, or null to indicate a default font
java.lang.IllegalArgumentException
- SWTException
- public void setForeground(Color color)
color
- the new foreground color for the receiver
java.lang.IllegalArgumentException
- SWTException
- public void setLineStyle(int lineStyle)
SWT.LINE_SOLID
, SWT.LINE_DASH
,
SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
SWT.LINE_DASHDOTDOT
.
lineStyle
- the style to be used for drawing lines
SWTException
- public void setLineWidth(int lineWidth)
drawLine
, drawRectangle
,
drawPolyline
, and so forth.
Note that line width of zero is used as a hint to indicate that the fastest possible line drawing algorithms should be used. This means that the output may be different from line width one.
lineWidth
- the width of a line
SWTException
- public void setXORMode(boolean xor)
true
, puts the receiver
in a drawing mode where the resulting color in the destination
is the exclusive or of the color values in the source
and the destination, and if the argument is false
,
puts the receiver in a drawing mode where the destination color
is replaced with the source color value.
xor
- if true
, then xor mode is used, otherwise source copy mode is used
SWTException
- public Point stringExtent(java.lang.String string)
The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font (in this case, the current font in the receiver).
string
- the string to measure
java.lang.IllegalArgumentException
- SWTException
- public Point textExtent(java.lang.String string)
The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font (in this case, the current font in the receiver).
string
- the string to measure
java.lang.IllegalArgumentException
- SWTException
- public Point textExtent(java.lang.String string, int flags)
The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font (in this case, the current font in the receiver).
string
- the string to measureflags
- the flags specifing how to process the text
java.lang.IllegalArgumentException
- SWTException
- public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |