Esempio n. 1
0
    private void executeEvent(final int x, final int y) {
      if (executer == null) {
        return;
      }
      final ILocation pp = getModelCoordinatesFrom(x, y, surface);
      if (pp.getX() < 0
          || pp.getY() < 0
          || pp.getX() >= surface.getEnvWidth()
          || pp.getY() >= surface.getEnvHeight()) {
        return;
      }
      final Arguments args = new Arguments();
      final Collection<IAgent> agentset = surface.selectAgent(x, y);
      if (pointArg != null) {
        args.put(
            pointArg, ConstantExpressionDescription.create(new GamaPoint(pp.getX(), pp.getY())));
      }
      if (listArg != null) {
        args.put(listArg, ConstantExpressionDescription.create(agentset));
      }

      executer.setRuntimeArgs(args);
      GAMA.run(
          new GAMA.InScope.Void() {

            @Override
            public void process(final IScope scope) {
              executer.executeOn(scope);
            }
          });
      if (surface.getOutput().isPaused() || GAMA.isPaused()) {
        surface.updateDisplay(true);
      }
    }
Esempio n. 2
0
 public EventListener(final IDisplaySurface display, final String event, final String action) {
   listenedEvent = getListeningEvent(event);
   IAgent a = display.getDisplayScope().getSimulationScope();
   if (a == null) {
     a = display.getDisplayScope().getExperiment();
   }
   executer = a.getSpecies().getAction(action);
   surface = display;
 }
Esempio n. 3
0
  @Override
  public void firstLaunchOn(final IDisplaySurface surface) {
    super.firstLaunchOn(surface);
    final IExpression eventType = definition.getFacet(IKeyword.NAME);
    final IExpression actionName = definition.getFacet(IKeyword.ACTION);
    IScope scope = surface.getDisplayScope();

    String currentMouseEvent = Cast.asString(scope, eventType.value(scope));
    String currentAction = Cast.asString(scope, actionName.value(scope));

    listener = new EventListener(surface, currentMouseEvent, currentAction);
    surface.addMouseListener(listener);
  }
Esempio n. 4
0
 // We explicitely translate by the origin of the surface
 @Override
 public ILocation getModelCoordinatesFrom(
     final int xOnScreen, final int yOnScreen, final IDisplaySurface g) {
   return g.getModelCoordinates();
 }
Esempio n. 5
0
 @Override
 public void disableOn(final IDisplaySurface surface) {
   super.disableOn(surface);
   surface.removeMouseListener(listener);
 }
Esempio n. 6
0
 @Override
 public void enableOn(final IDisplaySurface surface) {
   surface.addMouseListener(listener);
 }
Esempio n. 7
0
 public void dispose() {
   surface.removeMouseListener(this);
 }