objectdraw
Interface DrawingCanvas

All Superinterfaces:
objectdraw.Dependent

public interface DrawingCanvas
extends objectdraw.Dependent

DrawingCanvas is the interface listing the methods of the canvas on which objects are placed. It has methods dealing with the list of objects, its size, its background color, the events it receives, and whether it repaints automatically when a change is made. It is also possible to use a special magnifying-glass feature called the "loupe", which provides a zoomed-in view of a circular portion of the canvas.

Author:
Russell Zahniser (russell@zahniser.net)

Method Summary
 void addComponentListener(ComponentListener l)
          Add a component listener to the canvas.
 void addKeyListener(KeyListener l)
          Add a key listener to the canvas.
 void addMouseListener(MouseListener l)
          Add a mouse listener to the canvas.
 void addMouseMotionListener(MouseMotionListener l)
          Add a mouse motion listener to the canvas.
 void clear()
          Remove all objects from this canvas.
 void clearLoupe()
          Hide the loupe.
 void disableAutoRepaint()
          Set the canvas to repaint only when you explicitly call its repaint() method.
 void enableAutoRepaint()
          Set the canvas to repaint automatically when a change is made.
 Color getBackground()
          Return the background color of this canvas
 DrawableIterator getDrawableIterator()
          Return a DrawableIterator that will list off, one by one, the DrawableInterface objects that exist on this canvas.
 int getHeight()
          Return the height of the canvas
 Dimension getSize()
          Return the size of the canvas as a Dimension object.
 int getWidth()
          Return the width of the canvas
 void repaint()
          Repaint the canvas.
 void setBackground(Color c)
          Change the background color of the canvas
 void setLoupe(Location point)
          Move the loupe to center on the given location.
 void setLoupe(Location point, double size, double zoom)
          Move the loupe to the given location, and change its size and zoom factor.
 

Method Detail

addComponentListener

void addComponentListener(ComponentListener l)
Add a component listener to the canvas. This is a way to be notified when the canvas is resized, moved, hidden, or shown.

Parameters:
l - an object that will react to component events in the canvas

addKeyListener

void addKeyListener(KeyListener l)
Add a key listener to the canvas. This is an alternative to using the key event methods in WindowController.

Parameters:
l - an object that will react to key events in the canvas

addMouseListener

void addMouseListener(MouseListener l)
Add a mouse listener to the canvas. This is an alternative to using the mouse event methods in Controller.

Parameters:
l - an object that will react to mouse events in the canvas

addMouseMotionListener

void addMouseMotionListener(MouseMotionListener l)
Add a mouse motion listener to the canvas. This is an alternative to using the mouse event methods in WindowController.

Parameters:
l - an object that will react to mouse motion events in the canvas

clear

void clear()
Remove all objects from this canvas.


clearLoupe

void clearLoupe()
Hide the loupe.


disableAutoRepaint

void disableAutoRepaint()
Set the canvas to repaint only when you explicitly call its repaint() method. This can be useful if you want to be able to make a lot of changes at once and not have the canvas draw in a state where the changes are incomplete.


enableAutoRepaint

void enableAutoRepaint()
Set the canvas to repaint automatically when a change is made. This does not mean that it has to redraw the whole canvas for every change; if a string of changes are made, it remembers that it needs to redraw, and does so once the changes are done.


getBackground

Color getBackground()
Return the background color of this canvas

Returns:
the background Color of the canvas

getDrawableIterator

DrawableIterator getDrawableIterator()
Return a DrawableIterator that will list off, one by one, the DrawableInterface objects that exist on this canvas.

Returns:
a DrawableIterator for all the objects on this canvas

getHeight

int getHeight()
Return the height of the canvas

Returns:
the height of the canvas

getSize

Dimension getSize()
Return the size of the canvas as a Dimension object.

Returns:
the size of the canvas

getWidth

int getWidth()
Return the width of the canvas

Returns:
the width of the canvas

repaint

void repaint()
Repaint the canvas. Normally, the canvas is repainted automatically when any change is made, so using this method is only necessary if you have disabled auto-repainting.


setBackground

void setBackground(Color c)
Change the background color of the canvas

Parameters:
c - new Color for the background of the canvas

setLoupe

void setLoupe(Location point)
Move the loupe to center on the given location. This will also cause it to be displayed, if it was not displayed previously.

Parameters:
point - Location to move the loupe to

setLoupe

void setLoupe(Location point,
              double size,
              double zoom)
Move the loupe to the given location, and change its size and zoom factor. This will also cause it to be displayed, if it was not displayed previously. The size is the diameter of the circle to be magnified, and zoom is how many times bigger to make it. So, the circle you will actually see on the canvas has a diameter of size * zoom.

Parameters:
point - center Location to magnify
size - diameter of the circle to be magnified
zoom - how many times bigger to show the image