Print

Print


Very interesting question, Rob.  Here's the Display2D attach code at
present:

     public void attach(FieldPortrayal2D portrayal, String name,
Rectangle2D.Double bounds )
         {
         FieldPortrayal2DHolder p = new
FieldPortrayal2DHolder(portrayal,name,bounds);
         portrayals.add(p);
           popup.add(p.menuItem);
         }

FieldPortrayal2DHolder is an internal class in Display2D which holds
the relevant FieldPortrayal2D stuff.  Perhaps we should expose some of
those items later on, but for the moment it probably wouldn't hurt to
add the following method (I will go ahead and add it to the next
version so you can be assured it will stay in MASON if you let me know
it looks like it's working -- though don't expect "p.draw" to be the
same variable name):

     /** Attaches a portrayal to the Display2D, along with the provided
         human-readable name for the portrayal.  The portrayal's attached
         origin, width and height is given in the bounds rectangle.  The
portrayal
         may be set to initially visible or not visible.  Portrayals are
drawn
         on-screen in the order that they are attached; thus the
"top-most" portrayal
         will be the last one attached.  */
     public void attach(FieldPortrayal2D portrayal, String name,
                                        Rectangle2D.Double bounds, boolean visible )
         {
         FieldPortrayal2DHolder p = new
FieldPortrayal2DHolder(portrayal,name,bounds);
         p.draw = visible;
         p.menuItem.setSelected(visible);
         portrayals.add(p);
         popup.add(p.menuItem);
         }

     /** Attaches a portrayal to the Display2D, along with the provided
         human-readable name for the portrayal.  The portrayal will be
attached
         with an origin at (0,0) and a width and height equal to the
Display2D's
         default width and height.  The portrayal may be set to initially
         visible or not visible.  Portrayals are drawn
         on-screen in the order that they are attached; thus the
"top-most" portrayal
         will be the last one attached.*/
     public void attach(FieldPortrayal2D portrayal, String name, boolean
visible )
         {
         attach(portrayal, name,
                        new Rectangle2D.Double(0,0,insideDisplay.width,insideDisplay.height),
                        visible);
         }

I'll add similar stuff to Display3D.

Sean

On Apr 5, 2005, at 6:32 AM, Rob Alexander wrote:

> Hi,
>
> Is there any way to attach a field portrayal to a Display2D such that
> it
> appears in the "layers" popup menu but is off by default?
>
> I can see how the mechanism works; the FieldPortrayal2DHolder instance
> contains the actual menu item, and the menu item is given an
> ActionListener which sets the 'draw' field depending on the new state
> of
> the menu item. But the initial state appears to be hardcoded:
>
> menuItem = new JCheckBoxMenuItem(name,true);
>
> One option, I suppose, would be to subclass Display2D and override that
> constructor as well as Display2D.attach(), so that the initial state
> was
> controlled by a parameter. But have I missed something, is there a
> nicer
> way to do this?
>
> yours,
> rob
>
> --
> Rob Alexander
> Research Associate, Dept of Computer Science, The University of York,
> York, YO10 5DD, UK
> Tel: 01904 432764 Fax: 07976 889545   http://www.cs.york.ac.uk/~rda/