diva.canvas.connector
Class ConnectorInteractor

java.lang.Object
  extended by diva.canvas.interactor.AbstractInteractor
      extended by diva.canvas.interactor.DragInteractor
          extended by diva.canvas.connector.ConnectorInteractor
All Implemented Interfaces:
LayerListener, LayerMotionListener, Interactor, java.util.EventListener
Direct Known Subclasses:
ArcInteractor

public class ConnectorInteractor
extends DragInteractor

An interactor for dragging one end of a connector. This is a utility class designed for use in conjunction with ConnectorManipulator.

Version:
$Id: ConnectorInteractor.java 53042 2009-04-10 20:31:21Z cxh $
Author:
John Reekie, Steve Neuendorffer

Field Summary
private  Connector _connector
          The connector
private  java.util.ArrayList<ConnectorListener> _connectorListeners
          The list of connector listeners
private  GrabHandle _handle
          The handle being grabbed
private  ConnectorManipulator _manipulator
          The manipulator this interactor belongs to
private  Figure _target
          The current target object if we are over one, else null
 
Constructor Summary
ConnectorInteractor(ConnectorManipulator m)
          Create a new interactor to be used with the given manipulator
 
Method Summary
protected  void _notifyConnectorListeners(ConnectorEvent event, int id)
          Notify registered connector listeners of the specified event.
 void addConnectorListener(ConnectorListener l)
          Add a connector listener.
private  void attach(Site site)
          Detach the connector from its current site and attach it to the given site.
private  void detach(double x, double y)
          Detach the connector from its current site and attach it to a new autonomous site at the given coordinates
private  Site findSite(Figure f, double x, double y)
          Utility function to find a site.
private  Site findSite(Site s, double x, double y)
          Utility function to find a site.
protected  void fireConnectorEvent(int id)
          Fire a connector event to all connector listeners.
 Connector getConnector()
          Get the current connector.
 GrabHandle getHandle()
          Get the current grab handle.
 Figure getTarget()
          Get the current target figure.
 void mouseReleased(LayerEvent event)
          Handle a mouse-released event.
 void removeConnectorListener(ConnectorListener l)
          Remove a connector listener.
 void setup(LayerEvent e)
          Initialize the interactor when a grab-handle is grabbed.
 void snapToSite(FigureContainer container, java.awt.geom.Rectangle2D hitRect)
          Pick a site using the connector target and then snap to it.
 void translate(LayerEvent e, double dx, double dy)
          Respond to translation of the grab-handle.
 
Methods inherited from class diva.canvas.interactor.DragInteractor
addLayerListener, appendConstraint, constrainPoint, fireLayerEvent, getSelectiveEnabled, getTargetArray, getX, getY, mouseDragged, mousePressed, prependConstraint, removeLayerListener, setSelectiveEnabled, setTargetArray, targets
 
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

_connector

private Connector _connector
The connector


_handle

private GrabHandle _handle
The handle being grabbed


_manipulator

private ConnectorManipulator _manipulator
The manipulator this interactor belongs to


_target

private Figure _target
The current target object if we are over one, else null


_connectorListeners

private java.util.ArrayList<ConnectorListener> _connectorListeners
The list of connector listeners

Constructor Detail

ConnectorInteractor

public ConnectorInteractor(ConnectorManipulator m)
Create a new interactor to be used with the given manipulator

Method Detail

addConnectorListener

public void addConnectorListener(ConnectorListener l)
Add a connector listener. The listener will be notified on all significant events.


attach

private void attach(Site site)
Detach the connector from its current site and attach it to the given site.


detach

private void detach(double x,
                    double y)
Detach the connector from its current site and attach it to a new autonomous site at the given coordinates


findSite

private Site findSite(Figure f,
                      double x,
                      double y)
Utility function to find a site. Takes account of whether we are dragging the head or the tail. Don't find a site if the figure is the same as at the already-connected end of the connector. (Note: this needs to be parameterized, as sometimes snapping to a site on the same figure is useful.)


findSite

private Site findSite(Site s,
                      double x,
                      double y)
Utility function to find a site. Takes account of whether we are dragging the head or the tail.


fireConnectorEvent

protected void fireConnectorEvent(int id)
Fire a connector event to all connector listeners.


getConnector

public Connector getConnector()
Get the current connector. If there isn't one, return null.


getHandle

public GrabHandle getHandle()
Get the current grab handle.


getTarget

public Figure getTarget()
Get the current target figure. If there isn't one, return null.


mouseReleased

public void mouseReleased(LayerEvent event)
Handle a mouse-released event. This overrides the inherited method to generate a connector-dropped event.

Specified by:
mouseReleased in interface LayerListener
Overrides:
mouseReleased in class DragInteractor

removeConnectorListener

public void removeConnectorListener(ConnectorListener l)
Remove a connector listener.


setup

public void setup(LayerEvent e)
Initialize the interactor when a grab-handle is grabbed.

Overrides:
setup in class DragInteractor

snapToSite

public void snapToSite(FigureContainer container,
                       java.awt.geom.Rectangle2D hitRect)
Pick a site using the connector target and then snap to it. Container is the container to pick in; x, y are the coordinates of the drag point in the transform context of that container.


translate

public void translate(LayerEvent e,
                      double dx,
                      double dy)
Respond to translation of the grab-handle. Move the grab-handle, and adjust the connector accordingly, snapping it to a suitable target if possible.

Overrides:
translate in class DragInteractor

_notifyConnectorListeners

protected void _notifyConnectorListeners(ConnectorEvent event,
                                         int id)
Notify registered connector listeners of the specified event.

Parameters:
event - The event.
id - The id of the event (dragged, dropped, etc.).