Tuesday, February 16, 2010

JHotDraw

JHotDraw (http://www.jhotdraw.org/) is one of the best open source Java drawing tools available (not that there are many). It covers the basics of vector drawing with the types of tools that people expect (see image below).

The main reason that I'm interested in it is that I like to draw. But I don't just like to draw for other people, I like to draw pictures as inputs to programming. A framework like JHotDraw gives me most of what I want from a drawing tool in a form that I can easily customize to create visual programming languages or semantic images. More about that to come in later posts.


If you're interested in getting started with JHotDraw, you should be very comfortable with Java. Although the code is pretty readable, there is a lot of it, there is very little up-to-date documentation and the included examples are fairly complex. To help you get started, I'm posting my implementation of the simplest possible JHotDraw application - HelloJHotDraw. This code is based on the latest version of JHotDraw at the time of this writing: v7.4.1 You can find the JavaDoc at http://www.randelshofer.ch/oop/jhotdraw/.

-- code --

import org.jhotdraw.app.SDIApplication;
import org.jhotdraw.samples.draw.DrawApplicationModel;
import org.jhotdraw.samples.draw.DrawView;

public class HelloJHotDraw extends SDIApplication {

public HelloJHotDraw() {

}

/**
* @param args
*/
public static void main(String[] args) {
HelloJHotDraw app = new HelloJHotDraw();
DrawApplicationModel model = new DrawApplicationModel();
model.setViewClass(DrawView.class);
app.setModel(model);
app.launch(args);
}

}

1 comment:

John laPlante said...

I liked this quote "I like to draw. But I don't just like to draw for other people"

That says a lot about the Keith I know. Made my day.