Debian Codegraph @

build/shared/tools/howto.txt

raw
1 TOOLS IN PROCESSING
2
3 With initial help from code contributed by fjen, Processing release 0147 and
4 later have a dynamically loading tools menu, which can be used to expand the
5 environment in fun and fantastic ways.
6
7 A Tool is a chunk of code that runs from the Tools menu. Tools are a means
8 of building onto the Processing Development Environment without needing to
9 rebuild the beast from source.
10
11 The interface (at least for now) is extremely simple:
12
13
14 package processing.app.tools.Tool;
15
16 public interface Tool extends Runnable {
17
18 public void init(Editor editor);
19
20 public void run();
21
22 public String getMenuTitle();
23 }
24
25
26 The init() method is called when an Editor window first opens. This means
27 you won't have access to a sketch object, or a GUI, and should only do minimal
28 setup. (However it'd be a good idea to stash the "Editor" object for later.)
29
30 The run() method will be called by the main application when the tool is
31 selected from the menu. This is called using invokeLater(), so that the tool
32 can safely use Swing and any other GUI yackety yack. If you're using a Frame,
33 you'll need to detect whether the Frame is already open (and bring it to the
34 front) or whether to create a new window.
35
36 Faceless tools also use the run() method. You should avail yourselves of the
37 statusNotice() and statusError() methods in Editor, to let the user know what's
38 happened. (As per p. 107 of the Processing Development Environment Tools
39 Reference User Interface Guide.)
40
41 The getMenuTitle() method just returns the title for what should appear in the
42 Tools menu. Not doing shortcuts for now, because resolving them between tools
43 (and the rest of the interface) is fugly. We would also need additional
44 modifiers for shift and alt. It just gets messy quick. Ordering in the Tools
45 menu is alphabetical.
46
47
48 //////////////////////////////////////////////////////////////
49
50
51 Where to put Tools
52
53 Core tools live inside the "tools" subfolder of the Processing distribution,
54 however users should install "contributed" tools in their sketchbook folder,
55 inside a subfolder named "tools".
56
57 If a tool works only with a particular release of Processing, then it may make
58 sense for the user to put things into the Processing tools folder, however we'd
59 like to keep users out of there as much as possible. In fact, it may not be
60 visible in future releases of Processing (for instance, on Mac OS X, the tools
61 folder is hidden inside the .app bundle).
62
63 Tools should be laid out similar to libraries, though the structure is a little
64 more flexible. The tool folder should be the name of the main class (without
65 its package name but using the same capitalization), and have a subfolder named
66 "tool" that contains the .jar and .zip files it uses. I'll use the included
67 "Mangler" tool as an example.
68
69 (This Tool is not built by default, due to a lack of non-dubious arguments
70 regarding the usefulness of including (by default) a Tool that mangles code.)
71
72 The folder should be called Mangler (note the capitalization), and contain:
73
74 sketchbook/tools/Mangler -> tool folder
75 sketchbook/tools/Mangler/tool -> location for code
76 sketchbook/tools/Mangler/tool/mangle.jar -> jar with one or more classes
77
78 The naming of jar and zip files in the tool/* directory doesn't matter.
79
80 When Processing loads, the jar and zip files will be searched for
81 Mangler.class. Even though this tool is found in package poos.shoe,
82 it will be sussed out. Package names are required.
83
84 Loose .class files are not supported, use only jar and zip files.
85
86
87 //////////////////////////////////////////////////////////////
88
89
90 What You Can and Cannot Do
91
92 The only API methods that are officially scrubbed and sanctioned by the
93 Commissioner on Fair API and Proper Manners for use by the Tools classes
94 are found in:
95
96 processing.app.Base
97 processing.app.Editor
98 processing.app.Preferences
99 processing.app.Sketch
100 processing.app.SketchCode
101
102 In fact, most of the API you should be talking to is inside Editor.
103 Full API documentation can be found on dev.processing.org:
104 http://dev.processing.org/reference/everything/
105 (Keep in mind that this is not always perfectly up to date, but we'll try.)
106
107 Of course, you're welcome to go spelunking through the rest of the API
108 (that's where all the fun stuff is anyway), but don't be upset when something
109 changes and breaks your tool and makes your users sad.
110
111 Currently, native code is not supported with tools. This might be possible,
112 but it's another potentially messy thing to dynamically add native library
113 paths to running code. (See "Future Releases" below.)
114
115
116 //////////////////////////////////////////////////////////////
117
118
119 Future Releases
120
121 In future releases, we are considering the following features:
122
123 1. How shortcut keys are handled.
124 http://dev.processing.org/bugs/show_bug.cgi?id=140
125
126 2. Whether to allow tools to dock into the Preferences panel.
127 http://dev.processing.org/bugs/show_bug.cgi?id=883
128
129 3. A means to run native code from the Tools menu.
130 http://dev.processing.org/bugs/show_bug.cgi?id=884
131
132 4. Methods for reorganizing the Tools menu, or placing contributed
133 Tools inside other menus (such as Edit or Sketch).
134 http://dev.processing.org/bugs/show_bug.cgi?id=885
135
136 This is the first round of documentation for the Tools menu, we reserve the
137 right to update, clarify, and change our mind in future releases.
138
139
140 //////////////////////////////////////////////////////////////
141
142
143 Ben Fry, last updated 19 August 2008