|
10
|
1 |
/* |
|
9
|
2 |
TUIO processing library - part of the reacTIVision project |
|
|
3 |
http://reactivision.sourceforge.net/ |
|
4
|
4 |
|
|
9
|
5 |
Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu> |
|
4
|
6 |
|
|
|
7 |
This program is free software; you can redistribute it and/or modify |
|
|
8 |
it under the terms of the GNU General Public License as published by |
|
|
9 |
the Free Software Foundation; either version 2 of the License, or |
|
|
10 |
(at your option) any later version. |
|
|
11 |
|
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
15 |
GNU General Public License for more details. |
|
|
16 |
|
|
|
17 |
You should have received a copy of the GNU General Public License |
|
|
18 |
along with this program; if not, write to the Free Software |
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
20 |
*/ |
|
|
21 |
|
|
28
|
22 |
/* |
|
|
23 |
Modified by alexandre.bastien@iri.centrepompidou.fr to manage TUIO strings. |
|
|
24 |
*/ |
|
|
25 |
|
|
4
|
26 |
package TUIO; |
|
|
27 |
|
|
|
28 |
import java.awt.event.*; |
|
|
29 |
import java.lang.reflect.*; |
|
|
30 |
import processing.core.*; |
|
|
31 |
import java.util.*; |
|
|
32 |
|
|
|
33 |
public class TuioProcessing implements TuioListener { |
|
9
|
34 |
|
|
|
35 |
private PApplet parent; |
|
|
36 |
private Method addTuioObject, removeTuioObject, updateTuioObject, addTuioCursor, removeTuioCursor, updateTuioCursor, addTuioString, removeTuioString, updateTuioString, refresh; |
|
|
37 |
private TuioClient client; |
|
|
38 |
|
|
|
39 |
public TuioProcessing(PApplet parent) { |
|
|
40 |
this(parent,3333); |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
public TuioProcessing(PApplet parent, int port) { |
|
|
44 |
this.parent = parent; |
|
|
45 |
parent.registerDispose(this); |
|
|
46 |
|
|
|
47 |
try { refresh = parent.getClass().getMethod("refresh",new Class[] { TuioTime.class } ); } |
|
|
48 |
catch (Exception e) { |
|
|
49 |
System.out.println("TUIO: missing or wrong 'refresh(TuioTime bundleTime)' method implementation"); |
|
|
50 |
refresh = null; |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
try { addTuioObject = parent.getClass().getMethod("addTuioObject", new Class[] { TuioObject.class }); } |
|
|
54 |
catch (Exception e) { |
|
|
55 |
System.out.println("TUIO: missing or wrong 'addTuioObject(TuioObject tobj)' method implementation"); |
|
|
56 |
addTuioObject = null; |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
try { removeTuioObject = parent.getClass().getMethod("removeTuioObject", new Class[] { TuioObject.class }); } |
|
|
60 |
catch (Exception e) { |
|
|
61 |
System.out.println("TUIO: missing or wrong 'removeTuioObject(TuioObject tobj)' method implementation"); |
|
|
62 |
removeTuioObject = null; |
|
|
63 |
} |
|
|
64 |
|
|
|
65 |
try { updateTuioObject = parent.getClass().getMethod("updateTuioObject", new Class[] { TuioObject.class }); } |
|
|
66 |
catch (Exception e) { |
|
|
67 |
System.out.println("TUIO: missing or wrong 'updateTuioObject(TuioObject tobj)' method implementation"); |
|
|
68 |
updateTuioObject = null; |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
try { addTuioCursor = parent.getClass().getMethod("addTuioCursor", new Class[] { TuioCursor.class }); } |
|
|
72 |
catch (Exception e) { |
|
|
73 |
System.out.println("TUIO: missing or wrong 'addTuioCursor(TuioCursor tcur)' method implementation"); |
|
|
74 |
addTuioCursor = null; |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
try { removeTuioCursor = parent.getClass().getMethod("removeTuioCursor", new Class[] { TuioCursor.class }); } |
|
|
78 |
catch (Exception e) { |
|
|
79 |
System.out.println("TUIO:missing or wrong 'removeTuioCursor(TuioCursor tcur)' method implementation"); |
|
|
80 |
removeTuioCursor = null; |
|
|
81 |
} |
|
|
82 |
|
|
|
83 |
try { updateTuioCursor = parent.getClass().getMethod("updateTuioCursor", new Class[] { TuioCursor.class }); } |
|
|
84 |
catch (Exception e) { |
|
|
85 |
System.out.println("TUIO: missing or wrong 'updateTuioCursor(TuioCursor tcur)' method implementation"); |
|
|
86 |
updateTuioCursor = null; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
try { addTuioString = parent.getClass().getMethod("addTuioString", new Class[] { TuioString.class }); } |
|
|
90 |
catch (Exception e) { |
|
|
91 |
System.out.println("TUIO: missing or wrong 'addTuioString(TuioString tstr)' method implementation"); |
|
|
92 |
addTuioString = null; |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
try { removeTuioString = parent.getClass().getMethod("removeTuioString", new Class[] { TuioString.class }); } |
|
|
96 |
catch (Exception e) { |
|
|
97 |
System.out.println("TUIO:missing or wrong 'removeTuioString(TuioString tstr)' method implementation"); |
|
|
98 |
removeTuioString = null; |
|
|
99 |
} |
|
|
100 |
|
|
|
101 |
try { updateTuioString = parent.getClass().getMethod("updateTuioString", new Class[] { TuioString.class }); } |
|
|
102 |
catch (Exception e) { |
|
|
103 |
System.out.println("TUIO: missing or wrong 'updateTuioString(TuioString tstr)' method implementation"); |
|
|
104 |
updateTuioString = null; |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
client = new TuioClient(port); |
|
|
108 |
client.addTuioListener(this); |
|
|
109 |
client.connect(); |
|
|
110 |
} |
|
4
|
111 |
|
|
9
|
112 |
public void addTuioObject(TuioObject tobj) { |
|
|
113 |
if (addTuioObject!=null) { |
|
|
114 |
try { |
|
|
115 |
addTuioObject.invoke(parent, new Object[] { tobj }); |
|
|
116 |
} |
|
|
117 |
catch (IllegalAccessException e) {} |
|
|
118 |
catch (IllegalArgumentException e) {} |
|
|
119 |
catch (InvocationTargetException e) {} |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
|
|
|
123 |
public void updateTuioObject(TuioObject tobj) { |
|
|
124 |
|
|
|
125 |
if (updateTuioObject!=null) { |
|
|
126 |
try { |
|
|
127 |
updateTuioObject.invoke(parent, new Object[] { tobj }); |
|
|
128 |
} |
|
|
129 |
catch (IllegalAccessException e) {} |
|
|
130 |
catch (IllegalArgumentException e) {} |
|
|
131 |
catch (InvocationTargetException e) {} |
|
|
132 |
} |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
public void removeTuioObject(TuioObject tobj) { |
|
|
136 |
if (removeTuioObject!=null) { |
|
|
137 |
try { |
|
|
138 |
removeTuioObject.invoke(parent, new Object[] { tobj }); |
|
|
139 |
} |
|
|
140 |
catch (IllegalAccessException e) {} |
|
|
141 |
catch (IllegalArgumentException e) {} |
|
|
142 |
catch (InvocationTargetException e) {} |
|
|
143 |
} |
|
|
144 |
} |
|
|
145 |
|
|
|
146 |
public void addTuioCursor(TuioCursor tcur) { |
|
|
147 |
if (addTuioCursor!=null) { |
|
|
148 |
try { |
|
|
149 |
addTuioCursor.invoke(parent, new Object[] { tcur }); |
|
|
150 |
} |
|
|
151 |
catch (IllegalAccessException e) {} |
|
|
152 |
catch (IllegalArgumentException e) {} |
|
|
153 |
catch (InvocationTargetException e) {} |
|
|
154 |
} |
|
|
155 |
} |
|
|
156 |
|
|
|
157 |
public void updateTuioCursor(TuioCursor tcur) { |
|
|
158 |
if (updateTuioCursor!=null) { |
|
|
159 |
try { |
|
|
160 |
updateTuioCursor.invoke(parent, new Object[] { tcur }); |
|
|
161 |
} |
|
|
162 |
catch (IllegalAccessException e) {} |
|
|
163 |
catch (IllegalArgumentException e) {} |
|
|
164 |
catch (InvocationTargetException e) {} |
|
|
165 |
} |
|
|
166 |
} |
|
|
167 |
|
|
|
168 |
public void removeTuioCursor(TuioCursor tcur) { |
|
|
169 |
if (removeTuioCursor!=null) { |
|
|
170 |
try { |
|
|
171 |
removeTuioCursor.invoke(parent, new Object[] { tcur }); |
|
|
172 |
} |
|
|
173 |
catch (IllegalAccessException e) {} |
|
|
174 |
catch (IllegalArgumentException e) {} |
|
|
175 |
catch (InvocationTargetException e) {} |
|
|
176 |
} |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
public void addTuioString(TuioString tstr) { |
|
|
180 |
if (addTuioString!=null) { |
|
|
181 |
try { |
|
|
182 |
addTuioString.invoke(parent, new Object[] { tstr }); |
|
|
183 |
} |
|
|
184 |
catch (IllegalAccessException e) {} |
|
|
185 |
catch (IllegalArgumentException e) {} |
|
|
186 |
catch (InvocationTargetException e) {} |
|
|
187 |
} |
|
|
188 |
} |
|
|
189 |
|
|
|
190 |
public void updateTuioString(TuioString tstr) { |
|
|
191 |
if (updateTuioString!=null) { |
|
|
192 |
try { |
|
|
193 |
updateTuioString.invoke(parent, new Object[] { tstr }); |
|
|
194 |
} |
|
|
195 |
catch (IllegalAccessException e) {} |
|
|
196 |
catch (IllegalArgumentException e) {} |
|
|
197 |
catch (InvocationTargetException e) {} |
|
|
198 |
} |
|
|
199 |
} |
|
|
200 |
|
|
|
201 |
public void removeTuioString(TuioString tstr) { |
|
|
202 |
if (removeTuioString!=null) { |
|
|
203 |
try { |
|
|
204 |
removeTuioString.invoke(parent, new Object[] { tstr }); |
|
|
205 |
} |
|
|
206 |
catch (IllegalAccessException e) {} |
|
|
207 |
catch (IllegalArgumentException e) {} |
|
|
208 |
catch (InvocationTargetException e) {} |
|
|
209 |
} |
|
|
210 |
} |
|
|
211 |
|
|
|
212 |
public void refresh(TuioTime bundleTime) { |
|
|
213 |
if (refresh!=null) { |
|
|
214 |
try { |
|
|
215 |
refresh.invoke(parent,new Object[] { bundleTime }); |
|
|
216 |
} |
|
|
217 |
catch (IllegalAccessException e) {} |
|
|
218 |
catch (IllegalArgumentException e) {} |
|
|
219 |
catch (InvocationTargetException e) {} |
|
|
220 |
} |
|
|
221 |
} |
|
|
222 |
|
|
|
223 |
public Vector getTuioObjects() { |
|
|
224 |
return client.getTuioObjects(); |
|
|
225 |
} |
|
|
226 |
|
|
|
227 |
public Vector getTuioCursors() { |
|
|
228 |
return client.getTuioCursors(); |
|
|
229 |
} |
|
|
230 |
|
|
|
231 |
public Vector getTuioStrings() { |
|
|
232 |
return client.getTuioStrings(); |
|
|
233 |
} |
|
|
234 |
|
|
|
235 |
public TuioObject getTuioObject(long s_id) { |
|
|
236 |
return client.getTuioObject(s_id); |
|
|
237 |
} |
|
|
238 |
|
|
|
239 |
public TuioCursor getTuioCursor(long s_id) { |
|
|
240 |
return client.getTuioCursor(s_id); |
|
|
241 |
} |
|
|
242 |
|
|
|
243 |
public TuioString getTuioString(long s_id) { |
|
|
244 |
return client.getTuioString(s_id); |
|
|
245 |
} |
|
|
246 |
|
|
|
247 |
public void pre() { |
|
|
248 |
//method that's called just after beginFrame(), meaning that it |
|
|
249 |
//can affect drawing. |
|
|
250 |
} |
|
4
|
251 |
|
|
9
|
252 |
public void draw() { |
|
|
253 |
//method that's called at the end of draw(), but before endFrame(). |
|
|
254 |
} |
|
|
255 |
|
|
|
256 |
public void mouseEvent(MouseEvent e) { |
|
|
257 |
//called when a mouse event occurs in the parent applet |
|
|
258 |
} |
|
|
259 |
|
|
|
260 |
public void keyEvent(KeyEvent e) { |
|
|
261 |
//called when a key event occurs in the parent applet |
|
|
262 |
} |
|
|
263 |
|
|
|
264 |
public void post() { |
|
|
265 |
//method called after draw has completed and the frame is done. |
|
|
266 |
//no drawing allowed. |
|
|
267 |
} |
|
|
268 |
|
|
|
269 |
public void size(int width, int height) { |
|
|
270 |
//this will be called the first time an applet sets its size, but |
|
|
271 |
//also any time that it's called while the PApplet is running. |
|
|
272 |
} |
|
|
273 |
|
|
|
274 |
public void stop() { |
|
|
275 |
//can be called by users, for instance movie.stop() will shut down |
|
|
276 |
//a movie that's being played, or camera.stop() stops capturing |
|
|
277 |
//video. server.stop() will shut down the server and shut it down |
|
|
278 |
//completely, which is identical to its "dispose" function. |
|
|
279 |
} |
|
|
280 |
|
|
|
281 |
public void dispose() { |
|
|
282 |
|
|
|
283 |
if (client.isConnected()) client.disconnect(); |
|
|
284 |
|
|
|
285 |
//this should only be called by PApplet. dispose() is what gets |
|
|
286 |
//called when the host applet is stopped, so this should shut down |
|
|
287 |
//any threads, disconnect from the net, unload memory, etc. |
|
|
288 |
} |
|
4
|
289 |
} |