public class MouseTracker extends Drawable implements MouseListener, MouseMotionListener, InputObject
A MouseTracker is an InputObject. The values of the variables associated with the MouseTracker can change only when the checkInput() method is called (or when the setVal() method of the variable is called to set its value explicitely). If you want the value of the variables to track the mouse, you must add the MouseTracker (or the DisplayCanvas that contains it) to a Controller and set that Controller to listen for changes from the MouseTracker object by passing the Controller to the setOnUserAction() method of this class.
Modifier and Type | Field and Description |
---|---|
protected boolean |
clampX
If thie is true, then the value of the variable associated with
the x-ccordinate of the mouse is clamped to lie within the
xmin and xmax of the coordinate rect.
|
protected boolean |
clampY
If thie is true, then the value of the variable associated with
the y-ccordinate of the mouse is clamped to lie within the
ymin and ymax of the coordinate rect.
|
protected boolean |
listenForDrags
If true, the MouseTracker responds to both clicks and drags.
|
protected Controller |
onUserAction
If this is non-null, then its compute() method is called
when the user clicks the mouse and, if listenForDrags is also
true, when the user drags and releases the mouse.
|
protected boolean |
undefinedWhenNotDragging
If true, the values of the associated variables are
undefined except during the time that the user is
clicking and dragging the mouse.
|
Constructor and Description |
---|
MouseTracker()
Create a MouseTracker that responds to both clicks and drags.
|
MouseTracker(boolean listenForDrags,
boolean undefinedWhenNotDragging)
Creates a mouse tracker.
|
Modifier and Type | Method and Description |
---|---|
void |
checkInput()
Set the values of the associated variables.
|
void |
draw(Graphics g,
boolean coordsChanged)
A MouseTracker doesn't actually draw anything, but this method is required in
a Drawable object.
|
boolean |
getClampX()
Get the "clampX" property of the MouseTracker.
|
boolean |
getClampY()
Get the "clampY" property of the MouseTracker.
|
boolean |
getListenForDrags()
Gets the "listenForDrags" property of the MouseTracker, which determines
if the MouseTracker responds to both clicks and drags, or only to clicks.
|
Controller |
getOnUserAction()
Get the Controller that responds when a user mouse action is detected by this MouseTracker.
|
boolean |
getUndefinedWhenNotDragging()
Gets the "undefinedWhenNotDragging" property of the MouseTracker.
|
Variable |
getXVar()
Get the variable whose value represents the x-coordinate of the MouseTracker.
|
Variable |
getYVar()
Get the variable whose value represents the y-coordinate of the MouseTracker.
|
void |
mouseClicked(MouseEvent evt)
Empty method, required by MouseListener interface.
|
void |
mouseDragged(MouseEvent evt)
Responds when the user drags the mouse.
|
void |
mouseEntered(MouseEvent evt)
Empty method, required by MouseMotionListener interface.
|
void |
mouseExited(MouseEvent evt)
Empty method, required by MouseMotionListener interface.
|
void |
mouseMoved(MouseEvent evt)
Empty method, required by MouseMotionListener interface.
|
void |
mousePressed(MouseEvent evt)
Responds when the user clicks the mouse in the rectangular
area occupied by the CoordinateRect that contains this MouseTracker.
|
void |
mouseReleased(MouseEvent evt)
Responds when the user releases the mouse.
|
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, it simply calls
setOnUserAction(c).
|
void |
setClampX(boolean clamp)
Set the "clampX" property of the MouseTracker.
|
void |
setClampY(boolean clamp)
Set the "clampY" property of the MouseTracker.
|
void |
setListenForDrags(boolean listen)
Sets the "listenForDrags" property of the MouseTracker.
|
void |
setOnUserAction(Controller onUserAction)
Set a Controller to respond to user mouse actions tracked
by this MouseTracker.
|
protected void |
setOwnerData(DisplayCanvas canvas,
CoordinateRect coords)
This is called automatically by CoordinateRect when the
MouseTracker is added to the CoordinateRect.
|
void |
setUndefinedWhenNotDragging(boolean b)
Sets the "undefinedWhenNotDragging" property of the MouseTracker.
|
getVisible, needsRedraw, setVisible
protected boolean listenForDrags
protected boolean undefinedWhenNotDragging
protected Controller onUserAction
protected boolean clampX
protected boolean clampY
public MouseTracker()
public MouseTracker(boolean listenForDrags, boolean undefinedWhenNotDragging)
public Variable getXVar()
public Variable getYVar()
public void setListenForDrags(boolean listen)
public boolean getListenForDrags()
public void setUndefinedWhenNotDragging(boolean b)
public boolean getUndefinedWhenNotDragging()
public void setOnUserAction(Controller onUserAction)
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public Controller getOnUserAction()
public void setClampX(boolean clamp)
public boolean getClampX()
public void setClampY(boolean clamp)
public boolean getClampY()
public void checkInput()
checkInput
in interface InputObject
public void draw(Graphics g, boolean coordsChanged)
draw
in class Drawable
g
- The graphics context in which the Drawble is to be drawn. (The drawing
can change the color in g, but should not permanently change font, painting mode, etc.
Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.protected void setOwnerData(DisplayCanvas canvas, CoordinateRect coords)
setOwnerData
in class Drawable
public void mousePressed(MouseEvent evt)
mousePressed
in interface MouseListener
public void mouseReleased(MouseEvent evt)
mouseReleased
in interface MouseListener
public void mouseDragged(MouseEvent evt)
mouseDragged
in interface MouseMotionListener
public void mouseClicked(MouseEvent evt)
mouseClicked
in interface MouseListener
public void mouseEntered(MouseEvent evt)
mouseEntered
in interface MouseListener
public void mouseExited(MouseEvent evt)
mouseExited
in interface MouseListener
public void mouseMoved(MouseEvent evt)
mouseMoved
in interface MouseMotionListener