|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component net.sourceforge.webcompmath.draw.Drawable net.sourceforge.webcompmath.draw.MouseTracker
public class MouseTracker
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
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. |
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
canvas, coords |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
MouseTracker()
Create a MouseTracker that responds to both clicks and drags. |
|
MouseTracker(boolean listenForDrags,
boolean undefinedWhenNotDragging)
Creates a mouse tracker. |
Method Summary | |
---|---|
void |
checkInput()
Set the values of the associated variables. |
void |
draw(java.awt.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(java.awt.event.MouseEvent evt)
Empty method, required by MouseListener interface. |
void |
mouseDragged(java.awt.event.MouseEvent evt)
Responds when the user drags the mouse. |
void |
mouseEntered(java.awt.event.MouseEvent evt)
Empty method, required by MouseMotionListener interface. |
void |
mouseExited(java.awt.event.MouseEvent evt)
Empty method, required by MouseMotionListener interface. |
void |
mouseMoved(java.awt.event.MouseEvent evt)
Empty method, required by MouseMotionListener interface. |
void |
mousePressed(java.awt.event.MouseEvent evt)
Responds when the user clicks the mouse in the rectangular area occupied by the CoordinateRect that contains this MouseTracker. |
void |
mouseReleased(java.awt.event.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. |
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
getVisible, needsRedraw, setVisible |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean listenForDrags
protected boolean undefinedWhenNotDragging
protected Controller onUserAction
protected boolean clampX
protected boolean clampY
Constructor Detail |
---|
public MouseTracker()
public MouseTracker(boolean listenForDrags, boolean undefinedWhenNotDragging)
listenForDrags
- true or falseundefinedWhenNotDragging
- true or falseMethod Detail |
---|
public Variable getXVar()
getXVar
in interface MouseVar
public Variable getYVar()
getYVar
in interface MouseVar
public void setListenForDrags(boolean listen)
listen
- true or falsepublic boolean getListenForDrags()
public void setUndefinedWhenNotDragging(boolean b)
b
- true or falsepublic boolean getUndefinedWhenNotDragging()
public void setOnUserAction(Controller onUserAction)
onUserAction
- controller to usepublic void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
c
- controller to notifypublic Controller getOnUserAction()
public void setClampX(boolean clamp)
clamp
- true or falsepublic boolean getClampX()
public void setClampY(boolean clamp)
clamp
- true or falsepublic boolean getClampY()
public void checkInput()
checkInput
in interface InputObject
public void draw(java.awt.Graphics g, boolean coordsChanged)
draw
in class Drawable
g
- graphics contextcoordsChanged
- true or falseprotected void setOwnerData(DisplayCanvas canvas, CoordinateRect coords)
setOwnerData
in class Drawable
canvas
- DisplayCanvas to usecoords
- CoordinateRect to usepublic void mousePressed(java.awt.event.MouseEvent evt)
mousePressed
in interface java.awt.event.MouseListener
evt
- event created when user presses mouse buttonpublic void mouseReleased(java.awt.event.MouseEvent evt)
mouseReleased
in interface java.awt.event.MouseListener
evt
- event created when user releases mouse buttonpublic void mouseDragged(java.awt.event.MouseEvent evt)
mouseDragged
in interface java.awt.event.MouseMotionListener
evt
- event created when user drags mousepublic void mouseClicked(java.awt.event.MouseEvent evt)
mouseClicked
in interface java.awt.event.MouseListener
evt
- the eventpublic void mouseEntered(java.awt.event.MouseEvent evt)
mouseEntered
in interface java.awt.event.MouseListener
evt
- the eventpublic void mouseExited(java.awt.event.MouseEvent evt)
mouseExited
in interface java.awt.event.MouseListener
evt
- the eventpublic void mouseMoved(java.awt.event.MouseEvent evt)
mouseMoved
in interface java.awt.event.MouseMotionListener
evt
- the event
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |