package prefuse.controls;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import prefuse.Display;
import prefuse.action.layout.Layout;
import prefuse.visual.VisualItem;
/**
* Follows the mouse cursor, updating the anchor parameter for any number
* of layout instances to match the current cursor position. Will also
* run a given activity in response to cursor updates.
*
* @author jeffrey heer
*/
public class AnchorUpdateControl extends ControlAdapter {
private boolean m_anchorOverItem;
private Layout[] m_layouts;
private String m_action;
private Point2D m_tmp = new Point2D.Double();
/**
* Create a new AnchorUpdateControl.
* @param layout the layout for which to update the anchor point
*/
public AnchorUpdateControl(Layout layout) {
this(layout,null);
}
/**
* Create a new AnchorUpdateControl.
* @param layout the layout for which to update the anchor point
* @param action the name of an action to run upon anchor updates
*/
public AnchorUpdateControl(Layout layout, String action) {
this(new Layout[] {layout}, action);
}
/**
* Create a new AnchorUpdateControl.
* @param layout the layout for which to update the anchor point
* @param action the name of an action to run upon anchor updates
* @param overItem indicates if anchor update events should be processed
* while the mouse cursor is hovered over a VisualItem.
*/
public AnchorUpdateControl(Layout layout, String action, boolean overItem)
{
this(new Layout[] {layout}, action, overItem);
}
/**
* Create a new AnchorUpdateControl.
* @param layout the layouts for which to update the anchor point
* @param action the name of an action to run upon anchor updates
*/
public AnchorUpdateControl(Layout[] layout, String action) {
this(layout, action, true);
}
/**
* Create a new AnchorUpdateControl.
* @param layout the layouts for which to update the anchor point
* @param action the name of an action to run upon anchor updates
* @param overItem indicates if anchor update events should be processed
* while the mouse cursor is hovered over a VisualItem.
*/
public AnchorUpdateControl(Layout[] layout, String action, boolean overItem)
{
m_layouts = (Layout[])layout.clone();
m_action = action;
m_anchorOverItem = overItem;
}
// ------------------------------------------------------------------------
/**
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent e) {
for ( int i=0; i