February 2015


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
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Wed, 11 Feb 2015 11:46:04 -0500
text/plain (38 lines)
On Feb 11, 2015, at 11:35 AM, Simone Gabbriellini <[log in to unmask]> wrote:

> Actually I was copying your code from antsforage, but if I do as you suggest here, my agents don't get colored, they remains grey as default. 

I'm sorry, I should have said:

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

> About the labeling, I have added these lines as suggested:
> But nothing's happening... where am I wrong?

I forgot that your agents are also SimplePortrayals.  In the FieldPortrayal, when it needs to know how to draw an object, it does this:

If there is a portrayalForAll, use it.
Else if the object is null: 
	Use the portrayalForNull if there is one
	Else if a portrayal is explicitly registered for null, use it.
	Else use the defaultNullPortrayal. 
Else if the object is non-null: 
	If the object implements the appropriate Portrayal interface, use the object itself.
	Else use the portrayalForNonNull if there is one
	Else if a portrayal is explicitly registered for the object, use that portrayal.
	Else if a Portrayal is registered for the object's exact class (superclasses are ignored), use that portrayal. 	
	Else use the portrayalForRemainder if there is one
	Else use the default Portrayal object. 

The problem is that your object implements the Portrayal interface, so it overrides the portrayal we set up for the object's class.  If your field only contains object of this type simplest solution would be to register the portrayal for ALL rather than for a given CLASS: