Java DTV API 1.3
18-Nov-2009

com.sun.dtv.lwuit
Class Graphics

java.lang.Object
  extended by com.sun.dtv.lwuit.Graphics

public final class Graphics
extends Object

Abstracts the underlying platform graphics context thus allowing us to achieve portability between MIDP devices and CDC devices. This abstraction simplifies and unifies the Graphics implementations of various platforms. For usage of LWUIT within the DTV specification, a Graphics object always wraps an instance of java.awt.Graphics2D. The access to the wrapped object is encouraged only if this is really necessary in order to handle a specific LWUIT vs. AWT integration issue. It should not be used for ordinary tasks.


Constructor Summary
Graphics(Graphics2D g)
          Create a LWUIT Graphics object using a Graphics instance of the underlying Graphics library to be wrapped.
 
Method Summary
 void clearRect(int x, int y, int width, int height)
          Clears the specified rectangle by filling it with the background color of the current drawing surface.
 void clipRect(int x, int y, int width, int height)
          Clips the given rectangle by intersecting with the current clipping region, this method can thus only shrink the clipping region and never increase it.
 void copyArea(int x, int y, int width, int height, int dx, int dy)
          Copies an area of the component by a distance specified by the dx and dy parameters.
 void darkerColor(int factor)
          Makes the current color slightly darker, this is useful for many visual effects.
 void draw3DRect(int x, int y, int width, int height, boolean raised)
          Draws a 3D highlighted outline of the specified rectangle.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws a circular or elliptical arc based on the given angles and bounding box.
 void drawBytes(byte[] data, int offset, int length, int x, int y)
          Draws the text given by the specified byte array, using this graphics context's current font and color.
 void drawChar(char character, int x, int y)
          Draw the given char using the current font and color in the x,y coordinates.
 void drawChars(char[] data, int offset, int length, int x, int y)
          Draw the given char array using the current font and color in the x,y coordinates.
 void drawImage(Image img, int x, int y)
          Draws the image so its top left coordinate corresponds to x/y.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line between the 2 X/Y coordinates.
 void drawOval(int x, int y, int width, int height)
          Draws the outline of an oval into the bounds of the given rectangle.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a closed polygon defined by arrays of x and y coordinates.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
          Draws a sequence of connected lines defined by arrays of x and y coordinates.
 void drawRect(int x, int y, int width, int height)
          Draws a rectangle in the given coordinates.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a rounded corner rectangle in the given coordinates with the arcWidth/height matching the last two arguments respectively.
 void drawString(String str, int x, int y)
          Draw a string using the current font and color in the x,y coordinates.
 void fill3DRect(int x, int y, int width, int height, boolean raised)
          Fills a 3D highlighted rectangle filled with the current color.
 void fill3DRect(int x, int y, int width, int height, boolean raised, byte alpha)
          Fills a 3D highlighted rectangle filled with an optionally translucent fill color.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Fills a circular or elliptical arc based on the given angles and bounding box.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle, byte alpha)
          Fills a circular or elliptical arc based on the given angles and bounding box with an optionally translucent fill color.
 void fillLinearGradient(Color startColor, Color endColor, int x, int y, int width, int height, boolean horizontal)
          Draws a linear gradient in the given coordinates with the given colors, doesn't take alpha into consideration when drawing the gradient.
 void fillOval(int x, int y, int width, int height)
          Fills an oval bounded by the specified rectangle with the current color.
 void fillOval(int x, int y, int width, int height, byte alpha)
          Fills an oval bounded by the specified rectangle with an optionally translucent fill color.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Fills a closed polygon defined by the specified arrays of x and y coordinates with the graphics context's current color.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints, byte alpha)
          Fills a closed polygon defined by the specified arrays of x and y coordinates with an optionally translucent fill color.
 void fillRadialGradient(Color startColor, Color endColor, int x, int y, int width, int height)
          Draws a radial gradient in the given coordinates with the given colors, doesn't take alpha into consideration when drawing the gradient.
 void fillRect(int x, int y, int width, int height)
          Fills the rectangle from the given position according to the width/height minus 1 pixel according to the convention in Java.
 void fillRect(int x, int y, int w, int h, byte alpha)
          Fills a rectangle with an optionally translucent fill color.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Fills a rounded rectangle in the same way as drawRoundRect.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, byte alpha)
          Fills a rounded rectangle in the same way as drawRoundRect with an optionally translucent fill color.
 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
          Draws a filled triangle with the given coordinates.
 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, byte alpha)
          Draws a filled triangle with the given coordinates with an optionally translucent fill color.
 Graphics2D getAWTGraphics()
          Obtains the java.awt.Graphics2D object wrapped by this Graphics instance.
 Rectangle getClipBounds()
          Returns the bounding rectangle of the current clipping area.
 Rectangle getClipBounds(Rectangle r)
          Returns the bounding rectangle of the current clipping area.
 int getClipHeight()
          Returns the clip height.
 int getClipWidth()
          Returns the clip width.
 int getClipX()
          Returns the x clipping position.
 int getClipY()
          Returns the y clipping position.
 Color getColor()
          Returns the current color.
 Font getFont()
          Returns the font used with the drawString method calls.
 int getTranslateX()
          Returns the current x translate value.
 int getTranslateY()
          Returns the current y translate value.
 boolean hitClip(int x, int y, int width, int height)
          Returns true if the specified rectangular area might intersect the current clipping area.
 void lighterColor(int factor)
          Makes the current color slightly lighter, this is useful for many visual effects.
 void setClip(int x, int y, int width, int height)
          Updates the clipping region to match the given region exactly.
 void setColor(Color color)
          Sets the current rgb color while ignoring any potential alpha component within said color value.
 void setFont(Font font)
          Sets the font to use with the drawString method calls.
 void translate(int x, int y)
          Translates the X/Y location for drawing on the underlying surface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graphics

