javax.microedition.lcdui
Class Graphics

java.lang.Object
  extended by javax.microedition.lcdui.Graphics

public class Graphics
extends Object

lcdui.graphics implementation for the NXT LCD screen and in memory images. This class provides a sun-set of the standard JavaME graphics class. In particular it does not implement clipping. There are also several additional non-standard methods to allow easier use of images, alow access to inverse text, and allow the use of raster operations. Some of the standard limitations (like not allowing copyArea of the screen), are not enforced.

Author:
Brian Bagnall and Andy

Field Summary
static int BASELINE
          Position the anchor point at the baseline of text.
static int BLACK
           
static int BOTTOM
          Position the anchor point of text and images below the text or image.
static int DOTTED
          Constant for the DOTTED stroke style.
static int HCENTER
          Centering text and images horizontally around the anchor point
static int LEFT
          Position the anchor point of text and images to the left of the text or image.
static int RIGHT
          Position the anchor point of text and images to the right of the text or image.
static int SOLID
          Constant for the SOLID stroke style.
static int TOP
          Position the anchor point of text and images above the text or image.
static int VCENTER
          Centering images vertically around the anchor point.
static int WHITE
           
 
Constructor Summary
Graphics()
          Default constructor returns a context that can be used to access the NXT LCD display.
 
Method Summary
 void clear()
          Clear the graphics surface to white.
 void copyArea(int sx, int sy, int w, int h, int x, int y, int anchor)
          Copy one rectangular area of the drawing surface to another.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draw an arc, using the current color and style.
 void drawChar(char character, int x, int y, int anchor)
          Draw a single character to the graphics surface using the current color.
 void drawChars(char[] data, int offset, int length, int x, int y, int anchor)
          Draw a series of characters to the graphics surface using the current color.
 void drawImage(Image src, int x, int y, int anchor)
          Draw the specified image to the graphics surface, using the supplied rop.
 void drawLine(int x0, int y0, int x1, int y1)
          Draw a line between the specified points, using the current color and style.
 void drawRect(int x, int y, int width, int height)
          Draw a rectangle using the current color and style.
 void drawRegion(Image src, int sx, int sy, int w, int h, int transform, int x, int y, int anchor)
          Draw the specified region of the supplied image to the graphics surface.
 void drawRegionRop(Image src, int sx, int sy, int w, int h, int x, int y, int anchor, int rop)
          Draw the specified image to the graphics surface, using the supplied rop.
 void drawRegionRop(Image src, int sx, int sy, int w, int h, int transform, int x, int y, int anchor, int rop)
          Draw the specified region of the source image to the graphics surface after applying the requested transformation, use the supplied rop.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draw a rounded rectangle.
 void drawString(String str, int x, int y, int anchor)
          Draws the specified String using the current font and color.
 void drawString(String str, int x, int y, int anchor, boolean inverted)
          Draws the specified String using the current font and color.
 void drawSubstring(String str, int offset, int len, int x, int y, int anchor)
          Draw a substring to the graphics surface using the current color.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draw a filled arc, using the current color.
 void fillRect(int x, int y, int w, int h)
          Draw a filled rectangle using the current color.
 int getBlueComponent()
          Gets the blue value of color.
 int getColor()
          Return the current rgb color.
 int getDisplayColor(int color)
          Returns the actual color that will be used on the display if the specified color is requested.
 Font getFont()
          Return the currently selected font object.
 int getGreenComponent()
          Gets the green value of color.
 int getHeight()
          Return the height of the associated drawing surface.
 int getRedComponent()
          Gets the red value of color.
 int getStrokeStyle()
          Return the current stroke style.
 int getTranslateX()
          Gets the X coordinate of the translated origin of this graphics context.
 int getTranslateY()
          Gets the Y coordinate of the translated origin of this graphics context.
 int getWidth()
          Return the width of the associated drawing surface.
 void setColor(int rgb)
          Set the current drawing color.
 void setColor(int red, int green, int blue)
          Sets the current color to the specified RGB values.
 void setFont(Font f)
           
 void setStrokeStyle(int style)
          Set the stroke style to be used for drawing 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HCENTER

public static final int HCENTER
Centering text and images horizontally around the anchor point

Value 1 is assigned to HCENTER.

