MASON-INTEREST-L Archives

February 2015

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Tue, 10 Feb 2015 11:52:12 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (38 lines)
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

ATOM RSS1 RSS2