yopsx
Class VirtualImagePainter

java.lang.Object
  extended by yopsx.VirtualImagePainter
Direct Known Subclasses:
InkedImagePainter

public class VirtualImagePainter
extends java.lang.Object

Set up an image to be painted with a given color and brush width.

Author:
cytron

Field Summary
protected  int brush
           
protected  java.awt.Color color
           
 
Constructor Summary
VirtualImagePainter(Image image, java.awt.Color color, int brush)
           
 
Method Summary
 void addPixelObserver(PixelObserver po)
          Add a PixelObserver to be notified when a pixel changes.
protected  void affectPixel(Point p, java.awt.Color newColor, java.awt.Color oldColor)
          Instead of changing the pixel directly, allow observers to do that.
protected  Image getImage()
          Allow subclasses to get the image, but nobody else.
protected  java.awt.Color getPixel(Point p)
          Allow subclasses to inspect the image's pixels.
 boolean paint(Point pixel)
          Paint the specified pixel with the default color, using brushwidth pixels on all sides.
 void repaint()
          Request repaint of the contained image.
 boolean setPixel(Point pixel)
          Set a pixel to the default color.
 boolean setPixel(Point pixel, java.awt.Color color)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

color

protected final java.awt.Color color

brush

protected final int brush
Constructor Detail

VirtualImagePainter

public VirtualImagePainter(Image image,
                           java.awt.Color color,
                           int brush)
Parameters:
image - The yops image to be painted
color - The default color to be used
brush - The brush width
Method Detail

getImage

protected Image getImage()
Allow subclasses to get the image, but nobody else.

Returns:

addPixelObserver

public void addPixelObserver(PixelObserver po)
Add a PixelObserver to be notified when a pixel changes.

Parameters:
po - the PixelObserver to be added

repaint

public void repaint()
Request repaint of the contained image. This method delegates repaint to the image. Java will normally buffer updates; if you want to see the effects of changes sooner, just call this method.


getPixel

protected java.awt.Color getPixel(Point p)
Allow subclasses to inspect the image's pixels.

Parameters:
p - Location to be examined
Returns:
Color of the specified pixel

paint

public boolean paint(Point pixel)
Paint the specified pixel with the default color, using brushwidth pixels on all sides. All pixels in bounds of the point +/- the brush width are painted. If any of those pixels is out of bounds, false is returned.

Parameters:
pixel - Point to be painted
Returns:
true iff the brush did not wander out of bounds

setPixel

public boolean setPixel(Point pixel)
Set a pixel to the default color.

Parameters:
pixel -
Returns:
true iff pixel was in bounds

setPixel

public final boolean setPixel(Point pixel,
                              java.awt.Color color)

affectPixel

protected void affectPixel(Point p,
                           java.awt.Color newColor,
                           java.awt.Color oldColor)
Instead of changing the pixel directly, allow observers to do that. Only subclasses can change the pixel, but other observers can witness.

Parameters:
p -
color -