VisualizationViewer vv = (VisualizationViewer)e.getSource();
PickSupport pickSupport = vv.getPickSupport();
PickedState pickedState = vv.getPickedState();
if(pickSupport != null && pickedState != null) {
Layout layout = vv.getGraphLayout();
if(e.getModifiers() == getModifiers()) {
vv.addPostRenderPaintable(lensPaintable);
rect.setFrameFromDiagonal(down,down);
// p is the screen point for the mouse event
Point2D p = e.getPoint();
// take away the view transform
Point2D ip = vv.inverseViewTransform(p);
vertex = pickSupport.getVertex(ip.getX(), ip.getY());
if(vertex != null) {
if(pickedState.isPicked(vertex) == false) {
pickedState.clearPickedVertices();
pickedState.pick(vertex, true);
vv.fireStateChanged();
}
// layout.getLocation applies the layout transformer so
// q is transformed by the layout transformer only
Point2D q = layout.getLocation(vertex);
// transform the mouse point to graph coordinate system
Point2D gp = vv.inverseLayoutTransform(ip);
offsetx = (float) (gp.getX()-q.getX());
offsety = (float) (gp.getY()-q.getY());
} else if(isPickingEdges() &&
(edge = pickSupport.getEdge(ip.getX(), ip.getY())) != null) {
pickedState.clearPickedEdges();
pickedState.pick(edge, true);
} else {
pickedState.clearPickedEdges();
pickedState.clearPickedVertices();
vv.fireStateChanged();
}
} else if(e.getModifiers() == (addToSelectionModifiers)) {
vv.addPostRenderPaintable(lensPaintable);
rect.setFrameFromDiagonal(down,down);
Point2D p = e.getPoint();
// remove view transform
Point2D ip = vv.inverseViewTransform(p);
vertex = pickSupport.getVertex(ip.getX(), ip.getY());
if(vertex != null) {
boolean wasThere = pickedState.pick(vertex, !pickedState.isPicked(vertex));
if(wasThere) {
vertex = null;
} else {
// layout.getLocation applies the layout transformer so
// q is transformed by the layout transformer only
Point2D q = layout.getLocation(vertex);
// translate mouse point to graph coord system
Point2D gp = vv.inverseLayoutTransform(ip);
offsetx = (float) (gp.getX()-q.getX());
offsety = (float) (gp.getY()-q.getY());