PenProfile 2.x

com.livescribe.display
Class Graphics

java.lang.Object
  extended by com.livescribe.display.Graphics

public class Graphics
extends Object

The Graphics class provides 2D drawing functionality. It encapsulates the process of rendering on any drawing surface--whether an image or the pen display screen. The targeted image or display is called the "destination" of the Graphics instance. The Graphics instance contains the attributes, such as location, width, and color, of the lines used to render geometric shapes.

The static method getGraphics returns a Graphics instance that is associated with either the Image passed to the constructor or with the pen display. Call methods such as setBrushColor and setLineStyle to assign attributes. To render to the destination, call any of the draw methods, the fillRect method, the clear methods, or the lineTo method.


Field Summary
static int LINE_STYLE_DOTTED
           
static int LINE_STYLE_INVISIBLE
           
static int LINE_STYLE_SOLID
           
 
Method Summary
 void clearRect()
          Clears the drawing surface backed by the Graphics object.
 void clearRect(int x, int y, int width, int height)
          Clears the portion of the drawing surface backed by the Graphics object.
 void drawImage(Image src, int x, int y)
          Draw the specified image at coordinates x and y of the destination.
 void drawImage(Image src, int srcx, int srcy, int width, int height, int x, int y)
          Draws a portion of the image specified by (srcx,srcy,width,height) to the location (x,y) of the destination.
 void drawLine(int x0, int y0, int x1, int y1)
          Draws a line between the coordinates (x0,y0) and (x1,y1) on the destination associated with this Graphics.
 void drawString(AttributedText text, int x, int y, int anchor)
          Draw a Attributed text on the destination of this Graphics, using the current font.
 void drawString(String text, int x, int y, int anchor)
          Draw a string on the destination of this Graphics, using the current font.
 void fill(int x, int y, int width, int height, int color)
           
 void fillRect(int x, int y, int width, int height)
          Fills the specified rectangle with the white color.
 byte getBrushColor()
          Gets the current brush color of this Graphics.
 short getClipHeight()
          Gets the height of the clip
 short getClipWidth()
          Gets the width of the clip
 short getClipX()
          Gets the X-coordinate of the clip.
 short getClipY()
          Gets the Y-coordinate of the clip.
 Image getDestination()
          Gets the destination Image this Graphics renders to.
 Font getFont()
          Gets the current font of this Graphics.
static Graphics getGraphics(Image image)
          Gets an instance of the Graphics that can render to the Image passed.
 byte getNegativeBrushColor()
          Gets the color that will erase what is painted with the brush.
 void lineTo(int x, int y)
          Draws a line from the current position to the coordinate specified.
 void moveTo(int x, int y)
          Move to the coordinate specified by (x,y)
 void putPixel(int x, int y, int color)
          Puts a pixel (x,y) on the destination associated with this Graphics.
 void setBrushColor(byte brushColor)
          Set the color for this Graphics.
 void setFont(Font font)
          Sets the font for this Graphics.
 void setLineStyle(int linestyle)
          Set the line style for all strokes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_STYLE_SOLID

public static final int LINE_STYLE_SOLID
See Also:
Constant Field Values

LINE_STYLE_DOTTED

public static final int LINE_STYLE_DOTTED
See Also:
Constant Field Values

LINE_STYLE_INVISIBLE

public static final int LINE_STYLE_INVISIBLE
See Also:
Constant Field Values
Method Detail

getGraphics

public static Graphics getGraphics(Image image)
Gets an instance of the Graphics that can render to the Image passed. If the image is null then it is treated as a request to get a graphics instance for the display.

Parameters:
image - destination for the graphics operations. A value of null refers to the display as the destination.
Returns:
graphics instance.

getFont

public Font getFont()
Gets the current font of this Graphics.

Returns:
Font

setFont

public void setFont(Font font)
Sets the font for this Graphics.

Parameters:
font - Font

drawString

public void drawString(String text,
                       int x,
                       int y,
                       int anchor)
