Beispiel #1
0
  private void compileSource(
      org.nlogo.api.JobOwner owner, List<org.nlogo.window.Events.CompiledEvent> errorEvents) {
    try {
      CompilerResults results =
          workspace
              .compiler()
              .compileMoreCode(
                  owner.source(),
                  scala.Some.apply(owner.classDisplayName() + " '" + owner.displayName() + "'"),
                  workspace.world.program(),
                  workspace.getProcedures(),
                  workspace.getExtensionManager());

      if (!results.procedures().isEmpty()) {
        results.head().init(workspace);
        results.head().setOwner(owner);
        new org.nlogo.window.Events.CompiledEvent(
                owner, workspace.world.program(), results.head(), null)
            .raise(this);
      }
    } catch (CompilerException error) {
      errorEvents.add(
          new org.nlogo.window.Events.CompiledEvent(owner, workspace.world.program(), null, error));
    }
  }
Beispiel #2
0
 public void handle(org.nlogo.window.Events.CompileMoreSourceEvent e) {
   JobOwner owner = e.owner;
   if (isLoading) {
     widgets.add(owner);
     return;
   }
   if (owner.isCommandCenter()) {
     try {
       CompilerResults results =
           workspace
               .compiler()
               .compileMoreCode(
                   owner.source(),
                   scala.Some.apply(owner.classDisplayName()),
                   workspace.world.program(),
                   workspace.getProcedures(),
                   workspace.getExtensionManager());
       results.head().init(workspace);
       results.head().setOwner(owner);
       new org.nlogo.window.Events.CompiledEvent(
               owner, workspace.world.program(), results.head(), null)
           .raise(this);
     } catch (CompilerException error) {
       new org.nlogo.window.Events.CompiledEvent(owner, workspace.world.program(), null, error)
           .raise(this);
     }
   } else {
     compileWidgets();
   }
 }
 public Object load(scala.collection.Seq<String> strings, String version) {
   workspace.loadWorld(strings, version, this);
   // we can't clearAll here because the globals may not
   // be allocated yet ev 7/12/06
   // note that we clear turtles inside the load method so
   // it can happen before we set the topology ev 7/19/06
   workspace.world().tickCounter.clear();
   workspace.world().clearPatches();
   workspace.world().displayOn(true);
   return this;
 }
 public void setDimensions(int minPxcor, int maxPxcor, int minPycor, int maxPycor) {
   newMinX = minPxcor;
   newMaxX = maxPxcor;
   newMinY = minPycor;
   newMaxY = maxPycor;
   if (minPxcor != workspace.world().minPxcor()
       || maxPxcor != workspace.world().maxPxcor()
       || minPycor != workspace.world().minPycor()
       || maxPycor != workspace.world().maxPycor()) {
     prepareForWorldResize();
     workspace.world().createPatches(minPxcor, maxPxcor, minPycor, maxPycor);
     finishWorldResize();
   }
 }
  public boolean wrappingY() {
    if (!wrappingChanged) {
      newWrapY = workspace.world().wrappingAllowedInY();
    }

    return newWrapY;
  }
  public boolean wrappingX() {
    if (!wrappingChanged) {
      newWrapX = workspace.world().wrappingAllowedInX();
    }

    return newWrapX;
  }
Beispiel #7
0
 public SpeedSliderPanel(GUIWorkspace workspace, boolean labelsBelow) {
   this.workspace = workspace;
   this.labelsBelow = labelsBelow;
   speedSlider = new SpeedSlider((int) workspace.speedSliderPosition());
   speedSlider.setFocusable(false);
   speedSlider.addChangeListener(this);
   speedSlider.addMouseListener(this);
   speedSlider.setOpaque(false);
   org.nlogo.awt.Fonts.adjustDefaultFont(normal);
   setOpaque(false);
   if (labelsBelow) {
     GridBagLayout gridbag = new GridBagLayout();
     GridBagConstraints c = new GridBagConstraints();
     setLayout(gridbag);
     c.gridwidth = GridBagConstraints.REMAINDER;
     add(speedSlider, c);
     c.gridwidth = 1;
     c.anchor = GridBagConstraints.CENTER;
     add(normal, c);
   } else {
     java.awt.BorderLayout layout = new java.awt.BorderLayout();
     layout.setVgap(0);
     setLayout(layout);
     add(speedSlider, java.awt.BorderLayout.CENTER);
     add(normal, java.awt.BorderLayout.EAST);
   }
   enableLabels(0);
 }
Beispiel #8
0
 public void stateChanged(javax.swing.event.ChangeEvent e) {
   int value = speedSlider.getValue();
   // adjust the speed reported to the workspace
   // so there isn't a big gap between the snap area
   // and outside the snap area. ev 2/22/07
   if (value < -10) {
     value += 10;
   } else if (value > 10) {
     value -= 10;
   } else {
     value = 0;
   }
   workspace.speedSliderPosition(value / 2);
   if (org.nlogo.api.Version.isLoggingEnabled()) {
     org.nlogo.log.Logger.logSpeedSlider(value);
   }
   enableLabels(value);
   workspace.updateManager().nudgeSleeper();
 }
