Sender: |
|
Date: |
Tue, 10 Feb 2015 11:52:12 -0500 |
MIME-version: |
1.0 (Mac OS X Mail 7.3 \(1878.6\)) |
Reply-To: |
|
Content-type: |
text/plain; charset=iso-8859-1 |
Subject: |
|
From: |
|
In-Reply-To: |
|
Message-ID: |
|
Content-Transfer-Encoding: |
8bit |
Parts/Attachments: |
|
|
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
|
|
|