Draw a string on the destination of this Graphics, using the current font. Note that the Y-coordinate represents the upper-left corner of the text and not the baseline. This is not consistent with how Java AWT's drawString method works.

Parameters:
text - the text to draw
x - the X-coordinate
y - the Y-coordinate
anchor - the anchor, unused

drawString

public void drawString(AttributedText text,
                       int x,
                       int y,
                       int anchor)
Draw a Attributed text on the destination of this Graphics, using the current font. Note that the Y-coordinate represents the upper-left corner of the text and not the baseline. This is not consistent with how Java AWT's drawString method works.

Parameters:
text - attributed text to render
x - the X-coordinate
y - the Y-coordinate
anchor - the anchor, unused
Since:
0.5

setBrushColor

public void setBrushColor(byte brushColor)
Set the color for this Graphics. All drawing calls will use the specified color.

Parameters:
brushColor - the valid colors are (Display.getBlackColor(), Display.getWhiteColor())

getBrushColor

public byte getBrushColor()
Gets the current brush color of this Graphics.

Returns:
the current brush color

getNegativeBrushColor

public byte getNegativeBrushColor()
Gets the color that will erase what is painted with the brush. Applies to Color and erase associated with this Graphics.

Returns:
the color that will erase what is painted with the brush.

setLineStyle

public void setLineStyle(int linestyle)
Set the line style for all strokes.

Parameters:
linestyle - style of the line

clearRect

public void clearRect()
Clears the drawing surface backed by the Graphics object.


clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clears the portion of the drawing surface backed by the Graphics object. The rectangle specified should be fully contained by the drawing surface bounds.

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

fill

public void fill(int x,
                 int y,
                 int width,
                 int height,
                 int color)

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fills the specified rectangle with the white color.

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

drawLine

public void drawLine(int x0,
                     int y0,
                     int x1,
                     int y1)
Draws a line between the coordinates (x0,y0) and (x1,y1) on the destination associated with this Graphics. The current color and stroke style are used. The origin is at the top left-hand corner of the pen display.

Parameters:
x0 - the x coordinate of the start of the line.
y0 - the y coordinate of the start of the line.
x1 - the x coordinate of the end of the line.
y1 - the y coordinate of the end of the line.

putPixel

public void putPixel(int x,
                     int y,
                     int color)
Puts a pixel (x,y) on the destination associated with this Graphics.

Parameters:
x - the x coordinate of the pixel.
y - the y coordinate of the pixel.
color - the color of the pixel

moveTo

public void moveTo(int x,
                   int y)
Move to the coordinate specified by (x,y)

Parameters:
x - the X-coordinate
y - the Y-coordinate

lineTo

public void lineTo(int x,
                   int y)
Draws a line from the current position to the coordinate specified.

Parameters:
x - the X-coordinate
y - the Y-coordinate

drawImage

public void drawImage(Image src,
                      int x,
                      int y)
Draw the specified image at coordinates x and y of the destination. All or parts of src may end up outside the dimensions of the destination for this Graphics object.

Parameters:
src - the Image to be drawn to the destination.
x - horizontal position of src relative to destination.
y - vertical position of src relative to destination.

drawImage

public void drawImage(Image src,
                      int srcx,
                      int srcy,
                      int width,
                      int height,
                      int x,
                      int y)
Draws a portion of the image specified by (srcx,srcy,width,height) to the location (x,y) of the destination.

Parameters:
src - source image.
srcx - source x coordinate
srcy - source y coordinate
width - width of the source image
height - height of the source image
x - destination x coordinate
y - destination y coordinate

getDestination

public Image getDestination()
Gets the destination Image this Graphics renders to.

Returns:
destination image.

getClipX

public short getClipX()
Gets the X-coordinate of the clip.

Returns:
the clip X.

getClipY

public short getClipY()
Gets the Y-coordinate of the clip.

Returns:
the clip Y.

getClipWidth

public short getClipWidth()
Gets the width of the clip

Returns:
clip width

getClipHeight

public short getClipHeight()
Gets the height of the clip

Returns:
clip height

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.