//From Marcus Daniels, October 6,2001

JB> Hi, I tried to draw agents with method

JB> Raster.ellipseX0$Y0$X1$Y1$Width$Color(int, int, int, int, int,
JB> byte);

JB> but I saw only lines from left-top to right-bottom corner; not
JB> ellipses.  I using Win2000 Pro SP1 and Swarm 2.1.1.

This works for me on both Linux and Windows 2000.  I'm using the 2.2 pretest,
but I'm pretty sure this has been working since 2.1.1.1.

import swarm.Globals;
import swarm.defobj.Zone;
import swarm.random.NormalDist;
import swarm.random.NormalDistImpl;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.simtoolsgui.GUISwarm;
import swarm.gui.Colormap;
import swarm.gui.ColormapImpl;
import swarm.gui.RasterImpl;
import swarm.gui.Raster;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.Selector;

class DrawEllipse extends GUISwarmImpl {
  Schedule schedule;
  NormalDist normalDist;
  Raster raster;

  static void main (String args[]) {
    Globals.env.initSwarm ("DrawEllipse", "0.0", "bug-swarm.org", args);


    GUISwarm guiSwarm = new DrawEllipse (Globals.env.globalZone);

    guiSwarm.buildObjects ();
    guiSwarm.buildActions ();
    guiSwarm.activateIn (null);
    guiSwarm.go ();
  }

  public DrawEllipse (Zone aZone) {
    super (aZone);
  }

  public Object buildObjects () {
    super.buildObjects ();

    Colormap colormap = new ColormapImpl (getZone ());
    colormap.setColor$ToName ((byte) 1, "green");

    raster = new RasterImpl (getZone (), "raster");
    raster.setColormap (colormap);
    raster.setWidth$Height (200, 200);
    raster.setWindowTitle ("Test");
    raster.pack ();
    raster.erase ();

    normalDist = new NormalDistImpl (getZone (),
                                     Globals.env.randomGenerator,
                                     100.0, 50.0);
    
    return this;
  }
  
  public void resample () {
    int diameter = (int) normalDist.getDoubleSample ();

    raster.ellipseX0$Y0$X1$Y1$Width$Color (100 - diameter, 100 - diameter, 100 + diameter, 100 + diameter, 1, (byte) 1);
    raster.drawSelf ();
    getActionCache ().doTkEvents ();
  }

  public Object buildActions () {
    super.buildActions ();

    schedule = new ScheduleImpl (getZone (), 1);

    try {
      Selector sel = new Selector (getClass (), "resample", false);

      schedule.at$createActionTo$message (0, this, sel);
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    return this;
  }

  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);

    schedule.activateIn (this);
    return getActivity ();
  }
}


