Exemplo n.º 1
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();
   }
 }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
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();
   }
 }
Exemplo n.º 4
0
 public InterfacePanel(
     org.nlogo.window.ViewWidgetInterface viewWidget, org.nlogo.window.GUIWorkspace workspace) {
   super(workspace);
   this.viewWidget = viewWidget;
   workspace.setWidgetContainer(this);
   // in 3d don't add the view widget since it's always
   // disabled there's no reason for it to take space 7/5/07
   if (!Version.is3D()) {
     addWidget((Widget) viewWidget, 0, 0, false, false);
   }
   ((Widget) viewWidget).deleteable_$eq(false);
   addKeyListener(this);
   addMouseListener(this);
 }
Exemplo n.º 5
0
 /**
  * opens a NetLogo model from the previously loaded source. This is complicated and I'm not
  * totally sure I understand it, but it really should be documented...
  *
  * @param source the model source. May not be null.
  * @param path the full pathname of the model, including the file. For example:
  *     "/home/mmh/models/My_Model.nlogo". This may be null, if, for example, this is a new model,
  *     or the origin is unknown.
  * @param message the message to display in the "loading" modal dialog.
  * @param modelType the type of this model. Must be one of the types defined in
  *     org.nlogo.workspace.Workspace.
  */
 void openFromSource(String source, String path, String message, ModelType modelType)
     throws UserCancelException {
   // map elements are { source, info, resources, version }
   Map<ModelSection, String[]> map = ModelReader.parseModel(source);
   if (map == null || map.get(ModelSectionJ.VERSION()).length == 0) {
     notifyUserNotValidFile();
   }
   String version = org.nlogo.api.ModelReader.parseVersion(map);
   if (version == null || !version.startsWith("NetLogo")) {
     notifyUserNotValidFile();
   }
   if (org.nlogo.api.Version.is3D() && !org.nlogo.api.Version.is3D(version)) {
     checkWithUserBeforeOpening2DModelin3D();
   }
   if (!org.nlogo.api.Version.is3D() && org.nlogo.api.Version.is3D(version)) {
     checkWithUserBeforeOpening3DModelin2D(version);
   } else {
     if (!org.nlogo.api.Version.knownVersion(version)) {
       checkWithUserBeforeOpeningModelFromFutureVersion(version);
     }
   }
   openFromMap(map, path, message, modelType);
   savedVersion = version;
 }
Exemplo n.º 6
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();
   }
 }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
0
 public static void doHelp(java.awt.Component comp, String token) {
   if (!quickHelpLoaded) {
     quickHelpWords = loadHelp(QUICKHELPWORDS_PATH);
     // if we're not in 3D don't load the 3d dictionary words
     // cause we don't need 'em and they'll override the 2d
     // dictionary ev 10/25/07
     if (org.nlogo.api.Version.is3D()) {
       quickHelpWords3d = loadHelp(QUICKHELPWORDS_PATH3D);
     } else {
       quickHelpWords3d = new HashMap<String, String>();
     }
     quickHelpLoaded = true;
   }
   if (token == null) {
     return;
   }
   token = token.toLowerCase();
   // if there is an entry in the 3D dictionary then it overrides
   // the 2D entry ev 10/25/07
   if (quickHelpWords3d.containsKey(token)) {
     openDictionary(comp, token, quickHelpWords3d);
   } else if (quickHelpWords.containsKey(token)) {
     openDictionary(comp, token, quickHelpWords);
   } else {
     if (0
         == javax.swing.JOptionPane.showConfirmDialog(
             comp,
             token.toUpperCase()
                 + " could not be found in the NetLogo Dictionary.\n"
                 + "Would you like to open the full NetLogo Dictionary?",
             "NetLogo",
             javax.swing.JOptionPane.YES_NO_OPTION)) {
       org.nlogo.swing.BrowserLauncher.openURL(comp, "docs/index2.html", true);
     }
   }
 }
Exemplo n.º 9
0
 public static String modelSuffix() {
   return org.nlogo.api.Version.is3D() ? "nlogo3d" : "nlogo";
 }
Exemplo n.º 10
0
 SaveAppletAction() {
   super(I18N.guiJ().get("menu.file.saveAsApplet"));
   // disabled for 3-D since it doesn't work - ST 2/25/05
   setEnabled(!org.nlogo.api.Version.is3D());
 }