1 package paolomind.multitalk.toolwrapper;
2
3 import java.awt.event.KeyEvent;
4 import java.awt.event.MouseEvent;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.util.Properties;
8
9 import org.python.core.PyInstance;
10 import org.python.core.PyJavaInstance;
11 import org.python.core.PyString;
12 import org.python.util.PythonInterpreter;
13
14 import paolomind.multitalk.netmessage.IMessage;
15 import paolomind.multitalk.netmessage.MessageException;
16 import paolomind.multitalk.netmessage.Sender;
17 import paolomind.multitalk.plugin.ToolInterface;
18
19
20
21
22
23
24
25
26
27
28 public class PythonToolWrapper implements ToolInterface, Sender {
29
30
31 private PythonInterpreter engine;
32
33 private PyInstance ptool;
34
35
36 private Sender sender;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 public PythonToolWrapper(final InputStream in, final PythonInterpreter python)
94 throws IOException {
95 this.engine = python;
96 engine.execfile(in);
97 ptool = (PyInstance) python.eval("Tool()");
98 ptool.__setattr__("sender", new PyJavaInstance((Sender) this));
99 }
100
101
102
103
104
105
106 public final Properties getPropertes() {
107 return null;
108 }
109
110
111
112
113
114 public final void select() {
115 ptool.invoke("selected");
116 }
117
118
119
120
121
122
123 public final String getSelfId() {
124 return ptool.__findattr__("name").toString();
125 }
126
127
128
129
130
131
132 public final void setSelfId(final String name) {
133 ptool.__setattr__("name", new PyString(name));
134 }
135
136
137
138
139
140
141
142
143
144
145
146 public final void receive(final IMessage m) throws MessageException {
147 ptool.invoke("receive", new PyJavaInstance(m));
148 }
149
150
151
152
153
154 public final void mouseClicked(final MouseEvent e) {
155 ptool.invoke("mouseClick", new PyJavaInstance(e));
156 }
157
158
159
160
161
162 public final void mouseEntered(final MouseEvent e) {
163 ptool.invoke("mouseIn", new PyJavaInstance(e));
164 }
165
166
167
168
169
170 public final void mouseExited(final MouseEvent e) {
171 ptool.invoke("mouseOut", new PyJavaInstance(e));
172 }
173
174
175
176
177
178 public final void mousePressed(final MouseEvent e) {
179 ptool.invoke("mouseDown", new PyJavaInstance(e));
180 }
181
182
183
184
185
186 public final void mouseReleased(final MouseEvent e) {
187 ptool.invoke("mouseUp", new PyJavaInstance(e));
188 }
189
190
191
192
193
194 public final void mouseDragged(final MouseEvent e) {
195 ptool.invoke("mouseDrag", new PyJavaInstance(e));
196 }
197
198
199
200
201
202 public final void mouseMoved(final MouseEvent e) {
203 ptool.invoke("mouseMove", new PyJavaInstance(e));
204 }
205
206
207
208
209
210 public final void keyPressed(final KeyEvent e) {
211 ptool.invoke("keyDown", new PyJavaInstance(e));
212 }
213
214
215
216
217
218 public final void keyReleased(final KeyEvent e) {
219 ptool.invoke("keyUp", new PyJavaInstance(e));
220 }
221
222
223
224
225
226 public final void keyTyped(final KeyEvent e) {
227 ptool.invoke("keyType", new PyJavaInstance(e));
228 }
229
230
231
232
233
234 public final void send(final IMessage m) {
235 m.addInfo(this.getSelfId());
236 sender.send(m);
237 }
238
239
240
241
242
243 public final Sender getSender() {
244 return sender;
245 }
246
247
248
249
250
251 public final void setSender(final Sender psender) {
252 this.sender = psender;
253 }
254
255 }