See Also:
Constant Field Values

VCENTER

public static final int VCENTER
Centering images vertically around the anchor point.

Value 2 is assigned to VCENTER.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Position the anchor point of text and images to the left of the text or image.

Value 4 is assigned to LEFT.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Position the anchor point of text and images to the right of the text or image.

Value 8 is assigned to RIGHT.

See Also:
Constant Field Values

TOP

public static final int TOP
Position the anchor point of text and images above the text or image.

Value 16 is assigned to TOP.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Position the anchor point of text and images below the text or image.

Value 32 is assigned to BOTTOM.

See Also:
Constant Field Values

BASELINE

public static final int BASELINE
Position the anchor point at the baseline of text.

Value 64 is assigned to BASELINE.

See Also:
Constant Field Values

SOLID

public static final int SOLID
Constant for the SOLID stroke style.

Value 0 is assigned to SOLID.

See Also:
Constant Field Values

DOTTED

public static final int DOTTED
Constant for the DOTTED stroke style.

Value 1 is assigned to DOTTED.

See Also:
Constant Field Values

BLACK

public static final int BLACK
See Also:
Constant Field Values

WHITE

public static final int WHITE
See Also:
Constant Field Values
Constructor Detail

Graphics

public Graphics()
Default constructor returns a context that can be used to access the NXT LCD display.

Method Detail

getWidth

public int getWidth()
Return the width of the associated drawing surface.
Note: This is a non standard method.

Returns:
width of the surface

getHeight

public int getHeight()
Return the height of the associated drawing surface.
Note: This is a non standard method.

Returns:
height of the surface.

drawString

public void drawString(String str,
                       int x,
                       int y,
                       int anchor,
                       boolean inverted)
Draws the specified String using the current font and color. x and y give the location of the anchor point. Additional method to allow for the easy use of inverted text. In this case the area below the string is drawn in the current color, before drawing the text in the "inverted" color.
Note: This is a non standard method.

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
inverted - true to invert the text display.

drawRegionRop

public void drawRegionRop(Image src,
                          int sx,
                          int sy,
                          int w,
                          int h,
                          int x,
                          int y,
                          int anchor,
                          int rop)
Draw the specified image to the graphics surface, using the supplied rop.
Note: This is a non standard method. Added because without it, it is very hard to invert/manipulate an image, or screen region

