I have a Graph< Potter, Edge> g where Edges belongs to three different classes that extends the Edge class (I use it to represent different type of interactions, like begin related, ask advices and so on...). I would like to color edges accordingly to what they represent, like having all Parental edges turn green and not display arrows. I have this transformer to change color, but it appears to change colors to all the edges:
Transformer<Edge, Paint> parental_color_yes = new Transformer<Edge, Paint>() {
@Override
public Paint transform(Edge s) {
return Color.GREEN;
}
};
If I change the type of the transformer to Transformer< Parental, Paint>, then my VisualizationViewer< Potter, Edge> vv complains that cannot accept such a transformer... should I add a new visualization viewer? or there is something wrong in the transformer?
EDITED after the reply:
parental_color_yes = new Transformer<Edge, Paint>() {
@Override
public Paint transform(Edge s) {
if (s instanceof Parental){
return Color.GREEN;
} else if (s instanceof Innovation) {
return Color.RED;
} else {
return Color.BLACK;
}
}
};
Thank you for the help!
Best regards, Simone
It needs to be an Edge-Paint Transformer. Inside the transform method, use an instanceof check to see what color to return.