swarm-support
[Top][All Lists]
Advanced

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

control panel problem


From: Charles Staelin
Subject: control panel problem
Date: Tue, 18 Apr 2000 16:42:56 -0400

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.



reply via email to

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