Ejemplo n.º 1
0
  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    int start = argEvalIntValue(context, 1);
    int stop = argEvalIntValue(context, 2);
    int size = list.size();
    if (start < 0) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.startIsLessThanZero", start));
    } else if (stop < start) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsLessThanStart", stop, start));

    } else if (stop > size) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsGreaterThanListSize", stop, size));
    }
    return list.logoSublist(start, stop);
  }
Ejemplo n.º 2
0
 // This is used both when loading a model and when the user is making
 // new widgets in the UI.  For most widget types, the same type string
 // is used in both places. - ST 3/17/04
 public Widget makeWidget(String type, boolean loading) {
   type = "DUMMY " + type.toUpperCase();
   Widget fromRegistry = org.nlogo.window.WidgetRegistry.apply(type);
   if (fromRegistry != null) {
     return fromRegistry;
   } else if (type.equals("DUMMY SLIDER")) {
     return new org.nlogo.window.DummySliderWidget();
   } else if (type.equals("DUMMY CHOOSER")
       || // current name
       type.equals("DUMMY CHOICE")) // old name, used in old models
   {
     return new org.nlogo.window.DummyChooserWidget(
         new org.nlogo.nvm.DefaultCompilerServices(workspace.compiler()));
   } else if (type.equals("DUMMY BUTTON")) {
     return new org.nlogo.window.DummyButtonWidget();
   } else if (type.equals("DUMMY PLOT")) {
     // note that plots on the HubNet client must have the name of a plot
     // on the server, thus, feed the dummy plot widget the names of
     // the current plots so the user can select one. We override
     // this method in InterfacePanel since regular plots are handled
     // differently ev 1/25/07
     String[] names = workspace.plotManager().getPlotNames();
     if (names.length > 0) {
       return DummyPlotWidget.apply(names[0], workspace.plotManager());
     } else {
       return DummyPlotWidget.apply("plot 1", workspace.plotManager());
     }
   } else if (type.equals("DUMMY MONITOR")) {
     return new org.nlogo.window.DummyMonitorWidget();
   } else if (type.equals("DUMMY INPUT")
       || // in the GUI, it's "Input Box"
       type.equals("DUMMY INPUTBOX")) // in saved models, it's "INPUTBOX"
   {
     java.awt.Font font =
         new java.awt.Font(org.nlogo.awt.Fonts.platformMonospacedFont(), java.awt.Font.PLAIN, 12);
     return new org.nlogo.window.DummyInputBoxWidget(
         new org.nlogo.window.CodeEditor(
             1, 20, font, false, null, new EditorColorizer(workspace), I18N.guiJ().fn()),
         new org.nlogo.window.CodeEditor(
             5, 20, font, true, null, new EditorColorizer(workspace), I18N.guiJ().fn()),
         this,
         new org.nlogo.nvm.DefaultCompilerServices(workspace.compiler()));
   } else if (type.equals("DUMMY OUTPUT")) // currently in saved models only - ST 3/17/04
   {
     return new org.nlogo.window.OutputWidget();
   } else if (type.equals("DUMMY CC-WINDOW")) // definitely in saved models only
   {
     // in current NetLogo versions, the command center goes in
     // a JSplitPane instead of in the InterfacePanel, so we ignore
     // the entry in the model - ST 7/13/04, 3/14/06
     return null;
   } else if (type.equals("DUMMY GRAPHICS-WINDOW")
       || type.equals("DUMMY VIEW")
       || type.equals("VIEW")) {
     view = new org.nlogo.window.DummyViewWidget(workspace.world);
     return view;
   } else {
     throw new IllegalStateException("unknown widget type: " + type);
   }
 }
Ejemplo n.º 3
0
 private boolean checkWithUser() {
   return (!workspace.jobManager.anyPrimaryJobs())
       || org.nlogo.swing.OptionDialog.show(
               this,
               I18N.guiJ().get("common.messages.warning"),
               "Changing the size will halt and clear the world.",
               new String[] {"Change Size", I18N.guiJ().get("common.buttons.cancel")})
           == 0;
 }
Ejemplo n.º 4
0
  public boolean canAddWidget(String widget) {
    if (widget.equals(I18N.guiJ().get("tabs.run.widgets.view"))) {
      return !hasView();
    } else if (widget.equals(I18N.guiJ().get("tabs.run.widgets.plot"))) {
      // you can't add a plot to the client interface unless
      // there are plots in the server interface so enable the
      // plot button accordingly ev 1/25/07
      return workspace.plotManager().getPlotNames().length > 0;
    }

    return true;
  }
