objectdraw
Class MouseInterpreter

java.lang.Object
  extended by objectdraw.MouseInterpreter
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener

public class MouseInterpreter
extends Object
implements MouseListener, MouseMotionListener

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)

Author:
Russell Zahniser (russell@zahniser.net)

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

MouseInterpreter

public 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.

Parameters:
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

addToCanvas

public void addToCanvas(DrawingCanvas canvas)
Add this MouseInterpreter to a canvas. It will automatically be removed from whatever canvas it was previously attached to.

Parameters:
canvas - DrawingCanvas to which this MouseInterpreter should listen.

getCanvas

public DrawingCanvas getCanvas()
Return the canvas this interpreter is attached to.

Returns:
the DrawingCanvas that this interpreter is attached to.

removeFromCanvas

public void removeFromCanvas()
Remove this MouseInterpreter from the canvas. It will no longer detect mouse events, unless you add it back to a canvas.