Print

Print


Dear MASON Interest Group,

I have run into difficulty with using Wrapper Portrayals.

My simulation GUI takes inspiration from the Student Demo of the MASON manual, I use the "setPortrayalForAll(...)" method of my main Field Portrayal, where the portrayal being set is the LabelledPortrayal2D wrapper. To do this, I create a new sim.portrayal.simple.LabelledPortrayal2D object, passing "null" to the child argument, and "Hello World" to the label argument. Setting the child to null is necessary because the agents my model uses are their own Portrayals, extending a class that extends SimplePortrayal2D. Now up to this point, everything works, and the wrappers display as I want. 

However, I would like only some of the classes I use to use wrappers but using the "setPortrayalForClass(...)" method doesn't work. Looking at the documentation, it seems that this is the case because of the order of priority different portrayals take. Where the portrayal set by setPortrayalForAll is used first, then the object itself if it implements Portrayal, and the setPortrayalForClass portrayal beneath this. Is it possible to use wrappers if the object is its own portrayal? 

The obvious solution would be to simply not have my objects portrayal themselves, to instead decouple the portrayal from agent, and have a separate AgentPortrayal class that I then can register using the setPortrayalForClass method. I don't think this is possible, since I'm using the Physics2D framework, and my agents extend the MobileObject2D, is its own portrayal. 

What would be the best work around solution here? (I am new to Java and the MASON framework so could be missing an obvious solution here). 

Many thanks,

Alex