Print

Print


Norm,

The Inspector is one way of interacting with the objects in the
simulation.  It is a mere JPanel, which has an extra function called
updateInspector.  When some objects are selected/double-clicked, the
display asks the portrayal for the inspectors of those objects, and
creates.  The list reaches the console, which displays them and then
handles them as needed.  The updateInspector method is useful for the
following reason: as the simulation progresses, you may need to update the
information that the inspectors show (for example, the location of the
agent may change, and you may want the inspector to display the updated
information).  Therefore, the console makes sure it schedules a special
agent that at each timestep calls the updateInspector method on each of
the inspectors in the simulation.  So, the initialization (constructor)
may simply call the updateInspector method, as they both probably access
the same information.  Aside from this, you may use some code from
SimpleInspector or from other sources to build up your custom inspector,
but that should only be helpful.  Try something simpler initially, where
you only display location of agents, for example.  These could stay in
simple text labels inserted in the JPanel.  After the creation and testing
of this prototype, try inserting some code in the updateInspector method
to update the position as the simulation progresses (you may need to hold
on to a pointer to the object in your inspector for this purpose).  After
this is done and tested, try changing the labels with edit fields where
you can also modify values (again, this may require that you have pointers
to the original objects).

Hope this helps.

Liviu.

On Mon, 17 May 2004, Norman Josephy wrote:

> Liviu:
>
> Thank you for your incredibly fast response.
>
> I had done the following in Python.
>
> I created a class MyObjectGridPortrayal2D  extending
> ObjectGridPortrayal2D. My getInspector(wrapper,state) method
> simply returned an instance of MyInspector(wrapper,state).
>
> I created a class MyInspector extending Inspector.
> Its initialization code took the wrapper passed to
> it, extracted the object and accessed the object values
> to be displayed.
>
> Now things got fuzzy for me. My impression
> when reading the documentation on SimpleInspector was that
> I needed to package the values to be displayed in a
> CollectionProperties, it being the only Properties that
> did not seem to use the get/set accessing method.
>
> So I wrapped the array of values in CollectionProperties(),
> created an instance of SimpleInspector, and tried to
> force it to have my CollectionProperties instance
> with an assignment:
>  mySimpleInspector.properties = myCollectionProperties
> I then followed the Java code in creating a box, setting the
> layout of mySimpleInspector, adding the box and refreshing
> the controller.
>
> This seemed to be very convoluted. A consequence of my lack of
> understanding of the display mechanism. It also did not work.
> Not unexpected.
>
> What got more confusing was the updateInspector method. I
> do not know when it is called, and I don't know what it expects
> to be done, other than repeat the process followed in the
> initialization code. The tutorial examples had an already
> existing inspector do the updating, which did not help.
>
> I am sorry for the rambling. I will continue to experiment
> with creating a custom portrayal that constructs the
> visualization (widgets) containing the information.
>
> Again, thank you for your speedy response.
>
> Norm
>