| java.lang.Object edu.hws.jcm.draw.Drawable edu.hws.jcm.draw.MouseTracker
MouseTracker | public class MouseTracker extends Drawable implements MouseListener,MouseMotionListener,InputObject(Code) | | A MouseTracker can be added to a CoordinateRect in a DisplayCanvas to respond to user
mouse actions in the rectangular area occupied by the CoordinateRect. Two
Variable objects, which can be retrieved by calling getXVar() and getYVar(),
represent the location of the most recent mouse action in terms of the coordinates
of the CoordinateRect. Note that these variables are Tieable objects, so they
can be synchronized with other means of inputting the same information.
The default names of the variables, if you don't change them, are "xMouse"
and "yMouse".
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.
|
Field Summary | |
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 Summary | |
public | MouseTracker() Create a MouseTracker that responds to both clicks and drags. | public | MouseTracker(boolean listenForDrags, boolean undefinedWhenNotDragging) Creates a mouse tracker. |
Method Summary | |
public void | checkInput() Set the values of the associated variables. | public void | draw(Graphics g, boolean coordsChanged) A MouseTracker doesn't actually draw anything, but this method is required in
a Drawable object. | public boolean | getClampX() Get the "clampX" property of the MouseTracker. | public boolean | getClampY() Get the "clampY" property of the MouseTracker. | public boolean | getListenForDrags() Gets the "listenForDrags" property of the MouseTracker, which determines
if the MouseTracker responds to both clicks and drags, or only to clicks. | public Controller | getOnUserAction() Get the Controller that responds when a user mouse action is detected by this MouseTracker. | public boolean | getUndefinedWhenNotDragging() Gets the "undefinedWhenNotDragging" property of the MouseTracker. | public Variable | getXVar() Get the variable whose value represents the x-coordinate of the MouseTracker.
Note that this variable implements the Tieable interface, so can legally
be type-cast to type Tieable. | public Variable | getYVar() Get the variable whose value represents the y-coordinate of the MouseTracker.
Note that this variable implements the Tieable interface, so can legally
be type-cast to type Tieable. | public void | mouseClicked(MouseEvent evt) Empty method, required by MouseListener interface. | public void | mouseDragged(MouseEvent evt) Responds when the user drags the mouse. | public void | mouseEntered(MouseEvent evt) Empty method, required by MouseMotionListener interface. | public void | mouseExited(MouseEvent evt) Empty method, required by MouseMotionListener interface. | public void | mouseMoved(MouseEvent evt) Empty method, required by MouseMotionListener interface. | public void | mousePressed(MouseEvent evt) Responds when the user clicks the mouse in the rectangular
area occupied by the CoordinateRect that contains this MouseTracker.
Since the MouseTracker listens for clicks on the whole DisplayCanvas
and the CoordinateRect might only occupy part of that, it is necessary
to check whether the user click was in that rect. | public void | mouseReleased(MouseEvent evt) Responds when the user releases the mouse. | public void | notifyControllerOnChange(Controller c) Method required by InputObject interface; in this class, it simply calls
setOnUserAction(c). | public void | setClampX(boolean clamp) Set the "clampX" property of the MouseTracker. | public void | setClampY(boolean clamp) Set the "clampY" property of the MouseTracker. | public void | setListenForDrags(boolean listen) Sets the "listenForDrags" property of the MouseTracker. | public 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. | public void | setUndefinedWhenNotDragging(boolean b) Sets the "undefinedWhenNotDragging" property of the MouseTracker. |
clampX | protected boolean clampX(Code) | | 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.
|
clampY | protected boolean clampY(Code) | | 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.
|
listenForDrags | protected boolean listenForDrags(Code) | | If true, the MouseTracker responds to both clicks and drags.
If false, it responds only to clicks.
|
onUserAction | protected Controller onUserAction(Code) | | 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.
|
undefinedWhenNotDragging | protected boolean undefinedWhenNotDragging(Code) | | If true, the values of the associated variables are
undefined except during the time that the user is
clicking and dragging the mouse. This is ignored
if listenForDrags is false.
|
MouseTracker | public MouseTracker()(Code) | | Create a MouseTracker that responds to both clicks and drags. The values of the
associated variables remain defined even after the user stops dragging.
|
MouseTracker | public MouseTracker(boolean listenForDrags, boolean undefinedWhenNotDragging)(Code) | | Creates a mouse tracker. The first parameter specifies whether the values of
the variables change when the user drags the mouse, or only when the user clicks.
The second parameter is only used if the first is true. It specifies whether
the values of the variables become undefined after the user stops dragging the
mouse.
|
checkInput | public void checkInput()(Code) | | Set the values of the associated variables. This is part of the InputObject interface,
and it is meant to be called by a Controller.
|
draw | public void draw(Graphics g, boolean coordsChanged)(Code) | | A MouseTracker doesn't actually draw anything, but this method is required in
a Drawable object.
|
getClampX | public boolean getClampX()(Code) | | Get the "clampX" property of the MouseTracker.
|
getClampY | public boolean getClampY()(Code) | | Get the "clampY" property of the MouseTracker.
|
getListenForDrags | public boolean getListenForDrags()(Code) | | Gets the "listenForDrags" property of the MouseTracker, which determines
if the MouseTracker responds to both clicks and drags, or only to clicks.
|
getOnUserAction | public Controller getOnUserAction()(Code) | | Get the Controller that responds when a user mouse action is detected by this MouseTracker.
|
getUndefinedWhenNotDragging | public boolean getUndefinedWhenNotDragging()(Code) | | Gets the "undefinedWhenNotDragging" property of the MouseTracker.
|
getXVar | public Variable getXVar()(Code) | | Get the variable whose value represents the x-coordinate of the MouseTracker.
Note that this variable implements the Tieable interface, so can legally
be type-cast to type Tieable. It can be tied to other objects that
implement the Tieable and Value interfaces to synchronize their values.
|
getYVar | public Variable getYVar()(Code) | | Get the variable whose value represents the y-coordinate of the MouseTracker.
Note that this variable implements the Tieable interface, so can legally
be type-cast to type Tieable. It can be tied to other objects that
implement the Tieable and Value interfaces to synchronize their values.
|
mouseClicked | public void mouseClicked(MouseEvent evt)(Code) | | Empty method, required by MouseListener interface.
|
mouseDragged | public void mouseDragged(MouseEvent evt)(Code) | | Responds when the user drags the mouse. This is not meant to be called directly.
|
mouseEntered | public void mouseEntered(MouseEvent evt)(Code) | | Empty method, required by MouseMotionListener interface.
|
mouseExited | public void mouseExited(MouseEvent evt)(Code) | | Empty method, required by MouseMotionListener interface.
|
mouseMoved | public void mouseMoved(MouseEvent evt)(Code) | | Empty method, required by MouseMotionListener interface.
|
mousePressed | public void mousePressed(MouseEvent evt)(Code) | | Responds when the user clicks the mouse in the rectangular
area occupied by the CoordinateRect that contains this MouseTracker.
Since the MouseTracker listens for clicks on the whole DisplayCanvas
and the CoordinateRect might only occupy part of that, it is necessary
to check whether the user click was in that rect. This is not meant to be called directly.
|
mouseReleased | public void mouseReleased(MouseEvent evt)(Code) | | Responds when the user releases the mouse. This is not meant to be called directly.
|
notifyControllerOnChange | public void notifyControllerOnChange(Controller c)(Code) | | Method required by InputObject interface; in this class, it simply calls
setOnUserAction(c). This is meant to be called by JCMPanel.gatherInputs().
|
setClampX | public void setClampX(boolean clamp)(Code) | | Set the "clampX" property of the MouseTracker.
If set to true, which is the default, the value of
the variable associated with the horizontal position of
the mouse is clamped to lie within the containing
CoordinateRect.
|
setClampY | public void setClampY(boolean clamp)(Code) | | Set the "clampY" property of the MouseTracker.
If set to true, which is the default, the value of
the variable associated with the vertical position of
the mouse is clamped to lie within the containing
CoordinateRect.
|
setListenForDrags | public void setListenForDrags(boolean listen)(Code) | | Sets the "listenForDrags" property of the MouseTracker.
If set to true, then the MouseTracker responds to both clicks and drags if false,
it responds only to clicks.
|
setOnUserAction | public void setOnUserAction(Controller onUserAction)(Code) | | Set a Controller to respond to user mouse actions tracked
by this MouseTracker. The MouseTracker should also be added
to the Controller, so that the values of its variables will
actually change when a user action occurs.
|
setOwnerData | protected void setOwnerData(DisplayCanvas canvas, CoordinateRect coords)(Code) | | This is called automatically by CoordinateRect when the
MouseTracker is added to the CoordinateRect. It is not
meant to be used directly.
|
setUndefinedWhenNotDragging | public void setUndefinedWhenNotDragging(boolean b)(Code) | | Sets the "undefinedWhenNotDragging" property of the MouseTracker.
This is ignored if the MouseTracker is not listening for drags.
If set to true, the values of the variables associated with this
variable become undefined when the user is not dragging.
|
|
|