Parameters:
src - image to draw (may be null for ops that do not require input.
sx - x offset in the source
sy - y offset in the source
w - width of area to draw
h - height of area to draw.
x - destination
y - destination
anchor - location of the anchor point
rop - drawing operation.
See Also:
Image

drawRegionRop

public void drawRegionRop(Image src,
                          int sx,
                          int sy,
                          int w,
                          int h,
                          int transform,
                          int x,
                          int y,
                          int anchor,
                          int rop)
Draw the specified region of the source image to the graphics surface after applying the requested transformation, use the supplied rop.
NOTE: When calculating the anchor point this method assumes that a transformed version of the source width/height should be used.

Parameters:
src - The source image
sx - x coordinate of the region
sy - y coordinate of the region
w - width of the region
h - height of the region
transform - the required transform
x - x coordinate of the anchor point
y - y coordinate of the anchor point
anchor - type of anchor
rop - raster operation used to draw the output.

clear

public void clear()
Clear the graphics surface to white.


getFont

public Font getFont()
Return the currently selected font object.

Returns:
Current font.

setFont

public void setFont(Font f)

getDisplayColor

public int getDisplayColor(int color)
Returns the actual color that will be used on the display if the specified color is requested. On the NXT LCD and value that is not black will be treated as white.

Parameters:
color -
Returns:
the display color

setColor

public void setColor(int rgb)
Set the current drawing color. The value is in the format 0x00RRGGBB. NOTE. Currently only black and white is supported. any non black color is treated as white!

Parameters:
rgb - new color.

setColor

public void setColor(int red,
                     int green,
                     int blue)
Sets the current color to the specified RGB values.

Parameters:
red - the red component
green - the green component
blue - the blue
Throws:
IllegalArgumentException - if any of the color components are outside of range 0-255
See Also:
getColor()

getColor

public int getColor()
Return the current rgb color.

Returns:
current color.

getRedComponent

public int getRedComponent()
Gets the red value of color.

Returns:
value in range 0-255
See Also:
setColor(int, int, int)

getGreenComponent

public int getGreenComponent()
Gets the green value of color.

Returns:
integer value in range 0-255
See Also:
setColor(int, int, int)

getBlueComponent

public int getBlueComponent()
Gets the blue value of color.

Returns:
integer value in range 0-255
See Also:
setColor(int, int, int)

drawString

public void drawString(String str,
                       int x,
                       int y,
                       int anchor)
Draws the specified String using the current font and color. x and y give the location 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

drawSubstring

public void drawSubstring(String str,
                          int offset,
                          int len,
                          int x,
                          int y,
                          int anchor)
Draw a substring to the graphics surface using the current color.

Parameters:
str - the base string
offset - the start of the sub string
len - the length of the sub string
x - the x coordinate of the anchor point
y - the x coordinate of the anchor point
anchor - the anchor point used to position the text.

drawChar

public void drawChar(char character,
                     int x,
                     int y,
                     int anchor)
Draw a single character to the graphics surface using the current color.

Parameters:
character - the character to draw
x - the x coordinate of the anchor point
y - the x coordinate of the anchor point
anchor - the anchor point used to position the text.

drawChars

public void drawChars(char[] data,
                      int offset,
                      int length,
                      int x,
                      int y,
                      int anchor)
Draw a series of characters to the graphics surface using the current color.

Parameters:
data - the characters
offset - the start of the characters to be drawn
length - the length of the character string to draw
x - the x coordinate of the anchor point
y - the x coordinate of the anchor point
anchor - the anchor point used to position the text.

drawRegion

public void drawRegion(Image src,
                       int sx,
                       int sy,
                       int w,
                       int h,
                       int transform,
                       int x,
                       int y,
                       int anchor)
Draw the specified region of the supplied image to the graphics surface. NOTE: Transforms are not currently supported.

Parameters:
src - image to draw (may be null for ops that do not require input.
sx - x offset to the region
sy - y offset to the region
w - width of the region
h - height of the region
transform -
x - destination
y - destination
anchor - location of the anchor point
See Also:
Image

drawImage

public void drawImage(Image src,
                      int x,
                      int y,
                      int anchor)
Draw the specified image to the graphics surface, using the supplied rop.

Parameters:
src - image to draw (may be null for ops that do not require input.
x - destination
y - destination
anchor - location of the anchor point
See Also:
Image

drawLine

public void drawLine(int x0,
                     int y0,
                     int x1,
                     int y1)
Draw a line between the specified points, using the current color and style.

Parameters:
x0 - x start point
y0 - y start point
x1 - x end point
y1 - y end point

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draw an arc, using the current color and style.

Parameters:
x -
y -
width -
height -
startAngle -
arcAngle -

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draw a filled arc, using the current color.

Parameters:
x -
y -
width -
height -
startAngle -
arcAngle -

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draw a rounded rectangle.

Parameters:
x -
y -
width -
height -
arcWidth -
arcHeight -

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draw a rectangle using the current color and style.

Parameters:
x -
y -
width -
height -

fillRect

public void fillRect(int x,
                     int y,
                     int w,
                     int h)
Draw a filled rectangle using the current color.

Parameters:
x -
y -
w -
h -

getStrokeStyle

public int getStrokeStyle()
Return the current stroke style.

Returns:
current style.

setStrokeStyle

public void setStrokeStyle(int style)
Set the stroke style to be used for drawing operations.

Parameters:
style - new style.

copyArea

public void copyArea(int sx,
                     int sy,
                     int w,
                     int h,
                     int x,
                     int y,
                     int anchor)
Copy one rectangular area of the drawing surface to another.

Parameters:
sx - Source x
sy - Source y
w - Source width
h - Source height
x - Destination x
y - Destination y
anchor - location of the anchor point of the destination.

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. Calls are cumulative.

Parameters:
x - the new translation origin x value
y - new translation origin y value
See Also:
getTranslateX(), getTranslateY()

getTranslateX

public int getTranslateX()
Gets the X coordinate of the translated origin of this graphics context.

Returns:
X of current origin

getTranslateY

public int getTranslateY()
Gets the Y coordinate of the translated origin of this graphics context.

Returns:
Y of current origin