WISE-Community/WISE-VLE — pull request #289 by TheBizzle (2013-08-28 19:24:49+00:00)
Title: Improving NetLogo Support

Hey, sorry it took me so long to submit this. Working with applets is depressing....

1. I'm not sure that merging this directly into your `master` branch is really what you'll want to do, but maybe it is. Essentially, some changes are going to still need to be made on your end after merging this, in order to get out the behavior that you want.
1. You'll want to update the Airbags model on Berkeley WISE to use the modified versions that I created of the files. The files can be found in [this Gist](https://gist.github.com/TheBizzle/0dc3dcf4d8047583274a) that I created, or individually ([Airbags](https://gist.github.com/TheBizzle/0dc3dcf4d8047583274a/raw/24af4729381bf0b134f6c1f8d83fabb48d9aad02/airbags26.v0b.nlogo) and [data-export-modular](https://gist.github.com/TheBizzle/0dc3dcf4d8047583274a/raw/c394987603e64146a468940229b0d52935f8a6d9/data-export-modular.nls)).
2. You'll also want to make use of the `imageStr` that I'm pulling out of NetLogo in `netlogo.js`. It's a Base64-encoded PNG. (Not sure if you guys are aware of this or not, but, in modern browsers, you don't actually have to do any decoding, yourselves, in order to display a Base64-encoded image: http://css-tricks.com/data-uris/). You may even want to remove the generation of that image string from `netlogo.js` and force steps that want to generate images to do so, themselves.
2. I've thrown out some old `NetLogoLite5.jar.bak` file that was sitting around, because, well... it was in version control, so it didn't actually need to stick around. (i.e. If you need that back-up of the `.jar`, just get the old copy from version control.)
3. I've replaced the old `NetLogoLite5.jar` with a `NetLogoLite-5.0.x-zzzzzzz.jar` whose name contains the SHA hash for the NetLogo commit that is being used. People who, in the future, attempt to debug broken NetLogo applets might thank me for the versioning of this `.jar`
4. I created a NetLogo extension for exporting images from NetLogo for the web. It's called the "[Web Image](https://github.com/NetLogo/Web-Image-Extension)" extension. It exports images as arrays of bytes, and it also has primitives for Base64-encoding byte arrays and Base64-decoding strings into byte arrays.
5. This new NetLogo `.jar` mentioned in (3) includes some important fixes for being able to use the Web Image extension sanely. It doesn't strip out two chunks of the Scala library needed by the Web Image extension ([commit](https://github.com/NetLogo/NetLogo/commit/5a5445c9fc178a2ef4c12e1e0871c86d5c631e7f)) and it allows you to look up extension URLs in applets from a property that you can pass into the applet ([commit](https://github.com/NetLogo/NetLogo/commit/d27c65cea9b0f1bd511a3d829ecd189b356a5c30)). These changes exist on the NetLogo [`5.0.x-appletland`](https://github.com/NetLogo/NetLogo/tree/5.0.x-appletland) branch—the branch that any future NetLogo `.jar`s you guys use for applets ought to come from (which I'm telling you in case you, for some reason, need a new `.jar` in the future and I mysteriously die before then). This is cordoned off onto its own branch because we, at Northwestern, are making minimal efforts to support applets—hadn't I sworn to myself that I'd never deal with applets again before I undertook all this?—and because I decided that I didn't have time to write Java code for this that was actually _good_, so I just threw something together for it. At the height of my writing it, I even [decided to mock and insult myself a bit](https://github.com/NetLogo/NetLogo/commit/d27c65cea9b0f1bd511a3d829ecd189b356a5c30#L0R820), but... maybe that was unfair, as Java is the problem, not me!.
6. I changed the `netlogo.js` file a lot to get rid of some very crufty stuff. There was an awful lot of unnecessary polling, juggling of globals, needlessly getting handles on objects, and unnecessary functions laying around. So... I trashed most of that. Also, did you know that I hate mutable state?
* **Obligatory Functional Programming Plug**: I'd like to take this opportunity to tell you that leveraging a powerful static type system and utilizing functional programming constructs to avoid mutable state can help to you easily write clear, concise, easily-understandable, nearly-bug-free code in record time. Try it out today!
7. I didn't alter the model to be able to reimport the data that's being exported by `this.nlCmdReport("data-export:make-model-data")`—first, because the model is massive and scary, and, second, because I'm not sure how to do so meaningfully with that model. It looks like the data being exported is already processed data, so I'm not sure how to import it back in while still being meaningful to the activity. I would suggest that, if Concord wants that data getting back into the model, someone from Concord should write the NetLogo code (or NetLogo extension) to handle that.
8. Lastly (and mostly unrelated), not sure if you saw or not, but documentation for setting up the WISE development environment in IntelliJ is now available [here](https://github.com/WISE-Community/WISE/wiki/How-to-Setup-WISE:-Local-Development-Environment-using-IntelliJ-IDEA).