public Graphics(Graphics2D g)
Create a LWUIT Graphics object using a Graphics instance of the underlying Graphics library to be wrapped.

Parameters:
g - a Graphics instance of the underlying Graphics library
Method Detail

translate

public void translate(int x,
                      int y)
Translates the X/Y location for drawing on the underlying surface. Translation is incremental so the new value will be added to the current translation and in order to reset translation we have to invoke translate(-getTranslateX(), -getTranslateY())

Parameters:
x - the x coordinate
y - the y coordinate

getTranslateX

public int getTranslateX()
Returns the current x translate value.

Returns:
an int representing the translate x value

getTranslateY

public int getTranslateY()
Returns the current y translate value.

Returns:
an int representing the translate y value

getColor

public Color getColor()
Returns the current color.

Returns:
the current color
See Also:
setColor(java.awt.Color)

setColor

public void setColor(Color color)
Sets the current rgb color while ignoring any potential alpha component within said color value.

Parameters:
color - the color to be set.
See Also:
getColor()

getFont

public Font getFont()
Returns the font used with the drawString method calls.

Returns:
the current font
See Also:
setFont(Font)

setFont

public void setFont(Font font)
Sets the font to use with the drawString method calls.

Parameters:
font - the font to be set
See Also:
getFont()

getClipX

public int getClipX()
Returns the x clipping position.

Returns:
an int representing the clip x value

getClipY

public int getClipY()
Returns the y clipping position.

Returns:
an int representing the clip y value

getClipWidth

public int getClipWidth()
Returns the clip width.

Returns:
an int representing the clip width value

getClipHeight

public int getClipHeight()
Returns the clip height.

Returns:
an int representing the clip height value

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Clips the given rectangle by intersecting with the current clipping region, this method can thus only shrink the clipping region and never increase it.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Updates the clipping region to match the given region exactly.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line between the 2 X/Y coordinates.

Parameters:
x1 - first x position
y1 - first y position
x2 - second x position
y2 - second y position

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fills the rectangle from the given position according to the width/height minus 1 pixel according to the convention in Java.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

fillRadialGradient

public void fillRadialGradient(Color startColor,
                               Color endColor,
                               int x,
                               int y,
                               int width,
                               int height)
Draws a radial gradient in the given coordinates with the given colors, doesn't take alpha into consideration when drawing the gradient. Notice that a radial gradient will result in a circular shape, to create a square use fillRect or draw a larger shape and clip to the appropriate size.

Parameters:
startColor - the starting RGB color
endColor - the ending RGB color
x - the x coordinate
y - the y coordinate
width - the width of the region to be filled
height - the height of the region to be filled

fillLinearGradient

public void fillLinearGradient(Color startColor,
                               Color endColor,
                               int x,
                               int y,
                               int width,
                               int height,
                               boolean horizontal)
Draws a linear gradient in the given coordinates with the given colors, doesn't take alpha into consideration when drawing the gradient.

Parameters:
startColor - the starting RGB color
endColor - the ending RGB color
x - the x coordinate
y - the y coordinate
width - the width of the region to be filled
height - the height of the region to be filled
horizontal - indicating whether it is a horizontal fill or vertical

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draws a rectangle in the given coordinates.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a rounded corner rectangle in the given coordinates with the arcWidth/height matching the last two arguments respectively.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
arcWidth - the arc width of the given rectangle
arcHeight - the arc height of the given rectangle

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Fills a rounded rectangle in the same way as drawRoundRect.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
arcWidth - the arc width of the given rectangle
arcHeight - the arc height of the given rectangle
See Also:
drawRoundRect(int, int, int, int, int, int)

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight,
                          byte alpha)
Fills a rounded rectangle in the same way as drawRoundRect with an optionally translucent fill color.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
arcWidth - the arc width of the given rectangle
arcHeight - the arc height of the given rectangle
alpha - alpha composite value
See Also:
drawRoundRect(int, int, int, int, int, int)

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Fills a circular or elliptical arc based on the given angles and bounding box.

Parameters:
x - the x coordinate of the given arc
y - the y coordinate of the given arc
width - the width of the given arc
height - the height of the given arc
startAngle - the start angle of the given arc
arcAngle - the end angle of the given arc

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle,
                    byte alpha)
Fills a circular or elliptical arc based on the given angles and bounding box with an optionally translucent fill color.

Parameters:
x - the x coordinate of the given arc
y - the y coordinate of the given arc
width - the width of the given arc
height - the height of the given arc
startAngle - the start angle of the given arc
arcAngle - the end angle of the given arc
alpha - alpha composite value

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draws a circular or elliptical arc based on the given angles and bounding box.

Parameters:
x - the x coordinate of the given arc
y - the y coordinate of the given arc
width - the width of the given arc
height - the height of the given arc
startAngle - the start angle of the given arc
arcAngle - the end angle of the given arc

drawString

public void drawString(String str,
                       int x,
                       int y)
Draw a string using the current font and color in the x,y coordinates. The font is drawn from the top position and not the baseline.

Parameters:
str - the string
x - the x coordinate of the string
y - the y coordinate of the string

drawChar

public void drawChar(char character,
                     int x,
                     int y)
Draw the given char using the current font and color in the x,y coordinates. The font is drawn from the top position and not the baseline.

Parameters:
character - a char
x - x coordinate
y - y coordinate

drawChars

public void drawChars(char[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Draw the given char array using the current font and color in the x,y coordinates. The font is drawn from the top position and not the baseline.

Parameters:
data - the given char array
offset - offset of the array
length - length of the array
x - x coordinate of the position
y - y coordinate of the position

drawImage

public void drawImage(Image img,
                      int x,
                      int y)
Draws the image so its top left coordinate corresponds to x/y.

Parameters:
img - an Image object
x - x coordinate
y - y coordinate

fillTriangle

public void fillTriangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         int x3,
                         int y3)
Draws a filled triangle with the given coordinates.

Parameters:
x1 - x coordinate of point 1
y1 - y coordinate of point 1
x2 - x coordinate of point 2
y2 - y coordinate of point 2
x3 - x coordinate of point 3
y3 - y coordinate of point 3

fillTriangle

public void fillTriangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         int x3,
                         int y3,
                         byte alpha)
Draws a filled triangle with the given coordinates with an optionally translucent fill color.

Parameters:
x1 - x coordinate of point 1
y1 - y coordinate of point 1
x2 - x coordinate of point 2
y2 - y coordinate of point 2
x3 - x coordinate of point 3
y3 - y coordinate of point 3
alpha - alpha composite value

fillRect

public void fillRect(int x,
                     int y,
                     int w,
                     int h,
                     byte alpha)
Fills a rectangle with an optionally translucent fill color.

Parameters:
x - x coordinate of upper left corner
y - y coordinate of upper left corner
w - the width
h - the height
alpha - alpha composite value

lighterColor

public void lighterColor(int factor)
Makes the current color slightly lighter, this is useful for many visual effects.

Parameters:
factor - the degree of lightening a color per channel a number from 1 to 255

darkerColor

public void darkerColor(int factor)
Makes the current color slightly darker, this is useful for many visual effects.

Parameters:
factor - the degree of lightening a color per channel a number from 1 to 255

getAWTGraphics

public Graphics2D getAWTGraphics()
Obtains the java.awt.Graphics2D object wrapped by this Graphics instance.

Returns:
the wrapped java.awt.Graphics2D object

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clears the specified rectangle by filling it with the background color of the current drawing surface.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Copies an area of the component by a distance specified by the dx and dy parameters.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given area
y - the y coordinate of the given area
width - the width of the given area
height - the height of the given area
dx - x coordinate of the distance
dy - y coordinate of the distance

draw3DRect

public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Draws a 3D highlighted outline of the specified rectangle.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
raised - true if the rectangle appears to be raised above the surface, or false if it appears to be sunk into the surface

drawBytes

public void drawBytes(byte[] data,
                      int offset,
                      int length,
                      int x,
                      int y)
Draws the text given by the specified byte array, using this graphics context's current font and color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
data - the specified byte array
offset - the array's offset
length - the array's length
x - the x coordinate of the position
y - the y coordinate of the position

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draws the outline of an oval into the bounds of the given rectangle.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
xPoints - array of x coordinates
yPoints - array of y coordinates
nPoints - number of given points

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
xPoints - array of x coordinates
yPoints - array of y coordinates
nPoints - number of given points

fill3DRect

public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Fills a 3D highlighted rectangle filled with the current color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
raised - true if the rectangle appears to be raised above the surface, or false if it appears to be sunk into the surface

fill3DRect

public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised,
                       byte alpha)
Fills a 3D highlighted rectangle filled with an optionally translucent fill color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
raised - true if the rectangle appears to be raised above the surface, or false if it appears to be sunk into the surface
alpha - alpha composite value

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fills an oval bounded by the specified rectangle with the current color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height,
                     byte alpha)
Fills an oval bounded by the specified rectangle with an optionally translucent fill color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
alpha - alpha composite value

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Fills a closed polygon defined by the specified arrays of x and y coordinates with the graphics context's current color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
xPoints - array of x coordinates
yPoints - array of y coordinates
nPoints - number of given points

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints,
                        byte alpha)
Fills a closed polygon defined by the specified arrays of x and y coordinates with an optionally translucent fill color.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
xPoints - array of x coordinates
yPoints - array of y coordinates
nPoints - number of given points
alpha - alpha composite value

getClipBounds

public Rectangle getClipBounds()
Returns the bounding rectangle of the current clipping area.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Returns:
the bounding rectangle

getClipBounds

public Rectangle getClipBounds(Rectangle r)
Returns the bounding rectangle of the current clipping area. An existing rectangle is used instead of allocating a new one.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
r - the given existing rectangle
Returns:
the bounding rectangle

hitClip

public boolean hitClip(int x,
                       int y,
                       int width,
                       int height)
Returns true if the specified rectangular area might intersect the current clipping area.

IMPLEMENTATION NOTE: Delegate to the wrapped AWT Graphics2D object.

Parameters:
x - the x coordinate of the given rectangle
y - the y coordinate of the given rectangle
width - the width of the given rectangle
height - the height of the given rectangle
Returns:
true if the specified area intersects with the clipping area, false otherwise

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.