I have two types edges in my supply chain model: demand_links and supply_links. the default color is gray for all links. But I want to change the color of demand_links to red each time the attribute of the demand_link is changed (Note:the edge is the custom edge agent through edge creator). How to do this?
Below is my codes for simple test and it didn't work.
public class EdgeStyle2D extends DefaultStyleOGL2D {
@Override
public Color getColor(Object o){
// if (((CustomEdge) o).getCurrent_dl() == 1) {
// return Color.RED;
// }
// else {
// return Color.BLACK;
// }
if (o instanceof Distributor)
return Color.YELLOW;
return null;
}
}
I get the error when initialize.
Caused by: java.lang.ClassCastException: class supplyChainSystem.EdgeStyle2D cannot be cast to class repast.simphony.visualizationOGL2D.EdgeStyleOGL2D (supplyChainSystem.EdgeStyle2D and repast.simphony.visualizationOGL2D.EdgeStyleOGL2D are in unnamed module of loader repast.simphony.plugin.ExtendablePluginClassLoader @61af1510)
For styling links in this way, you should follow the example in the zombies.style.LinkStyle class within the Zombies_Demo model. Here's what the relevant parts of that class look like:
public class LinkStyle implements EdgeStyleOGL2D {
public Color getColor(RepastEdge<?> edge) {
BaseLink<?> link = (BaseLink<?>) edge;
return ReLogoSupport.lookupColor(link.getColor());
}
public int getLineWidth(RepastEdge<?> edge) {
return (int) (Math.abs(edge.getWeight()));
}
}
And you would use a class like this for the network (as opposed to agent) style.