Eclipse Draw2d
2.1

org.eclipse.draw2d
Class Graphics

java.lang.Object
  |
  +--org.eclipse.draw2d.Graphics
Direct Known Subclasses:
ScaledGraphics, SWTGraphics

public abstract class Graphics
extends Object

The Graphics class allows you to draw to a surface. The drawXxx() methods that pertain to shapes draw an outline of the shape, whereas the fillXxx() methods fill in the shape. Also provides for drawing text, lines and images.


Field Summary
static int LINE_DASH
           
static int LINE_DASHDOT
           
static int LINE_DASHDOTDOT
           
static int LINE_DOT
           
static int LINE_SOLID
           
 
Constructor Summary
Graphics()
           
 
Method Summary
abstract  void clipRect(Rectangle r)
          Sets the clip region to the given rectangle.
abstract  void dispose()
          Disposes this Graphics object.
abstract  void drawArc(int x, int y, int w, int h, int offset, int length)
          Draws the outline of an arc located at (x,y) with width w and height h.
 void drawArc(Rectangle r, int offset, int length)
           
abstract  void drawFocus(int x, int y, int w, int h)
          Draws a focus rectangle.
 void drawFocus(Rectangle r)
           
abstract  void drawImage(Image srcImage, int x, int y)
          Draws the given Image at the location (x,y).
abstract  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 drawImage(Image srcImage, Point p)
           
 void drawImage(Image srcImage, Rectangle src, Rectangle dest)
           
abstract  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 drawLine(Point p1, Point p2)
           
abstract  void drawOval(int x, int y, int w, int h)
          Draws the outline of an ellipse that fits inside the rectangle with the given properties using the foreground color.
 void drawOval(Rectangle r)
           
abstract  void drawPolygon(PointList points)
          Draws a closed polygon defined by the given PointList containing the vertices.
abstract  void drawPolyline(PointList points)
          Draws a polyline defined by the given PointList containing the vertices.
abstract  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 drawRectangle(Rectangle r)
           
abstract  void drawRoundRectangle(Rectangle r, int arcWidth, int arcHeight)
          Draws a rectangle with rounded corners using the foreground color.
abstract  void drawString(String s, int x, int y)
          Draws the given string using the current font and foreground color.
 void drawString(String s, Point p)
           
abstract  void drawText(String s, int x, int y)
          Draws the given string using the current font and foreground color.
 void drawText(String s, Point p)
           
abstract  void fillArc(int x, int y, int w, int h, int offset, int length)
          Fills the interior of an arc located at (x,y) with width w and height h.
 void fillArc(Rectangle r, int offset, int length)
           
abstract  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 fillGradient(Rectangle r, boolean vertical)
           
abstract  void fillOval(int x, int y, int w, int h)
          Fills an ellipse that fits inside the rectangle with the given properties using the background color.
 void fillOval(Rectangle r)
           
abstract  void fillPolygon(PointList points)
          Fills a closed polygon defined by the given PointList containing the vertices.
abstract  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 fillRectangle(Rectangle r)
           
abstract  void fillRoundRectangle(Rectangle r, int arcWidth, int arcHeight)
          Fills a rectangle with rounded corners using the background color.
abstract  void fillString(String s, int x, int y)
          Draws the given string using the current font and foreground color.
 void fillString(String s, Point p)
           
abstract  void fillText(String s, int x, int y)
          Draws the given string using the current font and foreground color.
 void fillText(String s, Point p)
           
abstract  Color getBackgroundColor()
          Returns the background color used for filling.
abstract  Rectangle getClip(Rectangle rect)
          Modifies the given rectangle to match the clip region and returns that rectangle.
abstract  Font getFont()
          Returns the font used to draw and fill text.
abstract  FontMetrics getFontMetrics()
          Returns the font metrics for the current font.
abstract  Color getForegroundColor()
          Returns the foreground color used to draw lines and text.
abstract  int getLineStyle()
          Returns the line style.
abstract  int getLineWidth()
          Returns the current line width.
abstract  boolean getXORMode()
          Returns true if this graphics object should use XOR mode with painting.
abstract  void popState()
          Pops the previous state of this graphics object off the stack (if pushState() has previously been called) and restores the current state to that popped state.
abstract  void pushState()
          Pushes the current state of this graphics object onto a stack.
abstract  void restoreState()
          Restores the previous state of this graphics object.
abstract  void scale(double amount)
          Scales this graphics object by the given amount.
abstract  void setBackgroundColor(Color rgb)
          Sets the background color.
abstract  void setClip(Rectangle r)
          Sets the clip rectangle.
abstract  void setFont(Font f)
          Sets the font.
abstract  void setForegroundColor(Color rgb)
          Sets the foreground color.
abstract  void setLineStyle(int style)
          Sets the line style.
abstract  void setLineWidth(int width)
          Sets the line width.
abstract  void setXORMode(boolean b)
          Sets the XOR mode.
