Print

Print


First off, I'd not copy stuff from OvalPortrayal2D unless you have to.  Just subclass your agents from OvalPortrayal2D.  Then you can say:

    public final void draw(Object object, Graphics2D graphics, DrawInfo2D info) {
        if (answer) 
            graphics.setColor(rightAnswer);
	else
            graphics.setColor(badAnswer);
	super.draw(object, graphics, info);
        }


Adding a label is really easy.  Just register your agents with your FieldPortrayal like this:

	LabelledPortrayal2D foo = new LabeledPortrayal2D(null, "This is my label");
	fieldPortrayal.setPortrayalForClass(MyAgentClass.class, foo);


If you would prefer a dynamic label, override the toString() method in your agent to return the value you'd prefer, then say: 
	
	LabelledPortrayal2D foo = new LabeledPortrayal2D(null, null);
	fieldPortrayal.setPortrayalForClass(MyAgentClass.class, foo);


If you don't want to override toString(), you could say:

	LabelledPortrayal2D foo = new LabeledPortrayal2D(null, null)
		{
		public String getLabel(Object obj, DrawInfo2D info)
			{
			MyAgentClass agent = (MyAgentClass) obj;
//			... query your agent here and return a label
			}
		};
	fieldPortrayal.setPortrayalForClass(MyAgentClass.class, foo);


Sean