Using SPDE with IntelliJ
This is mostly a note to myself, but I figured out how to get SPDE to work in IntelliJ IDEA.
SPDE is a port of Processing to the Scala programming language written by Nathan Hamblen. Scala compiles to Java byte codes, so it can be integrated with code (like Processing) which is written in Java.
IntelliJ IDEA is an IDE for developing Java which also supports Scala.
Putting the all of these pieces together was relatively straightforward, but there were a few tricky bits I don’t want to lose track of.
- Download and install IDEA. I used the preview of the new Community Edition which is available here.
- Start IDEA and choose File/Settings
- Go to the Plugins section and choose the Available tab
- Scroll down and choose the Scala plugin.
- Now download the SPDE Graft jar from here.
- Unpack that somewhere. You’ll end up with a bunch of directories. Find the directory lib_managed/compile. It should contain two jar files named something like
processing-core-1.0.3_0.1.3.jar
andspde-core_2.7.6-1.0.3_0.1.3.jar
. - Now go back to IDEA and choose New Project. You want to select Java Module, but on the “desired technologies” page, choose Scala.
- Go to the Project Settings dialog. Select Libraries and hit the + button to create a library. Call it whatever you want.
- On the page for that library, choose “Attach Classes…” and go select the first of those SPDE jar files.
- Choose “Attach Classes…” again and go select the other jar file.
- Go to “Edit Configurations” and create a new configuration of type applet. Remember to set the module pulldown to refer to your project.
- I found that the version of IDEA I downloaded was missing the appletviewer.policy file. I just created one that looks like this:
grant { permission java.security.AllPermission; };
- Close the Project Settings dialog.
- Right click on the src directory of your project and choose “New Scala Class”. Create a class that extends PApplet.
- Hit compile and run. Your applet should appear. That’s it!
Here’s my first trivial SPDE example.
class simple_example extends processing.core.PApplet { override def setup() { size(400,400) } override def draw() { val x = mouseX val y = mouseY noStroke() fill(random(0,255),random(0,255),random(0,255)) beginShape(processing.core.PConstants.TRIANGLES) vertex(x-10,y-10) vertex(x+10,y-10) vertex(x,y+10) endShape() } }
I’m afraid I haven’t managed to export a jar file that I can embed in the blog yet, but the result looks something like this:
Hopefully I’ll have some better examples coming soon.
I realized after posting this that it can be simplified quite a bit. Between them, the IntelliJ Scala plugin and the processing jar are supplying everything you need. The spde jar isn’t required.
I’ll add a simplified version of these instructions soon.
I’ve been using Classic would you mind posting what you learned about optimal integration between Graft and IntelliJ?!