perfect, they both works...

I only have to move part of the labels from behind the agents, but I think it won't be hard...

Thank you very much!


2015-02-11 17:46 GMT+01:00 Sean Luke <[log in to unmask]>:
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:




Simone Gabbriellini, PhD

Post-doctoral Researcher
ANR founded research project "DIFFCERAM"
GEMASS, CNRS & Paris-Sorbonne.

mobile: +39 340 39 75 626
email: [log in to unmask]