Class Graphics


  extended by Object
      extended by Graphics

public class Graphics
extends Object

Provides simple 2D geometric rendering capability. This is to be used with Script.paint(Component, Graphics, Style, int, int) and PaintCallback.paint(Component, Graphics, Style, int, int). A paint callback function can be given as an argument to the constructor Canvas.Canvas(Style, PaintCallback) of Canvas. The Graphics instance appears as an argument for the paint functions and can be used for drawing custom graphics there.


Method Summary
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws a circular or elliptical arc covering the specified rectangle.
 void drawImage(Image img, int x, int y, int anchor)
          Draws the specified image by using the anchor point.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line between the coordinates (x1,y1) and (x2,y2) using the current color and stroke style.
 void drawRect(int x, int y, int width, int height)
          Draws the outline of the specified rectangle using the current color and stroke style.
 void drawString(String str, int x, int y, int anchor)
          Draws the specified String using the current font and color.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Fills a circular or elliptical arc covering the specified rectangle.
 void fillRect(int x, int y, int width, int height)
          Fills the specified rectangle with the current color.
 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
          Fills the specified triangle will the current color.
  int, int, int, int getClip()
          Returns the current clipping area.
 int getColor()
          Gets the current color.
 Font getFont()
          Gets the current font used by text drawing operations.
  int, int getTranslate()
          Returns the current translation origin.
 void setClip(int x, int y, int width, int height, boolean absolute)
          Sets the current clip to the rectangle specified by the given coordinates.
 void setColor(int color)
          Sets the current color to the specified RGB values.
 void setFont(Font font)
          Sets the font for all subsequent text rendering operations.
 void translate(int x, int y)
          Translates the origin of the graphics context to the point (x, y) in the current coordinate system.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getColor

public int getColor()
Gets the current color.

Returns:
an integer in form 0x00RRGGBB
See Also:
setColor(int)

setColor

public void setColor(int color)
Sets the current color to the specified RGB values. All subsequent rendering operations will use this specified color. The RGB value passed in is interpreted with the least significant eight bits giving the blue component, the next eight more significant bits giving the green component, and the next eight more significant bits giving the red component. That is to say, the color component is specified in the form of 0x00RRGGBB. The high order byte of this value is ignored.

Parameters:
color - the color being set
See Also:
getColor()

getFont

public Font getFont()
Gets the current font used by text drawing operations.

Returns:
current font
See Also:
setFont(Font)

setFont

public void setFont(Font font)
Sets the font for all subsequent text rendering operations.

Parameters:
font - the specified font
See Also:
getFont(), drawString(String, int, int, int)

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line between the coordinates (x1,y1) and (x2,y2) using the current color and stroke style.

Parameters:
x1 - the x coordinate of the start of the line
y1 - the y coordinate of the start of the line
x2 - the x coordinate of the end of the line
y2 - the y coordinate of the end of the line

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draws the outline of the specified rectangle using the current color and stroke style. The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width or height is less than zero, nothing is drawn.

Parameters:
x - the x coordinate of the rectangle to be drawn
y - the y coordinate of the rectangle to be drawn
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn
See Also:
fillRect(int, int, int, int)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fills the specified rectangle with the current color. If either width or height is zero or less, nothing is drawn.

Parameters:
x - the x coordinate of the rectangle to be filled
y - the y coordinate of the rectangle to be filled
width - the width of the rectangle to be filled
height - the height of the rectangle to be filled
See Also:
drawRect(int, int, int, int)

fillTriangle

public void fillTriangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         int x3,
                         int y3)
Fills the specified triangle will the current color. The lines connecting each pair of points are included in the filled triangle.

Parameters:
x1 - the x coordinate of the first vertex of the triangle
y1 - the y coordinate of the first vertex of the triangle
x2 - the x coordinate of the second vertex of the triangle
y2 - the y coordinate of the second vertex of the triangle
x3 - the x coordinate of the third vertex of the triangle
y3 - the y coordinate of the third vertex of the triangle

drawImage

public void drawImage(Image img,
                      int x,
                      int y,
                      int anchor)
Draws the specified image by using the anchor point. The image can be drawn in different positions relative to the anchor point by passing the appropriate position constants.

Parameters:
img - the specified image to be drawn
x - the x coordinate of the anchor point
y - the y coordinate of the anchor point
anchor - the anchor point for positioning the image

drawString

public void drawString(String str,
                       int x,
                       int y,
                       int anchor)
Draws the specified String using the current font and color. The x,y position is the position of the anchor point.

Parameters:
str - the String to be drawn
x - the x coordinate of the anchor point
y - the y coordinate of the anchor point
anchor - the anchor point for positioning the text

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Fills a circular or elliptical arc covering the specified rectangle.

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

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draws a circular or elliptical arc covering the specified rectangle.

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

translate

public void translate(int x,
                      int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. All coordinates used in subsequent rendering operations on this graphics context will be relative to this new origin. The effect of translate() calls are cumulative. The application can set an absolute origin (ax, ay) using the following technique:
 int x, int y = g.getTranslate();
 g.translate(ax - x, ay - y);
 
x - the x coordinate of the new translation origin y - the y coordinate of the new translation origin

Since:
2.0.0

getTranslate

public   int, int getTranslate()
Returns the current translation origin.

Returns:
(int translateX, int translateY) tuple
Since:
2.0.0

getClip

public   int, int, int, int getClip()
Returns the current clipping area.

Returns:
Tuple containg (int clipX, int clipY, int clipWidth, int clipHeight).
Since:
2.0.0

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height,
                    boolean absolute)
Sets the current clip to the rectangle specified by the given coordinates. If the absolute is false the the current clip is intesected with the specified rectangle. Rendering operations have no effect outside of the clipping area.

Parameters:
x - the x coordinate of the rectangle to intersect the clip with
y - the y coordinate of the rectangle to intersect the clip with
width - the width of the rectangle to intersect the clip with
height - the height of the rectangle to intersect the clip with
absolute - If true sets new clip, otherwise intersects with current clip
Since:
2.0.0