package alive;

/**
 * <ALIVE Project>
 * Experiment 0 Environment class
 * By Rogerio Neves
 * LSI - POLI - USP
 */

import javax.vecmath.*;
import javax.media.j3d.*;

public class xp0_Environment extends Environment {
  java.awt.Checkbox ui = new java.awt.Checkbox("Experiment UI Enabled",true);
  java.awt.Scrollbar el = new java.awt.Scrollbar(0,100,1,0,101);
  java.awt.Label le = new java.awt.Label("      ");
  java.awt.TextField x = new java.awt.TextField("10");
  int nag = 100;

  double k = 1;

  public xp0_Environment(EnvConfig cfg) { // pre-computations
    configureEnvironment(cfg);
    message("\nxp0 started...");
    nag = (int)config.POP_LIMIT/10;
    super.start();
  }
  public void createContent() {
    message("\nAdding agents...");
    for (int i=0; i<nag;i++) addAgent(new xp0_Particle(this));
  }
  public void createCustomUI() {
    java.awt.Button b = new java.awt.Button("x New");
    b.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent e) {
        nag = getInt(x.getText());
        createContent();
      }});
    x.setColumns(10);
    control.ui.add(ui);
    control.ui.add(x);
    //control.ui.add(new java.awt.Label("Elasticity"));
    //control.ui.add(el);
    control.ui.add(b);
  }
  public void update() {
    if (ui.getState()) {
      k = (double) el.getValue()/100;
      le.setText(String.valueOf(k));
    }
  }

  // *** Main method: Makes experiment executable
  public static void main(String[] args) {
    EnvConfig cfg = new EnvConfig();
    cfg.POP_LIMIT = 100;
    new xp0_Environment(cfg);
  }
}
