Esempio n. 1
0
 private void exportInterface() throws java.io.IOException {
   try {
     final String exportPath =
         org.nlogo.swing.FileDialog.show(
             this,
             "Export Interface",
             java.awt.FileDialog.SAVE,
             workspace.guessExportName("interface.png"));
     final java.io.IOException[] exception = new java.io.IOException[] {null};
     org.nlogo.swing.ModalProgressTask.apply(
         org.nlogo.awt.Hierarchy.getFrame(this),
         "Exporting...",
         new Runnable() {
           public void run() {
             try {
               workspace.exportInterface(exportPath);
             } catch (java.io.IOException ex) {
               exception[0] = ex;
             }
           }
         });
     if (exception[0] != null) {
       throw exception[0];
     }
   } catch (org.nlogo.awt.UserCancelException ex) {
     org.nlogo.util.Exceptions.ignore(ex);
   }
 }
Esempio n. 2
0
 @Override
 void action() {
   try {
     quit();
   } catch (UserCancelException ex) {
     org.nlogo.util.Exceptions.ignore(ex);
   }
 }
Esempio n. 3
0
  public void handle(org.nlogo.window.Events.InterfaceGlobalEvent e) {
    InterfaceGlobalWidget widget = e.widget;
    globalWidgets.add(e.widget);
    if (e.nameChanged) {
      compileAll();
    }
    // this check is needed because it might be a brand new widget
    // that doesn't have a variable yet - ST 3/3/04
    else if (workspace.world.observerOwnsIndexOf(widget.name().toUpperCase()) != -1) {
      if (e.updating) {
        widget.valueObject(workspace.world.getObserverVariableByName(widget.name()));
      }
      // note that we do this even if e.updating() is true -- that's because
      // the widget may not have accepted the new value as is - ST 8/17/03
      try {
        Object val = widget.valueObject();

        // Only set the global if the value has changed.  This prevents
        // use from firing our constraint code all the time.
        if (val != workspace.world.getObserverVariableByName(widget.name())) {
          // so that we do not interrupt without-interruption
          synchronized (workspace.world) {
            workspace.world.setObserverVariableByName(widget.name(), widget.valueObject());
          }
        }
      } catch (org.nlogo.api.ValueConstraint.Violation ex) {
        // If we have a Violation, then just ignore it because it
        // appears the constraints have changed on us since the
        // widget had it's value set.  The widget will be updated
        // and thus will result in its current value being constrained
        // appropriately by the widget. -- CLB
        org.nlogo.util.Exceptions.ignore(ex);
      } catch (org.nlogo.api.AgentException ex) {
        throw new IllegalStateException(ex);
      } catch (org.nlogo.api.LogoException ex) {
        // A Logo exception here is ignored to avoid a never
        // ending cascade of error popups.  Like the ignoring
        // of Violation exceptions, we are working under the
        // assumption that Sliders will always give us a
        // coerced value back. -- CLB
        org.nlogo.util.Exceptions.ignore(ex);
      }
    }
  }
Esempio n. 4
0
 /** opens a model from a file path. */
 public void openFromPath(String path, ModelType modelType) throws java.io.IOException {
   try {
     String source = org.nlogo.api.FileIO.file2String(path);
     if (source == null) {
       throw new IllegalStateException("couldn't open: '" + path + "'");
     }
     openFromSource(source, path, "Loading...", modelType);
   } catch (UserCancelException ex) {
     org.nlogo.util.Exceptions.ignore(ex);
   }
 }
Esempio n. 5
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);
   }
 }
Esempio n. 6
0
 @Override
 public void removeAllWidgets() {
   try {
     java.awt.Component[] comps = getComponents();
     setVisible(false);
     for (int i = 0; comps.length != i; i++) {
       if (comps[i] instanceof WidgetWrapper) {
         WidgetWrapper wrapper = (WidgetWrapper) comps[i];
         if (wrapper.widget() != viewWidget) {
           removeWidget(wrapper);
         }
       }
     }
   } catch (RuntimeException ex) {
     org.nlogo.util.Exceptions.handle(ex);
   } finally {
     setVisible(false);
   }
 }
Esempio n. 7
0
 // this had to be made public so that workspace.Evaluator could call it when
 // running command thunks. - JC 6/11/10
 public void runtimeError(Exception ex) {
   try {
     Instruction instruction = null;
     Context context = null;
     if (ex instanceof EngineException) {
       instruction = ((EngineException) ex).instruction();
       context = ((EngineException) ex).context();
     }
     if (instruction == null) {
       instruction = activation.procedure().code()[ip];
     }
     if (context == null) {
       context = this;
     }
     activation.procedure().code()[ip].workspace.runtimeError(job.owner, context, instruction, ex);
   } catch (RuntimeException ex2) {
     // well we tried to report the original exception to the user,
     // but a new exception happened. so we'll report the original
     // using plan B. - ST 8/29/07
     org.nlogo.util.Exceptions.handle(ex);
   }
 }