objectdraw
Class CanvasManager

java.lang.Object
  extended by objectdraw.CanvasManager

 class CanvasManager
extends Object

A CanvasManager is automatically associated with each DrawingCanvas to manage the Drawable objects displayed on that canvas. CanvasManager provides methods to add, remove, or reorder objects on the canvas. Internally, the CanvasManager performs the steps necessary to update the image displayed when the collection of Drawables in changed in some way.

Version:
1.1.1 released February 2005 version 1.1 moved getVersion from CanvasManager to Controller

Field Summary
static Dimension DEFAULT_PREFERRED_SIZE
          The canvas' default preferred dimensions.
 
Constructor Summary
CanvasManager(Dimension size, DrawingCanvas canvas)
          Creates a CanvasManager.
 
Method Summary
(package private)  void addToCanvas(Drawable d)
          Adds a new object on top of existing objects.
(package private)  void clear()
          Clears the vector of all objects and redraws the screen.
 void disableAutoRepaint()
          Turns auto repaint off so the programmer must indicate when the canvas should be repainted.
 void enableAutoRepaint()
          Turns auto repaint on so the programmer does not have to manually repaint after changing the canvas.
protected  DrawingCanvas getCanvas()
          Access the DrawingCanvas associated with this manater
 DrawableIterator getDrawableIterator()
          Creates and returns an iterator of all the objects in the CanvasManager
(package private)  void paint(Graphics g)
          Paints the canvas.
(package private)  void removeFromCanvas(Drawable d)
          Removes the Drawable d from the canvas.
(package private)  void sendObjectBackward(Drawable object)
          Sends an object backward.
(package private)  void sendObjectForward(Drawable object)
          Sends an object forward.
(package private)  void sendObjectToBack(Drawable object)
          Sends an object to the back.
(package private)  void sendObjectToFront(Drawable object)
          Sends an object to the front.
(package private)  void setStateChanged()
          When invoked sets the stateChanged boolean to true and calls repaint() if enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PREFERRED_SIZE

public static final Dimension DEFAULT_PREFERRED_SIZE
The canvas' default preferred dimensions.

Constructor Detail

CanvasManager

public CanvasManager(Dimension size,
                     DrawingCanvas canvas)
Creates a CanvasManager.

Parameters:
size - the dimensions of the canvas
Method Detail

addToCanvas

void addToCanvas(Drawable d)
Adds a new object on top of existing objects. If the Drawable d is not already on a canvas d's canvas manager is set to be to this manager and d is added to the vector of drawables.

Parameters:
d - the new object

clear

void clear()
Clears the vector of all objects and redraws the screen.


disableAutoRepaint

public void disableAutoRepaint()
Turns auto repaint off so the programmer must indicate when the canvas should be repainted.


enableAutoRepaint

public void enableAutoRepaint()
Turns auto repaint on so the programmer does not have to manually repaint after changing the canvas.


getCanvas

protected DrawingCanvas getCanvas()
Access the DrawingCanvas associated with this manater

Returns:
the canvas this manager controls

getDrawableIterator

public DrawableIterator getDrawableIterator()
Creates and returns an iterator of all the objects in the CanvasManager

Returns:
an iterator of all of the CanvasManager's objects

paint

void paint(Graphics g)
Paints the canvas.

Parameters:
g - the canvas' graphics context.

removeFromCanvas

void removeFromCanvas(Drawable d)
Removes the Drawable d from the canvas.

Parameters:
d - the object to be removed

sendObjectBackward

void sendObjectBackward(Drawable object)
Sends an object backward. This means that it is being moved to the front of the vector

Parameters:
object - the object

sendObjectForward

void sendObjectForward(Drawable object)
Sends an object forward. This means that it is being moved to the back of the vector

Parameters:
object - the object

sendObjectToBack

void sendObjectToBack(Drawable object)
Sends an object to the back.

Parameters:
object - the object to move

sendObjectToFront

void sendObjectToFront(Drawable object)
Sends an object to the front.

Parameters:
object - the object to move

setStateChanged

void setStateChanged()
When invoked sets the stateChanged boolean to true and calls repaint() if enabled.