color = shortestPathPanel.getColor();
float[] colorArray = new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f};
Node targetNode = n;
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
AbstractShortestPathAlgorithm algorithm;
if (gc.getModel().getGraphVisible() instanceof DirectedGraph) {
algorithm = new BellmanFordShortestPathAlgorithm((DirectedGraph) gc.getModel().getGraphVisible(), sourceNode);
} else {
algorithm = new DijkstraShortestPathAlgorithm(gc.getModel().getGraphVisible(), sourceNode);
}
algorithm.compute();
double distance;
if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
targetNode.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
VizController.getInstance().selectNode(targetNode);
Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
Node predecessor = algorithm.getPredecessor(targetNode);
while (predecessorEdge != null && predecessor != sourceNode) {
predecessorEdge.getEdgeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
VizController.getInstance().selectEdge(predecessorEdge);
predecessor.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
VizController.getInstance().selectNode(predecessor);
predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
predecessor = algorithm.getPredecessor(predecessor);
}
predecessorEdge.getEdgeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
VizController.getInstance().selectEdge(predecessorEdge);
sourceNode.getNodeData().setColor(colorArray[0], colorArray[1], colorArray[2]);
VizController.getInstance().selectNode(sourceNode);