Ejemplo n.º 5
0
 private void checkWithUserBeforeOpening2DModelin3D() throws UserCancelException {
   String[] options = {
     I18N.guiJ().get("common.buttons.continue"), I18N.guiJ().get("common.buttons.cancel")
   };
   String message =
       "You are attempting to open a 2D model in "
           + org.nlogo.api.Version.version()
           + ". "
           + "You might need to make changes before it will work in 3D.";
   if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) {
     throw new UserCancelException();
   }
 }
Ejemplo n.º 6
0
 // This is used both when loading a model and when the user is making
 // new widgets in the UI.  For most widget types, the same type string
 // is used in both places. - ST 3/17/04
 @Override
 public Widget makeWidget(String type, boolean loading) {
   type = type.toUpperCase();
   Widget fromRegistry = org.nlogo.window.WidgetRegistry.apply(type);
   if (fromRegistry != null) {
     return fromRegistry;
   } else if (type.equalsIgnoreCase("SLIDER")) {
     return new org.nlogo.window.SliderWidget(workspace.world.auxRNG) {
       @Override
       public int sourceOffset() {
         return org.nlogo.workspace.Evaluator.sourceOffset(org.nlogo.agent.Observer.class, false);
       }
     };
   } else if (type.equals("CHOOSER")
       || // current name
       type.equals("CHOICE")) // old name, used in old models
   {
     return new org.nlogo.window.ChooserWidget(workspace);
   } else if (type.equals("BUTTON")) {
     return new org.nlogo.window.ButtonWidget(workspace.world.mainRNG);
   } else if (type.equals("PLOT")) {
     return org.nlogo.window.PlotWidget.apply(workspace.plotManager());
   } else if (type.equals("MONITOR")) {
     return new org.nlogo.window.MonitorWidget(workspace.world.auxRNG);
   } else if (type.equals("INPUT")
       || // in the GUI, it's "Input Box"
       type.equals("INPUTBOX")) // in saved models, it's "INPUTBOX"
   {
     java.awt.Font font =
         new java.awt.Font(org.nlogo.awt.Fonts.platformMonospacedFont(), java.awt.Font.PLAIN, 12);
     return new org.nlogo.window.InputBoxWidget(
         new org.nlogo.window.CodeEditor(
             1, 20, font, false, null, new EditorColorizer(workspace), I18N.guiJ().fn()),
         new org.nlogo.window.CodeEditor(
             5, 20, font, true, null, new EditorColorizer(workspace), I18N.guiJ().fn()),
         workspace,
         this);
   } else if (type.equals("OUTPUT")) // currently in saved models only - ST 3/17/04
   {
     return new org.nlogo.window.OutputWidget();
   } else if (type.equals("CC-WINDOW")) // definitely in saved models only
   {
     // in current NetLogo versions, the command center goes in
     // a JSplitPane instead of in the InterfacePanel, so we ignore
     // the entry in the model - ST 7/13/04, 3/14/06
     return null;
   } else {
     throw new IllegalStateException("unknown widget type: " + type);
   }
 }
Ejemplo n.º 7
0
 // this is bordering on comical its so confusing.
 // this method runs for the hubnet client editor.
 // im not yet sure if it runs anywhere else.
 // that seems like bugs waiting to happen. JC - 12/20/10
 protected void doPopup(java.awt.event.MouseEvent e) {
   javax.swing.JPopupMenu menu = new javax.swing.JPopupMenu();
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.button"), "BUTTON", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.slider"), "SLIDER", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.switch"), "SWITCH", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.chooser"), "CHOOSER", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.input"), "INPUT", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.monitor"), "MONITOR", e.getX(), e.getY()));
   WidgetCreationMenuItem plot =
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.plot"), "PLOT", e.getX(), e.getY());
   // if there are no plots in this model, then you can't have a plot in a hubnet client.
   if (workspace.plotManager().plots().size() == 0) {
     plot.setEnabled(false);
   }
   menu.add(plot);
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.note"), "NOTE", e.getX(), e.getY()));
   menu.show(this, e.getX(), e.getY());
 }
