swarm-support
[Top][All Lists]
Advanced

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

Re: control panel problem


From: Charles Staelin
Subject: Re: control panel problem
Date: Tue, 18 Apr 2000 19:19:45 -0400

Friends,

I think that I know the answer to my own question.  Tell me if I am right.
I assume that the setStateStopped message essentially sets a flag for the
control panel that it acts upon the next time it is polled for a button
press.  I also assume that the control panel is polled only between time
steps (every step?) and so the action stops only after the current period is
over.  Assuming that that is true, if one wants to prohibit the user from
restarting the simulation after an event that sets the STOP button, then I
assume you would have to check for a restart in the very first activity in
the next time period.  (Using setStateQuit instead of Stop clears the probe
and raster windows and therefore is not a good option here.)  That first
activity would be the first message inserted in the first schedule of the
top-level swarm?

If I am on the right track here, then I still am puzzled at why the
setStateStopped seems to work immediately in buildObjects.

Charles

--------------------------------------------------------------------------
Charles P. Staelin                              address@hidden
Department of Economics
Smith College                                    (413) 585-3621
Northampton, MA 01063                  (413) 585-3393 (FAX)
----- Original Message -----
From: "Charles Staelin" <address@hidden>
To: "Swarm Support" <address@hidden>
Sent: Tuesday, April 18, 2000 4:42 PM
Subject: control panel problem


