return;
}
ImageCacher.updateConstants( request );
DNVGraph graph = pb.getGraph();
int level = (int)pb.getLevel();
// pb.setHasBeenDisplayed( true );
int width = -1;
width = getWidth( request, width );
int height = -1;
height = getHeight( request, height );
boolean overview = false;
overview = getOverview( request, overview );
if( width == -1 )
width = (int)pb.getWidth();
if( height == -1 )
height = (int)pb.getHeight();
double minX = 0;
double minY = 0;
double maxX = 1;
double maxY = 1;
String minXStr = request.getParameter( "minX" );
if( minXStr != null && !minXStr.equals( "" ) )
{
minX = getMinX( request, minX );
pb.setMinX( minX );
}
String minYStr = request.getParameter( "minY" );
if( minYStr != null && !minYStr.equals( "" ) )
{
minY = getMinY( request, minY );
pb.setMinY( minY );
}
String maxXStr = request.getParameter( "maxX" );
if( maxXStr != null && !maxXStr.equals( "" ) )
{
maxX = getMaxX( request, maxX );
pb.setMaxX( maxX );
}
String maxYStr = request.getParameter( "maxY" );
if( maxYStr != null && !maxYStr.equals( "" ) )
{
maxY = getMaxY( request, maxY );
pb.setMaxY( maxY );
}
String renderingStr = request.getParameter( "r" );
int rendering = BufferedImage.TYPE_BYTE_INDEXED;
if( renderingStr != null && renderingStr.equals( "qual" ) )
{
rendering = BufferedImage.TYPE_INT_RGB;
}
Timer pickingTimer = new Timer( Timer.MILLISECONDS );
// ------------------------------------
// interaction with static image
// ------------------------------------
String mouseDownXstr = request.getParameter( "mouseDownX" );
// boolean mouseDown = false;
if( mouseDownXstr != null && !mouseDownXstr.equals( "" ) )
{
// mouseDown = true;
pickingTimer.setStart();
// drag closest node to this position
int mouseDownX = Integer.parseInt( mouseDownXstr );
int mouseDownY = Integer.parseInt( request.getParameter( "mouseDownY" ) );
// drag it to here
int mouseUpX = Integer.parseInt( request.getParameter( "mouseUpX" ) );
int mouseUpY = Integer.parseInt( request.getParameter( "mouseUpY" ) );
boolean sameNode = Boolean.parseBoolean( request.getParameter( "sameNode" ) );
boolean ctrlPressed = Boolean.parseBoolean( request.getParameter( "ctrlPressed" ) );
// - - - - - - - - - - -
// find closest node
// - - - - - - - - - - -
// float maxDepth = Integer.MAX_VALUE;
double globalMinX = GraphFunctions.getMinXPosition( graph, level, true );
double globalMaxX = GraphFunctions.getMaxXPosition( graph, level, true );
double globalMinY = GraphFunctions.getMinYPosition( graph, level, true );
double globalMaxY = GraphFunctions.getMaxYPosition( graph, level, true );
if( globalMinY == globalMaxY )
{
globalMinY -= 10;
globalMaxY += 10;
}
if( globalMinX == globalMaxX )
{
globalMinX -= 10;
globalMaxX += 10;
}
double yBuffer = ( globalMaxY - globalMinY ) * pb.getWhiteSpaceBuffer();
double xBuffer = ( globalMaxX - globalMinX ) * pb.getWhiteSpaceBuffer();
DNVNode selectedNode = null;
globalMaxY += yBuffer;
globalMinY -= yBuffer;
globalMaxX += xBuffer;
globalMinX -= xBuffer;
if( !sameNode )
{
List<DNVNode> nodes = graph.getNodes( level );
SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
Collections.sort( nodes, sbls );
DNVNode node;
Vector2D screenPosition;
double distance;
double minDistance = Integer.MAX_VALUE;
int nodeI = -1;
int distX = 0; // dist b/w this node and mouse click
int distY = 0;
// Check if user clicked on a solid node label
for( int i = nodes.size() - 1; i >= 0; i-- )
{
node = nodes.get( i );
if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
{
screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY,
width, height, node.getPosition( true ) );
ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null,
(int)Math.round( pb.getNodeSize() * node.getRadius() ), node.getLabel( pb.isInterpolationLabels() ), pb
.isCurvedLabels()
|| node.isCurvedLabel(), pb.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb
.getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
&& mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
{
distX = (int)( mouseDownX - screenPosition.getX() );
distY = (int)( mouseDownY - screenPosition.getY() );
node.setProperty( "distX", "" + distX );
node.setProperty( "distY", "" + distY );
minDistance = 0;
nodeI = i;
break;
}
}
}
if( nodeI == -1 )
{
// loop thru all nodes to find closest node
for( int i = nodes.size() - 1; i >= 0; i-- )
{
node = nodes.get( i );
if( node.isVisible() )
{
screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
maxY, width, height, node.getPosition( true ) );
// find node closest to mouseDown
distX = (int)( mouseDownX - screenPosition.getX() );
distY = (int)( mouseDownY - screenPosition.getY() );
distance = distX * distX + distY * distY;
if( distance < minDistance )
{
node.setProperty( "distX", "" + distX );
node.setProperty( "distY", "" + distY );
minDistance = distance;
nodeI = i;
}
}
}
}
if( nodes.size() > 0 && nodeI != -1 )
{
node = nodes.get( nodeI );
double nodeWidth;
nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
// check if selected node is close enough to mouseDown
if( Settings.DEBUG )
System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
if( Math.sqrt( minDistance ) >= nodeWidth )
{
// Still no node selected so check nodes with faded
// labels
for( int i = nodes.size() - 1; i >= 0; i-- )
{
node = nodes.get( i );
if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null
&& Float.parseFloat( node.getProperty( "faded" ) ) > 0.1 )
{
screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX,
minY, maxY, width, height, node.getPosition( true ) );
ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition,
null, (int)Math.round( pb.getNodeSize() * node.getRadius() ),
node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb
.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(),
pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
&& mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
{
distX = (int)( mouseDownX - screenPosition.getX() );
distY = (int)( mouseDownY - screenPosition.getY() );
node.setProperty( "distX", "" + distX );
node.setProperty( "distY", "" + distY );
minDistance = 0;
nodeI = i;
break;
}
}
}
}
node = nodes.get( nodeI );
nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
// check if selected node is close enough to mouseDown
if( Settings.DEBUG )
System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
if( Math.sqrt( minDistance ) < nodeWidth )
{
// if( node.isSelected() )
// {
// sameNode = true;
// }
pb.setSelectedNode( node, ctrlPressed );
selectedNode = node;
}
else
{
if( pb.getSelectedNode() != null )
{
pb.setSelectedNode( null, ctrlPressed );
// runDocumentTopicsCircularLayout( request, pb, graph, level );
}
}
}
if( selectedNode == null )
{
minDistance = Integer.MAX_VALUE;
List<DNVEdge> edges = graph.getEdges( level );
DNVEdge edge;
Vector2D screenPosition2;
int edgeI = 0;
for( int i = 0; i < edges.size(); i++ )
{