Exemplo 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);
   }
 }
Exemplo n.º 2
0
 @Override
 void action() {
   try {
     quit();
   } catch (UserCancelException ex) {
     org.nlogo.util.Exceptions.ignore(ex);
   }
 }
Exemplo 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);
      }
    }
  }
Exemplo 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);
   }
 }
Exemplo 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);
   }
 }