Ejemplo n.º 8
0
 private boolean userWantsToSaveFirst() throws UserCancelException {
   String[] options = {
     I18N.guiJ().get("common.buttons.save"), "Discard", I18N.guiJ().get("common.buttons.cancel")
   };
   String message = "Do you want to save the changes you made to this model?";
   switch (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options)) {
     case 0:
       return true;
     case 1:
       return false;
     default:
       throw new UserCancelException();
   }
 }
Ejemplo n.º 9
0
 public double report_1(Context context, double d0, double d1) throws LogoException {
   if (d1 == 0) {
     throw new EngineException(
         context, this, I18N.errorsJ().get("org.nlogo.prim.etc.$common.divByZero"));
   }
   return validDouble(d0 - (StrictMath.floor(d0 / d1) * d1));
 }
Ejemplo n.º 10
0
    @Override
    void action() throws UserCancelException, java.io.IOException {
      final String importPath =
          org.nlogo.swing.FileDialog.show(
              FileMenu.this, "Import HubNet Client Interface", java.awt.FileDialog.LOAD, null);
      final java.io.IOException[] exception = new java.io.IOException[] {null};
      final int choice =
          org.nlogo.swing.OptionDialog.show(
              app.workspace().getFrame(),
              "Import HubNet Client",
              "Which section would you like to import from?",
              new String[] {
                "Interface Tab", "HubNet client", I18N.guiJ().get("common.buttons.cancel")
              });

      if (choice != 2) {
        org.nlogo.swing.ModalProgressTask.apply(
            org.nlogo.awt.Hierarchy.getFrame(FileMenu.this),
            "Importing Drawing...",
            new Runnable() {
              public void run() {
                try {
                  app.workspace().getHubNetManager().importClientInterface(importPath, choice == 1);
                } catch (java.io.IOException ex) {
                  exception[0] = ex;
                }
              }
            });
        if (exception[0] != null) {
          throw exception[0];
        }
      }
    }
Ejemplo n.º 11
0
 private void checkWithUserBeforeSavingModelFromOldVersion() throws UserCancelException {
   if (!org.nlogo.api.Version.compatibleVersion(savedVersion)) {
     String[] options = {
       I18N.guiJ().get("common.buttons.save"), I18N.guiJ().get("common.buttons.cancel")
     };
     String message =
         "This model was made with "
             + savedVersion
             + ". "
             + "If you save it in "
             + org.nlogo.api.Version.version()
             + " it may not work in the old version anymore.";
     if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) {
       throw new UserCancelException();
     }
     savedVersion = org.nlogo.api.Version.version();
   }
 }
Ejemplo n.º 12
0
 private void checkWithUserBeforeOpening3DModelin2D(String version) throws UserCancelException {
   String[] options = {
     I18N.guiJ().get("common.buttons.continue"), I18N.guiJ().get("common.buttons.cancel")
   };
   String message =
       "You are attempting to open a model that was created"
           + " in a 3D version of NetLogo.  (This is "
           + org.nlogo.api.Version.version()
           + "; "
           + "the model was created in "
           + version
           + ".) "
           + "NetLogo can try to open the model, but it may "
           + "or may not work.";
   if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) {
     throw new UserCancelException();
   }
 }
