{
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++ )
{
edge = edges.get( i );
if( edge.isVisible() )