abstract  void translate(int dx, int dy)
          Translates this graphics object so that its origin is offset horizontally by dx and vertically by dy.
 void translate(Point pt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SOLID

public static final int LINE_SOLID
See Also:
SWT.LINE_SOLID, Constant Field Values

LINE_DASH

public static final int LINE_DASH
See Also:
SWT.LINE_DASH, Constant Field Values

LINE_DASHDOT

public static final int LINE_DASHDOT
See Also:
SWT.LINE_DASHDOT, Constant Field Values

LINE_DASHDOTDOT

public static final int LINE_DASHDOTDOT
See Also:
SWT.LINE_DASHDOTDOT, Constant Field Values

LINE_DOT

public static final int LINE_DOT
See Also:
SWT.LINE_DOT, Constant Field Values
Constructor Detail

Graphics

public Graphics()
Method Detail

clipRect

public abstract void clipRect(Rectangle r)
Sets the clip region to the given rectangle. Anything outside this rectangle will not be drawn.

Parameters:
r - the clip rectangle

dispose

public abstract void dispose()
Disposes this Graphics object.


drawArc

public final void drawArc(Rectangle r,
                          int offset,
                          int length)
See Also:
drawArc(int, int, int, int, int, int)

drawArc

public abstract void drawArc(int x,
                             int y,
                             int w,
                             int h,
                             int offset,
                             int length)
Draws the outline of an arc located at (x,y) with width w and height h. The starting angle of the arc (specified in degrees) is offset and length is the arc's angle (specified in degrees).

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height
offset - the start angle
length - the length of the arc

fillArc

public abstract void fillArc(int x,
                             int y,
                             int w,
                             int h,
                             int offset,
                             int length)
Fills the interior of an arc located at (x,y) with width w and height h. The starting angle of the arc (specified in degrees) is offset and length is the arc's angle (specified in degrees).

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height
offset - the start angle
length - the length of the arc

fillArc

public final void fillArc(Rectangle r,
                          int offset,
                          int length)
See Also:
fillArc(int, int, int, int, int, int)

fillGradient

public final void fillGradient(Rectangle r,
                               boolean vertical)
See Also:
fillGradient(int, int, int, int, boolean)

fillGradient

public abstract 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. If vertical is true, the gradient will go from top to bottom. Otherwise, it will go from left to right. background color.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height
vertical - whether the gradient should be vertical

drawFocus

public final void drawFocus(Rectangle r)
See Also:
drawFocus(int, int, int, int)

drawFocus

public abstract void drawFocus(int x,
                               int y,
                               int w,
                               int h)
Draws a focus rectangle.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height

drawImage

public final void drawImage(Image srcImage,
                            Point p)
See Also:
drawImage(Image, int, int)

drawImage

public abstract void drawImage(Image srcImage,
                               int x,
                               int y)
Draws the given Image at the location (x,y).

Parameters:
srcImage - the Image
x - the x coordinate
y - the y coordinate

drawImage

public final void drawImage(Image srcImage,
                            Rectangle src,
                            Rectangle dest)
See Also:
drawImage(Image, int, int, int, int, int, int, int, int)

drawImage

public abstract 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. The section of the image bounded by the rectangle (x1,y1,w1,h1) is copied to the section of the canvas bounded by the rectangle (x2,y2,w2,h2). If these two sizes are different, scaling will occur.

Parameters:
srcImage - the image
x1 - the x coordinate of the source
y1 - the y coordinate of the source
w1 - the width of the source
h1 - the height of the source
x2 - the x coordinate of the destination
y2 - the y coordinate of the destination
w2 - the width of the destination
h2 - the height of the destination

drawLine

public final void drawLine(Point p1,
                           Point p2)
See Also:
drawLine(int, int, int, int)

drawLine

public abstract 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.

Parameters:
x1 - the x coordinate for the first point
y1 - the y coordinate for the first point
x2 - the x coordinate for the second point
y2 - the y coordinate for the second point

drawOval

public final void drawOval(Rectangle r)
See Also:
drawOval(int, int, int, int)

drawOval

public abstract void drawOval(int x,
                              int y,
                              int w,
                              int h)
Draws the outline of an ellipse that fits inside the rectangle with the given properties using the foreground color.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height

fillOval

public final void fillOval(Rectangle r)
See Also:
fillOval(int, int, int, int)

fillOval

public abstract void fillOval(int x,
                              int y,
                              int w,
                              int h)
Fills an ellipse that fits inside the rectangle with the given properties using the background color.

Parameters:
x - the x coordinate
y - the y coordinate
w - the width
h - the height

drawPolygon

public abstract void drawPolygon(PointList points)
Draws a closed polygon defined by the given PointList containing the vertices. The first and last points in the list will be connected.

Parameters:
points - the vertices

fillPolygon

public abstract void fillPolygon(PointList points)
Fills a closed polygon defined by the given PointList containing the vertices. The first and last points in the list will be connected.

Parameters:
points - the vertices

drawPolyline

public abstract void drawPolyline(PointList points)
Draws a polyline defined by the given PointList containing the vertices. The first and last points in the list will not be connected.

Parameters:
points - the vertices

drawRectangle

public final void drawRectangle(Rectangle r)
See Also:
drawRectangle(int, int, int, int)

drawRectangle

public abstract 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.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width
height - the height

fillRectangle

public final void fillRectangle(Rectangle r)
See Also:
fillRectangle(int, int, int, int)

fillRectangle

public abstract 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.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width
height - the height

drawRoundRectangle

public abstract void drawRoundRectangle(Rectangle r,
                                        int arcWidth,
                                        int arcHeight)
Draws a rectangle with rounded corners using the foreground color. arcWidth and arcHeight represent the horizontal and vertical diameter of the corners.

Parameters:
r - the rectangle
arcWidth - the arc width
arcHeight - the arc height

fillRoundRectangle

public abstract void fillRoundRectangle(Rectangle r,
                                        int arcWidth,
                                        int arcHeight)
Fills a rectangle with rounded corners using the background color. arcWidth and arcHeight represent the horizontal and vertical diameter of the corners.

Parameters:
r - the rectangle
arcWidth - the arc width
arcHeight - the arc height

drawText

public abstract void drawText(String s,
                              int x,
                              int y)
Draws the given string using the current font and foreground color. Tab expansion and carriage return processing are performed. The background of the text will be transparent.

Parameters:
s - the text
x - the x coordinate
y - the y coordinate

drawString

public abstract void drawString(String s,
                                int x,
                                int y)
Draws the given string using the current font and foreground color. No tab expansion or carriage return processing will be performed. The background of the string will be transparent.

Parameters:
s - the string
x - the x coordinate
y - the y coordinate

drawString

public final void drawString(String s,
                             Point p)
See Also:
drawString(String, int, int)

drawText

public final void drawText(String s,
                           Point p)
See Also:
drawText(String, int, int)

fillString

public final void fillString(String s,
                             Point p)
See Also:
fillString(String, int, int)

fillString

public abstract void fillString(String s,
                                int x,
                                int y)
Draws the given string using the current font and foreground color. No tab expansion or carriage return processing will be performed. The background of the string will be filled with the current background color.

Parameters:
s - the string
x - the x coordinate
y - the y coordinate

fillText

public final void fillText(String s,
                           Point p)
See Also:
fillText(String, int, int)

fillText

public abstract void fillText(String s,
                              int x,
                              int y)
Draws the given string using the current font and foreground color. Tab expansion and carriage return processing are performed. The background of the text will be filled with the current background color.

Parameters:
s - the text
x - the x coordinate
y - the y coordinate

getBackgroundColor

public abstract Color getBackgroundColor()
Returns the background color used for filling.

Returns:
the background color

getClip

public abstract Rectangle getClip(Rectangle rect)
Modifies the given rectangle to match the clip region and returns that rectangle.

Parameters:
rect - the rectangle to hold the clip region
Returns:
the clip rectangle

getFont

public abstract Font getFont()
Returns the font used to draw and fill text.

Returns:
the font

getFontMetrics

public abstract FontMetrics getFontMetrics()
Returns the font metrics for the current font.

Returns:
the font metrics

getForegroundColor

public abstract Color getForegroundColor()
Returns the foreground color used to draw lines and text.

Returns:
the foreground color

getLineStyle

public abstract int getLineStyle()
Returns the line style.

Returns:
the line style

getLineWidth

public abstract int getLineWidth()
Returns the current line width.

Returns:
the line width

getXORMode

public abstract boolean getXORMode()
Returns true if this graphics object should use XOR mode with painting.

Returns:
whether XOR mode is turned on

popState

public abstract void popState()
Pops the previous state of this graphics object off the stack (if pushState() has previously been called) and restores the current state to that popped state.


pushState

public abstract void pushState()
Pushes the current state of this graphics object onto a stack.


restoreState

public abstract void restoreState()
Restores the previous state of this graphics object.


scale

public abstract void scale(double amount)
Scales this graphics object by the given amount.

Parameters:
amount - the scale factor

setBackgroundColor

public abstract void setBackgroundColor(Color rgb)
Sets the background color.

Parameters:
rgb - the new background color

setClip

public abstract void setClip(Rectangle r)
Sets the clip rectangle. Painting will not occur outside this area.

Parameters:
r - the new clip rectangle

setFont

public abstract void setFont(Font f)
Sets the font.

Parameters:
f - the new font

setForegroundColor

public abstract void setForegroundColor(Color rgb)
Sets the foreground color.

Parameters:
rgb - the new foreground color

setLineStyle

public abstract void setLineStyle(int style)
Sets the line style.

Parameters:
style - the new style

setLineWidth

public abstract void setLineWidth(int width)
Sets the line width.

Parameters:
width - the new width

setXORMode

public abstract void setXORMode(boolean b)
Sets the XOR mode.

Parameters:
b - the new XOR mode

translate

public final void translate(Point pt)
See Also:
translate(int, int)

translate

public abstract void translate(int dx,
                               int dy)
Translates this graphics object so that its origin is offset horizontally by dx and vertically by dy.

Parameters:
dx - the horizontal offset
dy - the vertical offset

Eclipse Draw2d
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.