public interface DrawingCanvas
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.
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 |
---|
void addComponentListener(ComponentListener l)
l
- an object that will react to component events in the canvasvoid addKeyListener(KeyListener l)
WindowController
.
l
- an object that will react to key events in the canvasvoid addMouseListener(MouseListener l)
Controller
.
l
- an object that will react to mouse events in the canvasvoid addMouseMotionListener(MouseMotionListener l)
WindowController
.
l
- an object that will react to mouse motion events in the canvasvoid clear()
void clearLoupe()
void disableAutoRepaint()
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.
void enableAutoRepaint()
Color getBackground()
Color
of the canvasDrawableIterator getDrawableIterator()
DrawableIterator
that will list off, one by one, the
DrawableInterface
objects that exist on this canvas.
DrawableIterator
for all the objects on this canvasint getHeight()
Dimension getSize()
Dimension
object.
int getWidth()
void repaint()
void setBackground(Color c)
c
- new Color
for the background of the canvasvoid setLoupe(Location point)
point
- Location
to move the loupe tovoid setLoupe(Location point, double size, double zoom)
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
.
point
- center Location
to magnifysize
- diameter of the circle to be magnifiedzoom
- how many times bigger to show the image