2

I have to change dynamically the border color of an agent. The agent is represented as the default circle on the display. The displayed color has to change according to a boolean variable defined inside the agent Class. When the agent is created and displayed for the first time, it has the correct style but when the boolen variable inside the agent class changes, the border color does not change. If I do the same for the fill color of the agent instead, it works fine. I put here the code I used:

public class NodeStyle extends DefaultStyleOGL2D{
    @Override
    public Color getBorderColor(Object agent) {
          Color borderColor = Color.BLACK;
          if(agent instanceof Process) {
                Process p = (Process)agent;
                if(p.isParticularNode) {
                     borderColor = Color.RED;
                }
           }
           return borderColor;
     }
}

When the agent is created and it is added to the context, it take the correct color but if isParticularNode changes, the border color does not change. I've tryed also to do the same importing the interface StyleOGL2D but the problem remains

g. tu
  • 149
  • 11

1 Answers1

3

I tried this with the JZombies demo, adding an "id" double to each zombie that is set with RandomHelper.nextDouble() each tick. The border color changes as expected. By default the border size is 0, so perhaps that needs to be changed in your code.

public class ZombieStyle extends DefaultStyleOGL2D {

    public Color getColor(Object agent) {
        return Color.RED;
    }

    public Color getBorderColor(Object agent) {
        Zombie z = (Zombie)agent;
        if (z.getID() > 0.5) {
            return Color.GREEN;
        }
        return Color.black;
    }

    public int getBorderSize(Object agent) {
        return 4;
    }

}
Nick Collier
  • 1,786
  • 9
  • 10
  • I don't think that the border size is the problem, I have set the border color to a value greater than 0. I have a similar problem implementing EdgeStyleOGL2D coloring edges. I return a color inside a condition and the edge is not dislpayed or displayed with a wrong color. The strange thing is that if I try to debug putting a breakpoint on the return line, the program breaks there. – g. tu Nov 19 '19 at 11:21
  • Can you create a simple test case that reproduces this? You can use the repast mailing list to post where we can download and experiment with it. – Nick Collier Nov 19 '19 at 15:39