Professional Documents
Culture Documents
Howto
Howto
With initial help from code contributed by fjen, Processing release 0147 and
later have a dynamically loading tools menu, which can be used to expand the
environment in fun and fantastic ways.
A Tool is a chunk of code that runs from the Tools menu. Tools are a means
of building onto the Processing Development Environment without needing to
rebuild the beast from source.
The interface (at least for now) is extremely simple:
package processing.app.tools.Tool;
public interface Tool extends Runnable {
public void init(Editor editor);
public void run();
public String getMenuTitle();
}
The init() method is called when an Editor window first opens. This means
you won't have access to a sketch object, or a GUI, and should only do minimal
setup. (However it'd be a good idea to stash the "Editor" object for later.)
The run() method will be called by the main application when the tool is
selected from the menu. This is called using invokeLater(), so that the tool
can safely use Swing and any other GUI yackety yack. If you're using a Frame,
you'll need to detect whether the Frame is already open (and bring it to the
front) or whether to create a new window.
Faceless tools also use the run() method. You should avail yourselves of the
statusNotice() and statusError() methods in Editor, to let the user know what's
happened. (As per p. 107 of the Processing Development Environment Tools
Reference User Interface Guide.)
The getMenuTitle() method just returns the title for what should appear in the
Tools menu. Not doing shortcuts for now, because resolving them between tools
(and the rest of the interface) is fugly. We would also need additional
modifiers for shift and alt. It just gets messy quick. Ordering in the Tools
menu is alphabetical.
//////////////////////////////////////////////////////////////
Where to put Tools
Core tools live inside the "tools" subfolder of the Processing distribution,
however users should install "contributed" tools in their sketchbook folder,
inside a subfolder named "tools".
If a tool works only with a particular release of Processing, then it may make
sense for the user to put things into the Processing tools folder, however we'd
like to keep users out of there as much as possible. In fact, it may not be
visible in future releases of Processing (for instance, on Mac OS X, the tools