Anonymous - 2012-08-01

this one is ready for instant drop-in to the existing class ;-) (some use of Guava)

Incidentally, since edges/vertices are By Design supposed to be unique in a Graph, I would strongly recommend changing all Graph APIs to return Set instead of Collection.

public void render(RenderContext<V, E> renderContext, Layout<V, E> layout) {
try {
Set<E> edges = Sets.newHashSet(layout.getGraph().getEdges());
Set<E> pickedEdges = renderContext.getPickedEdgeState().getPicked();
paintEdges(renderContext, layout, Sets.difference(edges, pickedEdges));
paintEdges(renderContext, layout, pickedEdges);

Set<V> vertices = Sets.newHashSet(layout.getGraph().getVertices());
Set<V> pickedVertices = renderContext.getPickedVertexState().getPicked();
paintVertices(renderContext, layout, Sets.difference(vertices, pickedVertices));
paintVertices(renderContext, layout, pickedVertices);
} catch (ConcurrentModificationException cme) {
renderContext.getScreenDevice().repaint();
}
}

private void paintEdges(RenderContext<V, E> renderContext, Layout<V, E> layout, Collection<E> edges) {
for (E e : edges) {
renderEdge(renderContext, layout, e);
renderEdgeLabel(renderContext, layout, e);
}
}

private void paintVertices(RenderContext<V, E> renderContext, Layout<V, E> layout, Collection<V> vertices) {
for (V v : vertices) {
renderVertex(renderContext, layout, v);
renderVertexLabel(renderContext, layout, v);
}
}