Beispiel #9
0
 private boolean compileProcedures() {
   workspace.world.program(workspace.world.newProgram());
   try {
     CompilerResults results =
         workspace
             .compiler()
             .compileProgram(
                 proceduresInterface.innerSource(),
                 workspace.world.newProgram(getGlobalVariableNames()),
                 workspace.getExtensionManager());
     workspace.setProcedures(results.proceduresMap());
     for (Procedure procedure : workspace.getProcedures().values()) {
       if (procedure.fileName.equals("")) {
         procedure.setOwner(proceduresInterface);
       } else if (procedure.fileName.equals("aggregate")) {
         procedure.setOwner(workspace.aggregateManager());
       } else {
         procedure.setOwner(new ExternalFileInterface(procedure.fileName));
       }
     }
     workspace.init();
     workspace.world.program(results.program());
     new org.nlogo.window.Events.CompiledEvent(proceduresInterface, results.program(), null, null)
         .raise(this);
     return true;
   } catch (CompilerException error) {
     if (AbstractWorkspace.isApplet()) {
       System.err.println("CompilerException: " + error);
       error.printStackTrace();
       new org.nlogo.window.Events.CompiledEvent(proceduresInterface, null, null, error)
           .raise(this);
     }
     if (error.fileName().equals("")) {
       new org.nlogo.window.Events.CompiledEvent(proceduresInterface, null, null, error)
           .raise(this);
     } else if (error.fileName().equals("aggregate")) {
       new org.nlogo.window.Events.CompiledEvent(workspace.aggregateManager(), null, null, error)
           .raise(this);
     } else {
       new org.nlogo.window.Events.CompiledEvent(
               new ExternalFileInterface(error.fileName()), null, null, error)
           .raise(this);
     }
     return false;
   }
 }
Beispiel #10
0
 void reset() {
   enableSizeControls(
       (workspace.world().maxPxcor() == -workspace.world().minPxcor()
           || workspace.world().minPxcor() == 0
           || workspace.world().maxPxcor() == 0),
       (workspace.world().maxPycor() == -workspace.world().minPycor()
           || workspace.world().minPycor() == 0
           || workspace.world().maxPycor() == 0));
   // this next line shouldn't be necessary, but in Java 1.4.2U1DP3
   // on OS X it became necessary in the applet, which is
   // probably a VM bug, but it's OK, I think it's harmless
   // - ST 7/13/04
   doLayout();
 }
Beispiel #11
0
 public void frameRate(double frameRate) {
   workspace.frameRate(frameRate);
 }
Beispiel #12
0
 public void setValue(int speed) {
   if (speedSlider.getValue() != speed) {
     speedSlider.setValue(speed);
   }
   enableLabels((int) workspace.speedSliderPosition());
 }
Beispiel #13
0
 private boolean newSizeOK(int sizeX, int sizeY) {
   return sizeX >= 1
       && sizeY >= 1
       && workspace.world().patchSize() * sizeX >= getMinimumSize().width;
 }
Beispiel #14
0
 void prepareForWorldResize() {
   workspace.jobManager.haltNonObserverJobs();
   workspace.world().clearTurtles();
   workspace.world().clearLinks();
 }
Beispiel #15
0
 void finishWorldResize() {
   workspace.patchesCreatedNotify();
   gWidget.resetSize();
   workspace.clearDrawing();
 }
Beispiel #16
0
 public void setDimensions(org.nlogo.api.WorldDimensions d, double patchSize) {
   workspace.world().patchSize(patchSize);
   setDimensions(d);
   patchSize(patchSize);
   gWidget.resetSize();
 }
Beispiel #17
0
 public double patchSize() {
   return workspace.world().patchSize();
 }
Beispiel #18
0
 public void dualView(boolean on) {
   workspace.dualView(on);
 }
Beispiel #19
0
 public void maxPycor(int maxPycor) {
   if (maxPycor >= 0) {
     newMaxY = maxPycor;
     edgesChanged = edgesChanged || (newMaxY != workspace.world().maxPycor());
   }
 }
Beispiel #20
0
 public UpdateMode updateMode() {
   return workspace.updateMode();
 }
Beispiel #21
0
 public double frameRate() {
   return workspace.frameRate();
 }
Beispiel #22
0
 public void wrappingY(boolean value) {
   newWrapY = value;
   wrappingChanged = wrappingChanged || (newWrapY != workspace.world().wrappingAllowedInY());
 }
Beispiel #23
0
 public void updateMode(UpdateMode updateMode) {
   workspace.updateMode(updateMode);
 }
Beispiel #24
0
 public void wrappingX(boolean value) {
   newWrapX = value;
   wrappingChanged = wrappingChanged || (newWrapX != workspace.world().wrappingAllowedInX());
 }
Beispiel #25
0
 public boolean dualView() {
   return workspace.dualView();
 }
Beispiel #26
0
 public void clearTurtles() {
   workspace.world().clearTurtles();
 }
Beispiel #27
0
 public void changeTopology(boolean wrapX, boolean wrapY) {
   workspace.changeTopology(wrapX, wrapY);
 }
Beispiel #28
0
 public void minPycor(int minPycor) {
   if (minPycor <= 0) {
     newMinY = minPycor;
     edgesChanged = edgesChanged || (newMinY != workspace.world().minPycor());
   }
 }