ewe.fx
Class BufferedGraphics

java.lang.Object
  extended byewe.fx.BufferedGraphics

public class BufferedGraphics
extends Object

A BufferedGraphics object provides a temporary off-screen Image for a Control to draw on, before being transferred to the on-screen Graphics.

This facility is necessary because some platforms (e.g. Qtopia on the Sharp Zaurus) do not support reading bits from a Window surface. This makes certain drawing operations impossible directly on this surface. e.g. XOR'ing of images and the drawing of transparent images. However all platforms should support reading bits from an Image and therefore these operations are possible using images.

You will generally create a BufferedGraphics in the doPaint() method of your control. You then call getGraphics() to get the Graphics object that you should use for your drawing and when you are done call release() on the BufferedGraphics to transfer what has been drawn to the original Graphics.

Note that you can construct the BufferedGraphics conditionally, which means that if the original Graphics was already drawing on an Image, that same graphics will be used and no temporary image will be created. In fact, when created conditionally, the canCopyFrom() method is called on the original Graphics, and if it returns true, then that original Graphics is used.


Constructor Summary
BufferedGraphics(Graphics original, Control control)
          Create a new BufferedGraphics from the original if the original does not support copying.
BufferedGraphics(Graphics original, Rect drawingAreaNeeded)
          Create a new BufferedGraphics from the original if the original does not support copying.
BufferedGraphics(Graphics original, Rect drawingAreaNeeded, boolean unconditionally)
          Create a new BufferedGraphics from the original.
 
Method Summary
 Graphics cancel()
          Cancel drawing, free resources and do not update the original graphics.
 Graphics flush()
          Copy the data already drawn on this surface, to the destination surface.
 Graphics getGraphics()
          Get the graphics that you should use to draw on.
 Graphics release()
          Copy the drawn image to the original graphics and free all temporary resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

BufferedGraphics

public BufferedGraphics(Graphics original,
                        Rect drawingAreaNeeded,
                        boolean unconditionally)
Create a new BufferedGraphics from the original.

Parameters:
original - The original graphics.
drawingAreaNeeded - A non-null rectangle specifying the area needed.
unconditionally - If this is true then a temporary image will always be created. If it is false, then a temporary image will only be created if original.canCopyFrom() returns false.

BufferedGraphics

public BufferedGraphics(Graphics original,
                        Rect drawingAreaNeeded)
Create a new BufferedGraphics from the original if the original does not support copying.

Parameters:
original - The original graphics.
drawingAreaNeeded - A non-null rectangle specifying the area needed.

BufferedGraphics

public BufferedGraphics(Graphics original,
                        Control control)
Create a new BufferedGraphics from the original if the original does not support copying.

Parameters:
original - The original graphics.
control - The control that the original graphics was set up for. This will use a drawing area equal to the size of the control.
Method Detail

getGraphics

public Graphics getGraphics()
Get the graphics that you should use to draw on. This may be the same as the original Graphics object, if that original Graphics already supported copying.

Returns:
The Graphics that you should use to draw on.

flush

public Graphics flush()
Copy the data already drawn on this surface, to the destination surface. You can continue using the buffered graphics after if you need to. This does not call flush on the original graphics. If you want to flush() the original Graphics as well, then you can call:
 	 bufferedGraphics.flush().flush();
 

Returns:
The original graphics.

release

public Graphics release()
Copy the drawn image to the original graphics and free all temporary resources. You should not attempt to use this after calling this method.

Returns:
The original Graphics.

cancel

public Graphics cancel()
Cancel drawing, free resources and do not update the original graphics.

Returns:
The original Graphics.