Menu

#191 ObservableGraph not always being repainted

open
nobody
5
2012-08-09
2012-08-09
Anonymous
No

I was noticing that the view of my Graph was sometimes out of sync with the model. I guess a repaint() isn't always trigged.

Workaround (I only care about VERTICES), in my JPanel which contains the graphLayout and graphVisualiser fields.

public void setGraph(ObservableGraph<Note, Weight> graph) {
Preconditions.checkNotNull(graph);
Graph<Note, Weight> current = graphLayout.getGraph();
if (current != graph) {
if (current instanceof ObservableGraph) {
((ObservableGraph<Note, Weight>) current).removeGraphEventListener(this);
}
graphLayout.setGraph(graph);
graph.addGraphEventListener(this);
}
}

@Override
public void handleGraphEvent(GraphEvent<Note, Weight> evt) {
switch (evt.getType()) {
case VERTEX_ADDED:
case VERTEX_REMOVED:
graphVisualiser.repaint();
}
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB