1: import swarm.Globals;
  2: import swarm.objectbase.Swarm;
  3: import swarm.activity.Activity;
  4: import swarm.activity.Schedule;
  5: import swarm.activity.ScheduleImpl;
  6: import swarm.simtoolsgui.GUISwarmImpl;
  7: import swarm.space.Object2dDisplay;
  8: import swarm.space.Object2dDisplayImpl;
  9: import swarm.gui.ZoomRasterImpl;
 10: import swarm.gui.ZoomRaster;
 11: import swarm.gui.Colormap;
 12: import swarm.gui.ColormapImpl;
 13: import swarm.defobj.Zone;
 14: import swarm.Selector;

 16: import java.util.List;
 17: import java.util.LinkedList;

 19: public class ObserverSwarm extends GUISwarmImpl {
 20:   public final static byte UserTourColor = 0;
 21:   public final static byte UserResistColor = 1;
 22:   public final static byte UserListenColor = 2;
 23:   public final static byte GlenTourColor = 3;
 24:   public final static byte GlenAttackColor = 4;
 25:   public final static byte MarcusIncubateColor = 5;
 26:   public final static byte MarcusResistColor = 6;
 27:   public final static byte MarcusListenColor = 7;
 28:   public final static byte MarcusNativeColor = 8;
 29:   public final static byte AlexTourColor = 9;
 30:   public final static byte AlexTalkColor = 10;
 31:   public final static byte AlexTargetColor = 11;
 32:   Object2dDisplay display;
 33:   ZoomRaster raster;
 34:   SDG model;
 35:   Colormap colormap;
 36:   Schedule displaySchedule;

 38:   public ObserverSwarm (Zone aZone) {
 39:     super (aZone);
 40:     model = new SDG (aZone, 100, 100);
 41:   }

 43:   public Object buildObjects () {
 44:     super.buildObjects ();

 46:     model.buildObjects ();
 47:     
 48:     colormap = new ColormapImpl (getZone ());
 49:     colormap.setColor$ToName (UserTourColor, "white");
 50:     colormap.setColor$ToName (UserResistColor, "gray");
 51:     colormap.setColor$ToName (UserListenColor, "slate gray");

 53:     colormap.setColor$ToName (MarcusIncubateColor, "yellow");
 54:     colormap.setColor$ToName (MarcusResistColor, "red");
 55:     colormap.setColor$ToName (MarcusListenColor, "pale green");
 56:     colormap.setColor$ToName (MarcusNativeColor, "dark green");

 58:     colormap.setColor$ToName (GlenTourColor, "cyan");
 59:     colormap.setColor$ToName (GlenAttackColor, "pink");

 61:     colormap.setColor$ToName (AlexTourColor, "brown");
 62:     colormap.setColor$ToName (AlexTalkColor, "orange");
 63:     colormap.setColor$ToName (AlexTargetColor, "brown");

 65:     raster = new ZoomRasterImpl (getZone (), "raster");
 66:     raster.setColormap (colormap);
 67:     raster.setZoomFactor (3);
 68:     raster.setWidth$Height (model.getWorld ().getSizeX (),
 69:                             model.getWorld ().getSizeY ());
 70:     raster.setWindowTitle ("SDG World");
 71:     raster.pack ();
 72:     raster.erase ();

 74:     try {
 75:       display = new Object2dDisplayImpl
 76:         (getZone (),
 77:          raster,
 78:          model.getWorld (),
 79:          new Selector (Class.forName ("agent2d.Agent2d"), "drawSelfOn", false));
 80:       raster.setButton$Client$Message (3, display,
 81:                                        new Selector (display.getClass (),
 82:                                                      "makeProbeAtX$Y", true));
 83:     } catch (Exception e) {
 84:       e.printStackTrace (System.err);
 85:       System.exit (1);
 86:     }

 88:     return this;
 89:   }

 91:   public void updateDisplay () {
 92:     raster.erase ();
 93:     display.display ();
 94:     raster.drawSelf ();
 95:     Globals.env.probeDisplayManager.update ();
 96:     getActionCache ().doTkEvents ();
 97:   }

 99:   public Object buildActions () {
100:     super.buildActions ();

102:     model.buildActions ();
103:     displaySchedule = new ScheduleImpl (getZone (), 1);

105:     try {
106:       displaySchedule.at$createActionTo$message
107:         (0, 
108:          this,
109:          new Selector (getClass (), "updateDisplay", false));
110:     } catch (Exception e) {
111:       e.printStackTrace (System.err);
112:       System.exit (1);
113:     }
114:     return this;
115:   }

117:   public Activity activateIn (Swarm context) {
118:     super.activateIn (context);
119:     
120:     model.activateIn (this);
121:     displaySchedule.activateIn (this);
122:     return getActivity ();
123:   }

125:   public static void main (String[] args) {
126:     Globals.env.initSwarm ("SDG", "0.0", "bug-swarm@swarm.org", args);
127:     ObserverSwarm observer = new ObserverSwarm (Globals.env.globalZone);
128:     observer.buildObjects ();
129:     observer.buildActions ();
130:     observer.activateIn (null);
131:     observer.go ();
132:   }
133: }