Package diva.canvas.interactor
Class DragInteractor
- java.lang.Object
-
- diva.canvas.interactor.AbstractInteractor
-
- diva.canvas.interactor.DragInteractor
-
- All Implemented Interfaces:
LayerListener
,LayerMotionListener
,Interactor
,java.util.EventListener
- Direct Known Subclasses:
BoundedDragInteractor
,ConnectorInteractor
,NodeDragInteractor
,SelectionDragger
public class DragInteractor extends AbstractInteractor
An interactor that responds to mouse drag events. It adds the notion of constraints, so that dragging can be limited to certain coordinates or "snapped" to suitable locations, and a "target" array, which contain the figure or figures that are dragged.- Version:
- $Id$
- Author:
- John Reekie
-
-
Constructor Summary
Constructors Constructor Description DragInteractor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLayerListener(LayerListener l)
Add the given layer listener to this interactor.void
appendConstraint(PointConstraint constraint)
Append a constraint to the list of constraints on this interactor.void
constrainPoint(java.awt.geom.Point2D p)
Constrain a point using the current constraints.void
fireLayerEvent(LayerEvent event)
Fire a layer event.boolean
getSelectiveEnabled()
Get the flag that says that the interactor responds only if the figure being moused on is selected.java.lang.Object[]
getTargetArray()
Get the target array.double
getX()
Get the current value of the X coordinate.double
getY()
Get the current value of the Y coordinate.void
mouseDragged(LayerEvent e)
Constrain the point and move the target if the mouse move.void
mousePressed(LayerEvent e)
Handle a mouse press on a figure or layer.void
mouseReleased(LayerEvent e)
Handle a mouse released event.void
prependConstraint(PointConstraint constraint)
Prepend a constraint to the list of constraints on this interactor.void
removeLayerListener(LayerListener l)
Remove the given layer listener from this interactor.boolean
setSelectiveEnabled(boolean s)
Set the flag that says that the interactor responds only if the figure being moused on is selected.void
setTargetArray(java.lang.Object[] arr)
Set the target that the interactor operates on.void
setup(LayerEvent e)
Initialize the interactor before a mouse-pressed event is processed.java.util.Iterator
targets()
Get an iterator over the target figures.void
translate(LayerEvent e, double x, double y)
Translate the target by the given distance.-
Methods inherited from class diva.canvas.interactor.AbstractInteractor
accept, getMouseFilter, isConsuming, isEnabled, isMotionEnabled, mouseClicked, mouseEntered, mouseExited, mouseMoved, setConsuming, setEnabled, setMotionEnabled, setMouseFilter
-
-
-
-
Method Detail
-
addLayerListener
public void addLayerListener(LayerListener l)
Add the given layer listener to this interactor. Any event that is received by this interactor will be passed on to the listener after it is handled by this interactor.- Parameters:
l
- The listener
-
appendConstraint
public void appendConstraint(PointConstraint constraint)
Append a constraint to the list of constraints on this interactor.- Parameters:
constraint
- The constraint.
-
constrainPoint
public void constrainPoint(java.awt.geom.Point2D p)
Constrain a point using the current constraints. The given point will be modified according to the current constraints. This method does not trigger constraint events. The caller must be careful to make a copy of the passed point if it is not guaranteed that changing the point will not affect other objects with a reference to it.- Parameters:
p
- The point
-
fireLayerEvent
public void fireLayerEvent(LayerEvent event)
Fire a layer event.- Parameters:
event
- The event
-
getSelectiveEnabled
public boolean getSelectiveEnabled()
Get the flag that says that the interactor responds only if the figure being moused on is selected. By default, this flag is false.- Returns:
- True if selective is enabled.
- See Also:
setSelectiveEnabled(boolean)
-
getTargetArray
public java.lang.Object[] getTargetArray()
Get the target array.- Returns:
- the target array
- See Also:
setTargetArray(Object[])
-
getX
public double getX()
Get the current value of the X coordinate.- Returns:
- The x value
-
getY
public double getY()
Get the current value of the Y coordinate.- Returns:
- the y value
-
mouseDragged
public void mouseDragged(LayerEvent e)
Constrain the point and move the target if the mouse move. The target movement is done by the translate() method, which can be overridden to change the behaviour. Nothing happens if the interactor is not enabled, or if it is "selective enabled" but not in the selection.- Specified by:
mouseDragged
in interfaceLayerListener
- Overrides:
mouseDragged
in classAbstractInteractor
- Parameters:
e
- the event
-
mousePressed
public void mousePressed(LayerEvent e)
Handle a mouse press on a figure or layer. Set the target to be the figure contained in the event. Call the setup() method in case there is additional setup to do, then constrain the point and remember it. Nothing happens if the interactor is not enabled, or if it is "selective enabled" but not in the selection.- Specified by:
mousePressed
in interfaceLayerListener
- Overrides:
mousePressed
in classAbstractInteractor
- Parameters:
e
- the event
-
mouseReleased
public void mouseReleased(LayerEvent e)
Handle a mouse released event. Nothing happens if the interactor is not enabled, if if it is "selective enabled" but not in the selection.- Specified by:
mouseReleased
in interfaceLayerListener
- Overrides:
mouseReleased
in classAbstractInteractor
- Parameters:
e
- The event
-
prependConstraint
public void prependConstraint(PointConstraint constraint)
Prepend a constraint to the list of constraints on this interactor.- Parameters:
constraint
- The constraint
-
removeLayerListener
public void removeLayerListener(LayerListener l)
Remove the given layer listener from this interactor.- Parameters:
l
- the listener
-
setSelectiveEnabled
public boolean setSelectiveEnabled(boolean s)
Set the flag that says that the interactor responds only if the figure being moused on is selected. By default, this flag is false; if set true, then the mouse methods check that the figure is contained in the selection model of that figure's selection interactor (if it has one).- Parameters:
s
- The value of selective enable- Returns:
- The value of the selective enabled flag
- See Also:
getSelectiveEnabled()
-
setTargetArray
public void setTargetArray(java.lang.Object[] arr)
Set the target that the interactor operates on. By default, this will be the figure obtained from the event, but this method can be used to set it to something else.- Parameters:
arr
- The array- See Also:
getTargetArray()
-
setup
public void setup(LayerEvent e)
Initialize the interactor before a mouse-pressed event is processed. This default implementation does nothing, but clients can override to cause it to perform some action, such as setting up constraints.- Parameters:
e
- The event
-
targets
public java.util.Iterator targets()
Get an iterator over the target figures.- Returns:
- An iterator
-
translate
public void translate(LayerEvent e, double x, double y)
Translate the target by the given distance. The first argument is the figure that was moused one. Any overriding methods should be aware that the interactor may in general be operating on multiple figures, and use the targets() method to get them.- Parameters:
e
- The eventx
- the x distancey
- the y distance
-
-