Ejemplo n.º 13
0
  public FileMenu(App app, ModelSaver modelSaver, AppletSaver appletSaver) {
    super(I18N.guiJ().get("menu.file"));
    this.app = app;
    this.modelSaver = modelSaver;
    this.appletSaver = appletSaver;
    addMenuItem('N', new NewAction());
    addMenuItem('O', new OpenAction());
    addMenuItem('M', new ModelsLibraryAction());
    addSeparator();
    addMenuItem('S', new SaveAction());
    addMenuItem(new SaveAsAction());
    addMenuItem(new SaveAppletAction());
    addSeparator();
    addMenuItem(I18N.guiJ().get("menu.file.print"), 'P', app.tabs().printAction());
    addSeparator();
    org.nlogo.swing.Menu exportMenu = new org.nlogo.swing.Menu(I18N.guiJ().get("menu.file.export"));
    exportMenu.addMenuItem(new ExportWorldAction());
    exportMenu.addMenuItem(new ExportPlotAction());
    exportMenu.addMenuItem(new ExportAllPlotsAction());
    exportMenu.addMenuItem(new ExportGraphicsAction());
    exportMenu.addMenuItem(new ExportInterfaceAction());
    exportMenu.addMenuItem(new ExportOutputAction());
    add(exportMenu);
    addSeparator();
    org.nlogo.swing.Menu importMenu = new org.nlogo.swing.Menu(I18N.guiJ().get("menu.file.import"));
    importMenu.addMenuItem(new ImportWorldAction());
    importMenu.addMenuItem(new ImportPatchColorsAction());
    importMenu.addMenuItem(new ImportPatchColorsRGBAction());
    if (!org.nlogo.api.Version.is3D()) {
      importMenu.addMenuItem(new ImportDrawingAction());
    }
    importMenu.addMenuItem(new ImportClientAction());

    add(importMenu);
    if (!System.getProperty("os.name").startsWith("Mac")) {
      addSeparator();
      addMenuItem('Q', new QuitAction());
    }
    // initialize here, unless there's a big problem early on in the
    // initial load process it'll get initialize properly below
    // maybe this fixes Nigel Gilbert's bug. maybe. ev 1/30/07
    savedVersion = org.nlogo.api.Version.version();
  }
Ejemplo n.º 14
0
 @Override
 public java.awt.Dimension getMinimumSize() {
   java.awt.Dimension d = super.getMinimumSize();
   java.awt.FontMetrics fontMetrics = getFontMetrics(getFont());
   if (!labelsBelow) {
     d.width =
         StrictMath.max(
             d.width,
             fontMetrics.stringWidth(I18N.guiJ().get("tabs.run.speedslider.normalspeed")));
   } else {
     d.width =
         StrictMath.max(
             d.width,
             fontMetrics.stringWidth(
                     "                         "
                         + I18N.guiJ().get("tabs.run.speedslider.faster"))
                 + 10);
   }
   return d;
 }
Ejemplo n.º 15
0
 @Override
 public Object report(final org.nlogo.nvm.Context context) throws LogoException {
   int index = argEvalIntValue(context, 0);
   Object obj = args[1].report(context);
   if (index < 0) {
     throw new EngineException(
         context, this, I18N.errorsJ().getN("org.nlogo.prim.etc.$common.negativeIndex", index));
   }
   if (obj instanceof LogoList) {
     LogoList list = (LogoList) obj;
     if (index >= list.size()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.etc.$common.indexExceedsListSize",
                   index,
                   Dump.logoObject(list),
                   list.size()));
     }
     return list.get(index);
   } else if (obj instanceof String) {
     String string = (String) obj;
     if (index >= string.length()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.etc.$common.indexExceedsListSize",
                   index,
                   Dump.logoObject(string),
                   string.length()));
     }
     return string.substring(index, index + 1);
   } else {
     throw new ArgumentTypeException(
         context, this, 1, Syntax.ListType() | Syntax.StringType(), obj);
   }
 }
Ejemplo n.º 16
0
 public void addCornerChoices() {
   cornerChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.corner.bottomLeft"),
           new boolean[] {false, true, false, true},
           new boolean[] {true, false, true, false}));
   cornerChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.corner.topLeft"),
           new boolean[] {false, true, true, false},
           new boolean[] {true, false, false, true}));
   cornerChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.corner.topRight"),
           new boolean[] {true, false, true, false},
           new boolean[] {false, true, false, true}));
   cornerChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.corner.bottomRight"),
           new boolean[] {true, false, false, true},
           new boolean[] {false, true, true, false}));
 }
Ejemplo n.º 17
0
  // this is called whenever a workspace is about to be destroyed
  public void offerSave() throws UserCancelException {

    // check if we have an open movie
    if (app.workspace().movieEncoder != null) {
      String[] options = {
        I18N.guiJ().get("common.buttons.ok"), I18N.guiJ().get("common.buttons.cancel")
      };
      String message =
          "There is a movie in progress. "
              + "Are you sure you want to exit this model? "
              + "You will lose the contents of your movie.";
      if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) == 1) {
        throw new UserCancelException();
      }
      app.workspace().movieEncoder.cancel();
      app.workspace().movieEncoder = null;
    }

    if (app.dirtyMonitor().dirty() && userWantsToSaveFirst()) {
      save();
    }
  }
Ejemplo n.º 18
0
 public void addEdgeChoices() {
   edgeChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.edge.bottom"),
           new boolean[] {true, true, false, true},
           new boolean[] {false, false, true, false}));
   edgeChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.edge.top"),
           new boolean[] {true, true, true, false},
           new boolean[] {false, false, false, true}));
   edgeChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.edge.right"),
           new boolean[] {true, false, true, true},
           new boolean[] {false, true, false, false}));
   edgeChoices.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.edge.left"),
           new boolean[] {false, true, true, true},
           new boolean[] {true, false, false, false}));
 }
Ejemplo n.º 19
0
 public void addOriginConfigurations() {
   originConfigurations.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.center"),
           new boolean[] {false, true, false, true},
           new boolean[] {false, false, false, false}));
   originConfigurations.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.corner"),
           new boolean[] {true, true, true, true},
           new boolean[] {false, false, false, false}));
   originConfigurations.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.edge"),
           new boolean[] {true, true, true, true},
           new boolean[] {false, false, false, false}));
   originConfigurations.add(
       new OriginConfiguration(
           I18N.guiJ().get("edit.viewSettings.origin.location.custom"),
           new boolean[] {true, true, true, true},
           new boolean[] {false, false, false, false}));
 }
Ejemplo n.º 20
0
 public void actionPerformed(java.awt.event.ActionEvent e) {
   try {
     action();
   } catch (UserCancelException ex) {
     org.nlogo.util.Exceptions.ignore(ex);
   } catch (java.io.IOException ex) {
     javax.swing.JOptionPane.showMessageDialog(
         FileMenu.this,
         ex.getMessage(),
         I18N.guiJ().get("common.messages.error"),
         javax.swing.JOptionPane.ERROR_MESSAGE);
   }
 }
Ejemplo n.º 21
0
  public void deleteFile(String filePath) throws java.io.IOException {
    org.nlogo.api.File file = findOpenFile(filePath);

    if (file != null) {
      throw new java.io.IOException("You need to close the file before deletion");
    }
    java.io.File checkFile = new java.io.File(filePath);
    if (!checkFile.exists()) {
      throw new java.io.IOException(
          I18N.errorsJ().get("org.nlogo.workspace.DefaultFileManager.cannotDeleteNonExistantFile"));
    }
    if (!checkFile.canWrite()) {
      throw new java.io.IOException("Modification to this file is denied.");
    }
    if (!checkFile.isFile()) {
      throw new java.io.IOException(
          I18N.errorsJ().get("org.nlogo.workspace.DefaultFileManager.canOnlyDeleteFiles"));
    }

    if (!checkFile.delete()) {
      throw new java.io.IOException("Deletion failed.");
    }
  }
Ejemplo n.º 22
0
  @Override
  protected void doPopup(final java.awt.event.MouseEvent e) {
    JPopupMenu menu = new JPopupMenu();
    // add all the widgets
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.button"), "BUTTON", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.slider"), "SLIDER", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.switch"), "SWITCH", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.chooser"), "CHOOSER", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.input"), "INPUT", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.monitor"), "MONITOR", e.getX(), e.getY()));
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.plot"), "PLOT", e.getX(), e.getY()));
    WidgetCreationMenuItem outputItem =
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.output"), "OUTPUT", e.getX(), e.getY());
    if (getOutputWidget() != null) {
      outputItem.setEnabled(false);
    }
    menu.add(outputItem);
    menu.add(
        new WidgetCreationMenuItem(
            I18N.guiJ().get("tabs.run.widgets.note"), "NOTE", e.getX(), e.getY()));

    // add extra stuff
    menu.add(new javax.swing.JPopupMenu.Separator());
    menu.add(exportItem());

    menu.show(this, e.getX(), e.getY());
  }
Ejemplo n.º 23
0
 // identical to perform_1() above... BUT with a profiling hook added
 public void profiling_perform_1(final org.nlogo.nvm.Context context) {
   if (!context.atTopActivation()) {
     context.finished = true;
   } else {
     if (context.activation.procedure().isReporter()
         || context.activation.procedure().isTask()
             && context.activation.procedure().parent().isReporter()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN("org.nlogo.prim.etc._stop.notAllowedInsideToReport", displayName()));
     }
     workspace.profilingTracer().closeCallRecord(context, context.activation);
     context.stop();
   }
 }
