swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fixing display


From: Ken Cline
Subject: Re: fixing display
Date: Tue, 9 Sep 1997 12:56:05 -0400 (EDT)

On Mon, 8 Sep 1997, Sven Thommesen wrote:

> Awright! I think this qualifies ...
> 
> I'll put something together within a week or so;
> right now there's a push to get a new version of
> Random ready for 1.0.3 :-)

I'm not sure how to do this for any Swarm GUI widget, but
here's what I've done for my probes.

   In ModelObserver.m:
   -------------------
            ...
      -buildObjects {
         id aProbeDisplay = NULL;
            ...

         if ( showModelProbe == TRUE && modelSwarm != NULL )
            aProbeDisplay = 
               [ probeDisplayManager createProbeDisplayFor: modelSwarm ];

         if ( aProbeDisplay != NULL )
            [ aProbeDisplay->topLevel setPositionX: 15 Y: 100 ];

            ...
       }

`setPositionX:Y:' is defined for any Widget but I suppose
you want to be sure to only call `setPositionX:Y:' for the
top level frame (from what I've seen this is usually named
"topLevel").

You will get some compiler warning from the code above;
stuff like:

      ModelObserver.m: In function `_i_ModelObserver__buildObjects':
      ModelObserver.m:103: warning: static access to object of type `id'

There's probably a way to make these warnings go away but
note that if "aProbeDisplay" was not type `id' (and was type
`SimpleProbeDisplay *' instead, for example) then the code
probably won't compile at all because "topLevel" is a
protected member.

Alternatively, you could subclass a class such as
ProbeDisplay and add a `setPositionX:Y:' method.  This is a
lot of effort for just one feature.  However, for my
customized control panel, I did choose this alternative
because I also wanted to add a new button: "Reset".

As a subclass of ControlPanel, I can access the "panel"
member directly.  This is the method I added to my control
panel:

    -setPositionX: (int) x Y: (int) y {
       [ [panel getTopLevel] setPositionX: x Y: y ];
       return self;
    }

Be warned that subclassing ControlPanel took a little doing
and frankly it would be easier to cut-n-paste the
ControlPanel code and make a sibling class rather than a
subclass, IMHO.

One problem, you want to override `createEnd' but you also
want to call [super createEnd] within your `createEnd' (this
may not be absolutely necesssary but ControlPanel is a 
subclass of SwarmObject so it is probably a good idea.)  The
problem is that ControlPanel's `createEnd' creates the
(button) "panel" so you have to decided whether you want to
modify the existing panel or create a new panel.

For instance, you could add a new button with the following
code:

     [ panel addButtonName: "Reset"
                   Command: "simctl setStateReset" ];

But if want the new "Reset" button to appear above the
"Quit" button, then you might have to doing something like:

     if ( panel != NULL ) {
        [ globalTkInterp eval: "destroy %s", 
                 [ [panel getTopLevel] getWidgetName] ];
        [ panel drop   ];
     }

     panel = [ ButtonPanel create: [self getZone] ];
        ...

There's also probably a way to remove the "Quit" button with
tk commands and then add it back on the panel, I just
haven't tried that yet.  Perhaps in a future release the
ControlPanel `createEnd' method will test whether "panel"
already exists; in that case you could just create your
customized panel before calling [super createEnd].


Anyway, that's how I positioned my widgets to fixed window
positions.  I'm sure Sven will have a better way but I
figured that since he was so busy I'd post what I'd done.


Ken.

PS: Thanks to Ginger and Nelson for their discussion about
positioning windows, it was a great help.  See http://
www.santafe.edu/projects/swarm/archive/list-archive.9603/0027.html


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427




                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]