> Friends,
>
> I may have asked this before, but I don't remember there
> being an answer and now I have a little test program to
> demonstrate the problem.  This is all in Java on a Win98
> platform using Swarm 2.1 and Kaffe.
>
> If I use getControlPanel().setStateStopped() I seem to get
> unpredictable results - at least to me!  In the following
> test program, the first call to setStateStopped in
> buildObjects in the ObserverSwarm class works as expected.
> The "Now building objects" message does not appear on the
> console until after the START button is pushed on the
> control panel.  However, the application seems to blow right
> through the second call to setStateStopped in the
> checkForDone method.  The println's (and any "real" code
> such as the code which has been commented out) execute
> _before_ I press any button on the control panel.  However,
> _after_ the println's appear(or other code in the block
> executes), the application does seem to stop and wait for a
> button push.
>
> I'm stumped.  Any suggestions as to what is going on?
>
> The test code is below, followed by the console output.
>
> -------------------------------------------------------
> import swarm.Globals;
> import swarm.Selector;
> import swarm.defobj.Zone;
> import swarm.defobj.ZoneImpl;
> import swarm.simtoolsgui.GUISwarm;
> import swarm.simtoolsgui.GUISwarmImpl;
>
> import swarm.activity.ActionGroup;
> import swarm.activity.ActionGroupImpl;
> import swarm.activity.Schedule;
> import swarm.activity.ScheduleImpl;
> import swarm.activity.Activity;
>
> import swarm.objectbase.Swarm;
> import swarm.objectbase.SwarmImpl;
>
>
>
> public class Test
> {
>     public static void main (String[] args)
>     {
> ObserverSwarm displaySwarm;
>
>         // Swarm initialization: all Swarm apps must call
> this first.
>         Globals.env.initSwarm ("SimpleBug", "2.1",
>        "address@hidden", args);
>
>         displaySwarm = new
> ObserverSwarm(Globals.env.globalZone);
>
> displaySwarm.buildObjects();
> displaySwarm.buildActions();
> displaySwarm.activateIn(null);
>
> displaySwarm.go();
>
> displaySwarm.drop();
>     }
> }
>
> class ObserverSwarm extends GUISwarmImpl
> {
>     ZoneImpl modelZone;
>     ModelSwarm modelSwarm;
>     ScheduleImpl displaySchedule;
>
>     boolean simulationFinished = false;
>
>     public ObserverSwarm(Zone azone)
>     {
> super(azone);
>     }
>
>     public Object buildObjects()
>     {
> super.buildObjects();
>
> modelZone = new ZoneImpl(getZone());
> modelSwarm = new ModelSwarm(modelZone);
>
> getControlPanel().setStateStopped();
> System.out.println("Now building objects.");
>
> modelSwarm.buildObjects();
> modelSwarm.setDisplaySwarm(this);
>
> return this;
>     }
>
>     public Object buildActions()
>     {
> Selector sel;
> ActionGroupImpl displayActions;
>
> super.buildActions();
>
> modelSwarm.buildActions();
>
> displayActions = new ActionGroupImpl(getZone());
> try
>     {
>     sel = new Selector(getClass(), "checkForDone", false);
>     displayActions.createActionTo$message(this, sel);
>     }
> catch (Exception e)
>     {
>     System.out.println("Selector error.");
>     System.exit(1);
>     }
>
> displaySchedule = new ScheduleImpl(getZone(), 1);
> displaySchedule.at$createAction(0, displayActions);
>
> return this;
>     }
>
>     public Activity activateIn(Swarm swarmContext)
>     {
> super.activateIn(swarmContext);
>
> modelSwarm.activateIn(this);
> displaySchedule.activateIn(this);
>
> return getActivity();
>     }
>
>     public void checkForDone()
>     {
> if (simulationFinished)
>     {
>     System.out.println("We're done at time = " +
>        Globals.env.getCurrentTime() +
>        ".  Press QUIT when ready.");
>     getControlPanel().setStateStopped();
>     System.out.println("to 1");
>     //     (modelSwarm.getActivity()).terminate();
>     System.out.println("to 1a");
>     //     modelSwarm.drop();
>     System.out.println("to 2");
>     //     getControlPanel().setStateQuit();
>     System.out.println("to 3");
>     }
>     }
>
>     // Receive a message that the simulation is done and set
>     // simulationFinished to true.
>     public void simulationDone()
>     {
> simulationFinished = true;
>     }
> }
>
> class ModelSwarm extends SwarmImpl
> {
>     ScheduleImpl modelSchedule;
>     ObserverSwarm displaySwarm;
>
>     public ModelSwarm(Zone azone)
>     {
> super(azone);
>     }
>
>     public void setDisplaySwarm(ObserverSwarm dS)
>     {
> displaySwarm = dS;
>     }
>
>     public Object buildObjects()
>     {
> super.buildObjects();
>
> return this;
>     }
>
>     public Object buildActions()
>     {
> Selector sel;
> ActionGroupImpl modelActions;
>
> modelActions = new ActionGroupImpl(getZone());
> try
>     {
>     sel = new Selector(getClass(), "checkTime", false);
>     modelActions.createActionTo$message(this, sel);
>     }
> catch (Exception e)
>     {
>     System.out.println("Selector error.");
>     System.exit(1);
>     }
>
> modelSchedule = new ScheduleImpl(getZone(), 1);
> modelSchedule.at$createAction(0, modelActions);
>
> return this;
>     }
>
>     public Activity activateIn(Swarm swarmContext)
>     {
> super.activateIn(swarmContext);
>
> modelSchedule.activateIn(this);
>
> return getActivity();
>     }
>
>     public void checkTime()
>     {
> int time;
>
> time = Globals.env.getCurrentTime();
> System.out.println("Time = " + time);
> if (time >= 5)
>     {
> displaySwarm.simulationDone();
>     }
>
> return;
>     }
> }
>
> -------------------------------------------------------
> cd c:/usr/home/jTutorial-V2/simpleObserverBug/Problem/
> C:\Swarm-2.1\libexec\Kaffe -classpath
> .;C:\Swarm-2.1\share\swarm\swarm.jar;C:\Swarm-2.1\share\kaff
> e\Klasses.jar Test
>
> ************************Waits here till I press START
> Now building objects.
> Time = 0
> Time = 1
> Time = 2
> Time = 3
> Time = 4
> Time = 5
> We're done at time = 5.  Press QUIT when ready.
> to 1
> to 1a
> to 2
> to 3
> ***********************Waits HERE till I press QUIT
>
> Process Test finished
>
>
>
> --------------------------------------------------------
> Charles Staelin                email: address@hidden
> Department of Economics
> Smith College                  phone: (413) 585-3621
> Northampton, MA 01063            fax: (413) 585-3393
> --------------------------------------------------------
>
>
>                   ==================================
>    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.
>
>


                  ==================================
   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]