I have an SparseMultigraph< Node, Edge > g where edges have two attributes:
int weight;
ArrayList<Date> time;
I would like to filter the graph according to weight and time independently. Say I start filtering out according to weight using a JSlider called weightSlider (I am in Netbeans and Swing):
private void weightSliderMouseReleased(java.awt.event.MouseEvent evt) {
// filter network according to weight:
Predicate<Edge> edgeAboveWeight = new Predicate<Edge>() {
@Override
public boolean evaluate(Edge e) {
return e.getWeight() >= weightSlider.getValue();
}
};
EdgePredicateFilter<Node, Edge> edgePredicateFilter = new EdgePredicateFilter<>(edgeAboveWeight);
Graph<Node, Edge> transform = edgePredicateFilter.transform(g);
}
My question is: how do I push the new graph in the visualization, preserving the node position?
Since it is the first time I attempt to do something like that, I might have missed a simpler way to achieve my goal, so any suggestion is more than welcome!
EDIT: I succeeded to implement this with:
private void weightSliderMouseReleased(java.awt.event.MouseEvent evt) {
// filter network according to weight:
Predicate<Edge> edgeAboveWeight = new Predicate<Edge>() {
@Override
public boolean evaluate(Edge e) {
return e.getWeight() >= weightSlider.getValue();
}
};
EdgePredicateFilter<Node, Edge> edgePredicateFilter = new EdgePredicateFilter<>(edgeAboveWeight);
Graph<Node, Edge> transform = edgePredicateFilter.transform(g);
layout.setGraph(transform);
vv.validate();
vv.repaint();
}
Still don't know if it's the most efficient way, but it works...