java.lang.Objectobjectdraw.MouseInterpreter
public class MouseInterpreter
MouseInterpreter
is the class that processes mouse events and calls the
appropriate methods in WindowController
. Additional mouse interpreters can be
created to pipe these events to other objects as well. For example, you may want an
ActiveObject to be controlled by the mouse, and you can do this by making a new
MouseInterpreter
that has that object as its target and attaching it to the
canvas.
The methods that will be called by the interpreter are the following:
public void onMouseClick(Location point)
public void onMouseDrag(Location point)
public void onMouseMove(Location point)
public void onMouseEnter(Location point)
public void onMouseExit(Location point)
public void onMousePress(Location point)
public void onMouseRelease(Location point)
Constructor Summary | |
---|---|
MouseInterpreter(Object target,
DrawingCanvas canvas)
Construct a MouseInterpreter that will listen for mouse events on the given
canvas and relay them to the target object. |
Method Summary | |
---|---|
void |
addToCanvas(DrawingCanvas canvas)
Add this MouseInterpreter to a canvas. |
DrawingCanvas |
getCanvas()
Return the canvas this interpreter is attached to. |
void |
removeFromCanvas()
Remove this MouseInterpreter from the canvas. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.awt.event.MouseListener |
---|
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased |
Methods inherited from interface java.awt.event.MouseMotionListener |
---|
mouseDragged, mouseMoved |
Constructor Detail |
---|
public MouseInterpreter(Object target, DrawingCanvas canvas)
MouseInterpreter
that will listen for mouse events on the given
canvas
and relay them to the target
object.
target
- Object that will be notified of mouse events. It should have method such
as onMousePress()
for the events that it is interested in.canvas
- Canvas from which events will be captured.Method Detail |
---|
public void addToCanvas(DrawingCanvas canvas)
MouseInterpreter
to a canvas. It will automatically be removed from
whatever canvas it was previously attached to.
canvas
- DrawingCanvas
to which this MouseInterpreter
should listen.public DrawingCanvas getCanvas()
DrawingCanvas
that this interpreter is attached to.public void removeFromCanvas()
MouseInterpreter
from the canvas. It will no longer detect mouse
events, unless you add it back to a canvas.