diva.canvas.interactor
Class DragInteractor

java.lang.Object
  extended by diva.canvas.interactor.AbstractInteractor
      extended by diva.canvas.interactor.DragInteractor
All Implemented Interfaces:
LayerListener, LayerMotionListener, Interactor, java.util.EventListener
Direct Known Subclasses:
AttributeBoundsManipulator.Resizer, BoundedDragInteractor, BoundsManipulator.Resizer, CircleManipulator.Resizer, ConnectorInteractor, NodeDragInteractor, PathManipulator.Resizer, 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: DragInteractor.java 53042 2009-04-10 20:31:21Z cxh $
Author:
John Reekie

Field Summary
private  java.util.ArrayList<PointConstraint> _constraints
          The set of constraints
private  LayerListener _layerListener
          Layer listeners
private  double _prevX
           
private  double _prevY
           
private  boolean _selectiveEnabled
           
private  java.lang.Object[] _targetArray
          The target array.
 
Constructor Summary
DragInteractor()
           
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_constraints

private java.util.ArrayList<PointConstraint> _constraints
The set of constraints


_targetArray

private transient java.lang.Object[] _targetArray
The target array. This is an array of objects to make it easier to use with SelectionModel.


_layerListener

private transient LayerListener _layerListener
Layer listeners


_prevX

private double _prevX

_prevY

private double _prevY

_selectiveEnabled

private boolean _selectiveEnabled
Constructor Detail

DragInteractor

public DragInteractor()
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.


appendConstraint

public void appendConstraint(PointConstraint constraint)
Append a constraint to the list of constraints on this interactor.


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.


fireLayerEvent

public void fireLayerEvent(LayerEvent event)
Fire a layer 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.


getTargetArray

public java.lang.Object[] getTargetArray()
Get the target array.


getX

public double getX()
Get the current value of the X coordinate


getY

public double getY()
Get the current value of the Y coordinate


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 interface LayerListener
Overrides:
mouseDragged in class AbstractInteractor

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 interface LayerListener
Overrides:
mousePressed in class AbstractInteractor

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 interface LayerListener
Overrides:
mouseReleased in class AbstractInteractor

prependConstraint

public void prependConstraint(PointConstraint constraint)
Prepend a constraint to the list of constraints on this interactor.


removeLayerListener

public void removeLayerListener(LayerListener l)
Remove the given layer listener from this interactor.


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).


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.


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.


targets

public java.util.Iterator targets()
Get an iterator over the target figures.


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.