Ejemplo n.º 24
0
  public void ensureMode(org.nlogo.api.FileMode openMode) throws java.io.IOException {
    if (!hasCurrentFile()) {
      throw new java.io.IOException(
          I18N.errorsJ().get("org.nlogo.workspace.DefaultFileManager.noOpenFile"));
    }

    if (currentFile.mode() == org.nlogo.api.FileModeJ.NONE()) {
      try {
        currentFile.open(openMode);
      } catch (java.io.FileNotFoundException ex) {
        throw new java.io.IOException(
            "The file " + currentFile.getAbsolutePath() + " cannot be found");
      } catch (java.io.IOException ex) {
        throw new java.io.IOException(ex.getMessage());
      }
    } else if (currentFile.mode() != openMode) {
      String mode = (currentFile.mode() == org.nlogo.api.FileModeJ.READ()) ? "READING" : "WRITING";

      throw new java.io.IOException("You can only use " + mode + " primitives with this file");
    }
  }
Ejemplo n.º 25
0
 public void perform_1(final org.nlogo.nvm.Context context) {
   // check: are we in an ask?
   if (!context.atTopActivation()) {
     // if so, then "stop" means that this agent prematurely
     // finishes its participation in the ask.
     context.finished = true;
   } else {
     // if we're not in an ask, then "stop" means to exit this procedure
     // immediately.  first we must check that it's a command procedure
     // and not a reporter procedure.
     if (context.activation.procedure().isReporter()
         || context.activation.procedure().isTask()
             && context.activation.procedure().parent().isReporter()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN("org.nlogo.prim.etc._stop.notAllowedInsideToReport", displayName()));
     }
     context.stop();
   }
 }
Ejemplo n.º 26
0
 public double report_1(Context context, AgentSet sourceSet, Reporter block) throws LogoException {
   block.checkAgentSetClass(sourceSet, context);
   Context freshContext = new Context(context, sourceSet);
   int result = 0;
   for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext(); ) {
     Agent tester = iter.next();
     Object value = freshContext.evaluateReporter(tester, block);
     if (!(value instanceof Boolean)) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.$common.expectedBooleanValue",
                   displayName(),
                   Dump.logoObject(tester),
                   Dump.logoObject(value)));
     }
     if (((Boolean) value).booleanValue()) {
       result++;
     }
   }
   return result;
 }
Ejemplo n.º 27
0
 @Override
 public Object report(Context context) {
   LogoList list = argEvalList(context, 0);
   double winner = 0;
   Double boxedWinner = null;
   for (Object elt : list) {
     if (elt instanceof Double) {
       Double boxedValue = (Double) elt;
       double value = boxedValue.doubleValue();
       if (boxedWinner == null || value > winner) {
         winner = value;
         boxedWinner = boxedValue;
       }
     }
   }
   if (boxedWinner == null) {
     throw new EngineException(
         context,
         this,
         I18N.errorsJ()
             .getN("org.nlogo.prim._max.cantFindMaxOfListWithNoNumbers", Dump.logoObject(list)));
   }
   return boxedWinner;
 }
Ejemplo n.º 28
0
 void enableLabels(int value) {
   if (value == 0) {
     if (labelsBelow) {
       normal.setText("      " + I18N.guiJ().get("tabs.run.speedslider.normalspeed"));
     } else {
       normal.setText(I18N.guiJ().get("tabs.run.speedslider.normalspeed"));
     }
   } else if (value < 0) {
     if (labelsBelow) {
       normal.setText(
           I18N.guiJ().get("tabs.run.speedslider.slower") + "                         ");
     } else {
       normal.setText(I18N.guiJ().get("tabs.run.speedslider.slower"));
     }
   } else {
     if (labelsBelow) {
       normal.setText(
           "                         " + I18N.guiJ().get("tabs.run.speedslider.faster"));
     } else {
       normal.setText(I18N.guiJ().get("tabs.run.speedslider.faster"));
     }
   }
 }
Ejemplo n.º 29
0
 private void notifyUserNotValidFile() throws UserCancelException {
   String[] options = {I18N.guiJ().get("common.buttons.ok")};
   org.nlogo.swing.OptionDialog.show(
       this, "NetLogo", "The file is not a valid NetLogo model file.", options);
   throw new UserCancelException();
 }
Ejemplo n.º 30
0
 QuitAction() {
   super(I18N.guiJ().get("menu.file.quit"));
 }