Package edu.hws.jcm.draw
Class Panner
java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.draw.Panner
- All Implemented Interfaces:
MouseListener
,MouseMotionListener
,Serializable
,EventListener
When a Panner object is added to a CoordinateRect, it becomes possible to
"grab" the coordinate rectangle and pan it (that is, slide it around by
moving it with the mouse). By default, the user must right-click-and-drag
to pan the coordinates, but this can be changed by providing an argument to
the constructor. It is possible to set a Controller to be notified each time
the mouse moves while the user is dragging. Alternatively, or in addition,
you can set a Controller to be notified when the user finishes dragging.
However, for the most part this is unnecessary, since the Drawables in the
CoordinateRect will for the most part redraw themselves properly when the
limits on the CoordinateRect change. However, if you have Computable objects
that depend on the coordinate limits, then they will need to be recomputed.
(This will be the case if you use value objects returned by the
getValueObject() method in the CoordinateRect class.)
A Panner, p, is inactive if its "visible" property has been set to false. (This is done by calling p.setVisible(false).)
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionPanner()
Create a Panner object that will let the user pan the CoordinateRect that contains the Panner by right-clicking and dragging (or, on Macintosh, command-clicking).Panner
(int modifierSet) Create a Panner object that will let the user click-and-drag to pan the CoordinateRect that contains the Panner. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Override the abstract draw() method from the Drawable class.Get the Controller that is notified when the user finishs a drag.Get the Controller that is notified when the user moves the mouse during a drag.void
mouseClicked
(MouseEvent evt) Responds to a mouse-click.void
mouseDragged
(MouseEvent evt) Responds to a mouse-drag.void
mouseEntered
(MouseEvent evt) Responds to a mouse-enter event.void
mouseExited
(MouseEvent evt) Responds to a mouse-exit event.void
mouseMoved
(MouseEvent evt) Responds when mouse moves.void
mousePressed
(MouseEvent evt) Responds to a mouse-press.void
mouseReleased
(MouseEvent evt) Responds to a mouse-release.void
Set a Controller that will be notified (by calling its compute method) whenever the user finishes a drag operation.void
Set a Controller that will be notified (by calling its compute method) whenever the user moves the mouse during a drag.protected void
setOwnerData
(DisplayCanvas canvas, CoordinateRect coords) Called when this object is added to a DisplayCanvas.Methods inherited from class edu.hws.jcm.draw.Drawable
getVisible, needsRedraw, setVisible
-
Constructor Details
-
Panner
public Panner()Create a Panner object that will let the user pan the CoordinateRect that contains the Panner by right-clicking and dragging (or, on Macintosh, command-clicking). -
Panner
public Panner(int modifierSet) Create a Panner object that will let the user click-and-drag to pan the CoordinateRect that contains the Panner. The mouse-pressed event must have the specfied set of modifiers set.- Parameters:
modifiers
- If the value is zero, the user drags the CoordinateRect by clicking without pressing any modifier keys. Otherwise, the value should be a combination of one or more of the constants MouseEvent.SHIFT_MASK, MouseEvent.CTRL_MASK, MouseEvent.META_MASK, and MouseEvent.ALT_MASK, or'ed together. (Remember that right-clicking sets META_MASK and clicking with a middle mouse button sets ALT_MASK.)
-
-
Method Details
-
setOnUserAction
Set a Controller that will be notified (by calling its compute method) whenever the user moves the mouse during a drag. If the value is null, no Controller is notified. Note that Drawables generally redraw themselvs correctly during the drag anyway, without any Controller being involved. Even if there are other things that need to be computed, it's probably better to compute them only once at the end of the drag. Do this by calling setOnFinishDrag() instead of this method. -
getOnUserAction
Get the Controller that is notified when the user moves the mouse during a drag. Returns null if no Controller is notified. -
setOnFinishDrag
Set a Controller that will be notified (by calling its compute method) whenever the user finishes a drag operation. If the value is null, no Controller is notified. You only need to do this if you have to recompute some object that depends on the coordinate limits of the CoordinateRect that contains this Panner object. Presumably, this will be an object that depends on one if the Value objects returned by the getValueObject() method in the CoordinatRect class. -
getOnFinishDrag
Get the Controller that is notified when the user finishs a drag. Returns null if no Controller is notified. -
setOwnerData
Called when this object is added to a DisplayCanvas. Not meant to be called directly.- Overrides:
setOwnerData
in classDrawable
-
draw
Override the abstract draw() method from the Drawable class. This is defined to be empty since a Panner object has no visible representation.- Specified by:
draw
in classDrawable
- Parameters:
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.
-
mousePressed
Responds to a mouse-press. Not meant to be called directly.- Specified by:
mousePressed
in interfaceMouseListener
-
mouseDragged
Responds to a mouse-drag. Not meant to be called directly.- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseReleased
Responds to a mouse-release. Not meant to be called directly.- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseClicked
Responds to a mouse-click. Not meant to be called directly. Defined to be empty in this class.- Specified by:
mouseClicked
in interfaceMouseListener
-
mouseMoved
Responds when mouse moves. Not meant to be called directly. Defined to be empty in this class.- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
mouseEntered
Responds to a mouse-enter event. Not meant to be called directly. Defined to be empty in this class.- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
Responds to a mouse-exit event. Not meant to be called directly. Defined to be empty in this class.- Specified by:
mouseExited
in interfaceMouseListener
-