author | cg |
Thu, 05 Feb 1998 11:10:33 +0000 | |
changeset 311 | b23c5e132b8c |
parent 303 | 0b95d5f40bf2 |
child 318 | 8720093188f7 |
permissions | -rw-r--r-- |
233 | 1 |
JavaView subclass:#JavaEmbeddedFrameView |
282 | 2 |
instanceVariableNames:'codeURL codeBaseURL documentURL archiveURL parameterDictionary |
3 |
embeddedAppletFrame applet appletID appletThread |
|
288 | 4 |
infoDisplayReceiver autoSetupApplet autoStartApplet |
5 |
autoDestroyApplet' |
|
282 | 6 |
classVariableNames:'NextSequentialAppletID' |
233 | 7 |
poolDictionaries:'' |
8 |
category:'Java-Views-Support' |
|
9 |
! |
|
10 |
||
11 |
||
282 | 12 |
!JavaEmbeddedFrameView methodsFor:'accessing'! |
13 |
||
14 |
appletID |
|
15 |
"return the value of the instance variable 'appletID' (automatically generated)" |
|
16 |
||
17 |
^ appletID |
|
18 |
||
19 |
"Created: / 28.1.1998 / 21:08:54 / cg" |
|
20 |
! |
|
21 |
||
22 |
appletID:something |
|
23 |
"set the value of the instance variable 'appletID' (automatically generated)" |
|
24 |
||
25 |
appletID := something. |
|
26 |
||
27 |
"Created: / 28.1.1998 / 21:08:54 / cg" |
|
28 |
! |
|
29 |
||
30 |
appletThread |
|
31 |
^ appletThread |
|
32 |
||
33 |
"Created: / 28.1.1998 / 21:39:42 / cg" |
|
34 |
! |
|
35 |
||
36 |
archiveURL:anArchiveURLString |
|
37 |
archiveURL := anArchiveURLString |
|
38 |
||
39 |
"Created: / 28.1.1998 / 21:00:38 / cg" |
|
40 |
! |
|
41 |
||
42 |
codeBaseURL:aCodeBaseURLString |
|
43 |
codeBaseURL := aCodeBaseURLString |
|
44 |
||
45 |
"Created: / 28.1.1998 / 20:59:34 / cg" |
|
46 |
! |
|
47 |
||
48 |
codeURL:aCodeURLString |
|
49 |
codeURL := aCodeURLString |
|
50 |
||
51 |
"Created: / 28.1.1998 / 21:10:11 / cg" |
|
52 |
! |
|
53 |
||
54 |
documentURL:aDocumentURLString |
|
55 |
documentURL := aDocumentURLString |
|
56 |
||
57 |
"Created: / 28.1.1998 / 21:00:03 / cg" |
|
58 |
"Modified: / 28.1.1998 / 21:00:28 / cg" |
|
59 |
! |
|
60 |
||
61 |
embeddedAppletFrame |
|
62 |
^ embeddedAppletFrame |
|
63 |
||
64 |
"Created: / 28.1.1998 / 21:39:35 / cg" |
|
65 |
! |
|
66 |
||
67 |
infoDisplayReceiver |
|
68 |
"return the value of the instance variable 'infoDisplayReceiver' (automatically generated)" |
|
69 |
||
70 |
^ infoDisplayReceiver |
|
71 |
||
72 |
"Created: / 28.1.1998 / 21:43:54 / cg" |
|
73 |
! |
|
74 |
||
75 |
infoDisplayReceiver:something |
|
76 |
"set the value of the instance variable 'infoDisplayReceiver' (automatically generated)" |
|
77 |
||
78 |
infoDisplayReceiver := something. |
|
79 |
||
80 |
"Created: / 28.1.1998 / 21:43:54 / cg" |
|
81 |
! |
|
82 |
||
83 |
parameterDictionary:aParameterDictionary |
|
84 |
parameterDictionary := aParameterDictionary |
|
85 |
||
86 |
"Created: / 28.1.1998 / 21:01:20 / cg" |
|
87 |
! ! |
|
88 |
||
89 |
!JavaEmbeddedFrameView methodsFor:'applet control'! |
|
90 |
||
91 |
appletDESTROY |
|
92 |
embeddedAppletFrame |
|
93 |
perform:#'sendEvent(I)V' |
|
94 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_DESTROY'). |
|
95 |
||
96 |
"Created: / 28.1.1998 / 21:41:45 / cg" |
|
97 |
! |
|
98 |
||
99 |
appletDISPOSE |
|
100 |
embeddedAppletFrame |
|
101 |
perform:#'sendEvent(I)V' |
|
102 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_DISPOSE'). |
|
103 |
||
104 |
"Created: / 28.1.1998 / 21:41:57 / cg" |
|
105 |
! |
|
106 |
||
107 |
appletINIT |
|
108 |
embeddedAppletFrame |
|
109 |
perform:#'sendEvent(I)V' |
|
110 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_INIT'). |
|
111 |
||
112 |
"Created: / 28.1.1998 / 21:17:51 / cg" |
|
113 |
! |
|
114 |
||
115 |
appletLOAD |
|
116 |
embeddedAppletFrame |
|
117 |
perform:#'sendEvent(I)V' |
|
118 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_LOAD'). |
|
119 |
||
120 |
"Created: / 28.1.1998 / 21:17:37 / cg" |
|
121 |
! |
|
122 |
||
123 |
appletSTART |
|
124 |
embeddedAppletFrame |
|
125 |
perform:#'sendEvent(I)V' |
|
126 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_START'). |
|
127 |
||
128 |
"Created: / 28.1.1998 / 21:18:01 / cg" |
|
129 |
! |
|
130 |
||
131 |
appletSTOP |
|
132 |
embeddedAppletFrame |
|
133 |
perform:#'sendEvent(I)V' |
|
134 |
with:(embeddedAppletFrame class instVarNamed:'APPLET_STOP'). |
|
135 |
||
136 |
"Created: / 28.1.1998 / 21:41:33 / cg" |
|
137 |
! |
|
138 |
||
288 | 139 |
autoDestroyApplet:aBoolean |
140 |
"set/clear the autoDestroy flag. |
|
141 |
If set, the applet will be shutDown whenever the I get destroyed. |
|
142 |
if clear, the applet is not automatically shutDown and must be |
|
143 |
terminated by someone else. |
|
144 |
The default is false." |
|
145 |
||
146 |
autoDestroyApplet := aBoolean. |
|
147 |
||
148 |
"Created: / 29.1.1998 / 15:18:50 / cg" |
|
149 |
"Modified: / 29.1.1998 / 15:21:01 / cg" |
|
150 |
! |
|
151 |
||
152 |
autoSetupApplet:aBoolean |
|
153 |
"set/clear the autoSetup flag. |
|
154 |
If set, the appletFrame will be setup whenever the I get realized |
|
155 |
for the first time. |
|
156 |
If clear, the frame is not automatically setup and must be |
|
157 |
setup by someone else. |
|
158 |
The default is true." |
|
159 |
||
160 |
||
161 |
autoSetupApplet := aBoolean. |
|
162 |
||
163 |
"Created: / 29.1.1998 / 15:18:41 / cg" |
|
164 |
"Modified: / 29.1.1998 / 20:45:37 / cg" |
|
165 |
! |
|
166 |
||
167 |
autoStartApplet:aBoolean |
|
168 |
"set/clear the autoStart flag. |
|
169 |
If set, the applet will be loaded & started whenever the I get realized |
|
170 |
for the first time. |
|
171 |
If clear, the applet is not automatically started and must be |
|
172 |
started by someone else. |
|
173 |
The default is false." |
|
174 |
||
175 |
||
176 |
autoStartApplet := aBoolean. |
|
177 |
||
178 |
"Created: / 29.1.1998 / 15:18:41 / cg" |
|
179 |
"Modified: / 29.1.1998 / 15:20:54 / cg" |
|
180 |
! |
|
181 |
||
282 | 182 |
startApplet |
183 |
self startAppletThread. |
|
184 |
||
185 |
self appletLOAD. |
|
186 |
self appletINIT. |
|
187 |
self appletSTART |
|
188 |
||
189 |
"Modified: / 28.1.1998 / 21:30:24 / cg" |
|
190 |
! |
|
191 |
||
192 |
startAppletThread |
|
193 |
|appletName| |
|
194 |
||
195 |
appletThread := JavaProcess |
|
196 |
for:[ |
|
197 |
"/ passnotifications to the documentFrame ... |
|
198 |
Object informationSignal handle:[:ex | |
|
199 |
JavaVM javaConsoleStream showCR:ex errorString. |
|
200 |
ex proceed. |
|
201 |
] do:[ |
|
202 |
Object activityNotificationSignal handle:[:ex | |
|
203 |
infoDisplayReceiver notNil ifTrue:[ |
|
204 |
infoDisplayReceiver infoDisplay:ex errorString. |
|
205 |
] ifFalse:[ |
|
206 |
Transcript showCR:ex errorString |
|
207 |
]. |
|
208 |
ex proceed. |
|
209 |
] do:[ |
|
210 |
[ |
|
211 |
embeddedAppletFrame perform:#'run()V'. |
|
212 |
] valueNowOrOnUnwindDo:[ |
|
213 |
appletThread terminateAllSubprocesses. |
|
214 |
Transcript showCR:'JAVA applet startup finished'. |
|
215 |
] |
|
216 |
] |
|
217 |
] |
|
218 |
] |
|
219 |
priority:(Processor activePriority - 1). |
|
220 |
||
221 |
appletName := codeURL asFilename withoutSuffix baseName. |
|
222 |
appletThread name:('JAVA-applet ''' , appletName , ''' [startup]'). |
|
223 |
||
224 |
appletThread resume. |
|
225 |
||
226 |
^ appletThread. |
|
227 |
||
228 |
"Created: / 28.1.1998 / 21:30:32 / cg" |
|
229 |
"Modified: / 28.1.1998 / 21:44:03 / cg" |
|
286 | 230 |
! |
231 |
||
232 |
stopApplet |
|
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
233 |
|n n2| |
286 | 234 |
|
235 |
(appletThread notNil |
|
236 |
and:[appletThread isDead not])ifTrue:[ |
|
237 |
'EmbeddedAppletFrame [info]: send APPLET_STOP ...' infoPrintCR. |
|
238 |
self appletSTOP. |
|
239 |
||
240 |
'EmbeddedAppletFrame [info]: send APPLET_DESTROY ...' infoPrintCR. |
|
241 |
self appletDESTROY. |
|
242 |
||
243 |
'EmbeddedAppletFrame [info]: send APPLET_DISPOSE ...' infoPrintCR. |
|
244 |
self appletDISPOSE. |
|
245 |
||
246 |
"/ |
|
247 |
"/ give it a chance to stop ... |
|
248 |
"/ |
|
249 |
Processor yield. |
|
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
250 |
n2 := 0. |
286 | 251 |
[appletThread isDead] whileFalse:[ |
252 |
n := 0. |
|
253 |
[n < 10 and:[appletThread isDead not]] whileTrue:[ |
|
254 |
Delay waitForSeconds:0.1. |
|
255 |
n := n + 1. |
|
256 |
]. |
|
257 |
appletThread isDead ifFalse:[ |
|
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
258 |
Transcript showCR:'EmbeddedAppletFrame [info]: JAVA thread did not stop - soft terminate ...'. |
286 | 259 |
appletThread terminate. |
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
260 |
n2 := n2 + 1. |
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
261 |
n2 > 10 ifTrue:[ |
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
262 |
Transcript showCR:'EmbeddedAppletFrame [info]: JAVA thread did not stop - shooting down ...'. |
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
263 |
appletThread terminateNoSignal |
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
264 |
] |
286 | 265 |
]. |
266 |
]. |
|
267 |
]. |
|
268 |
appletThread := nil |
|
269 |
||
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
270 |
"Modified: / 5.2.1998 / 12:10:01 / cg" |
286 | 271 |
! ! |
272 |
||
273 |
!JavaEmbeddedFrameView methodsFor:'initialize / release'! |
|
274 |
||
275 |
destroy |
|
276 |
autoDestroyApplet == true ifTrue:[ |
|
277 |
self stopApplet |
|
278 |
]. |
|
279 |
super destroy. |
|
280 |
||
281 |
"Created: / 29.1.1998 / 15:21:45 / cg" |
|
282 |
"Modified: / 29.1.1998 / 15:28:26 / cg" |
|
283 |
! |
|
284 |
||
285 |
realize |
|
286 |
super realize. |
|
288 | 287 |
|
288 |
autoSetupApplet ~~ false ifTrue:[ |
|
289 |
self setupAppletFrame |
|
290 |
]. |
|
286 | 291 |
autoStartApplet == true ifTrue:[ |
288 | 292 |
embeddedAppletFrame notNil ifTrue:[ |
293 |
self startApplet |
|
294 |
] |
|
286 | 295 |
] |
296 |
||
297 |
"Created: / 29.1.1998 / 15:21:30 / cg" |
|
288 | 298 |
"Modified: / 29.1.1998 / 20:51:41 / cg" |
282 | 299 |
! ! |
300 |
||
301 |
!JavaEmbeddedFrameView methodsFor:'private'! |
|
302 |
||
303 |
setupAppletFrame |
|
304 |
|jMozillaAppletContextClass appletContext |
|
305 |
jEmbeddedAppletFrameClass |
|
306 |
toolkit peer attribs id |
|
307 |
jCodeBaseURL jDocumentURL jArchiveURL| |
|
308 |
||
288 | 309 |
embeddedAppletFrame notNil ifTrue:[ |
310 |
"/ already setup |
|
311 |
^ self |
|
312 |
]. |
|
313 |
||
314 |
codeBaseURL isNil ifTrue:[ |
|
315 |
^ self |
|
316 |
]. |
|
317 |
||
318 |
Java startupJavaSystem. |
|
319 |
||
282 | 320 |
jCodeBaseURL := Java as_URL:codeBaseURL. |
288 | 321 |
documentURL notNil ifTrue:[ |
322 |
jDocumentURL := Java as_URL:documentURL. |
|
323 |
]. |
|
324 |
archiveURL notNil ifTrue:[ |
|
325 |
jArchiveURL := Java as_URL:archiveURL. |
|
326 |
]. |
|
282 | 327 |
|
328 |
id := appletID. |
|
329 |
id isNil ifTrue:[ |
|
330 |
NextSequentialAppletID isNil ifTrue:[ |
|
331 |
NextSequentialAppletID := 1. |
|
332 |
]. |
|
333 |
id := NextSequentialAppletID. |
|
334 |
NextSequentialAppletID := NextSequentialAppletID + 1 |
|
335 |
]. |
|
336 |
||
337 |
attribs := Dictionary new. |
|
338 |
width notNil ifTrue:[attribs at:'width' put:width printString]. |
|
339 |
height notNil ifTrue:[attribs at:'height' put:height printString]. |
|
340 |
codeURL notNil ifTrue:[attribs at:'code' put:codeURL]. |
|
341 |
parameterDictionary notNil ifTrue:[ |
|
342 |
attribs declareAllFrom:parameterDictionary |
|
343 |
]. |
|
344 |
attribs := Java as_Hashtable:attribs. |
|
345 |
||
346 |
"/ this makes it a modzilla frame ... |
|
347 |
jMozillaAppletContextClass := Java classForName:'netscape.applet.MozillaAppletContext'. |
|
348 |
jMozillaAppletContextClass isNil ifTrue:[ |
|
349 |
self warn:'no netscape.applet.MozillaAppletContext class'. |
|
350 |
^ false |
|
351 |
]. |
|
352 |
appletContext := jMozillaAppletContextClass new. |
|
353 |
||
354 |
jEmbeddedAppletFrameClass := Java classForName:'netscape.applet.EmbeddedAppletFrame'. |
|
355 |
jEmbeddedAppletFrameClass isNil ifTrue:[ |
|
356 |
self warn:'no netscape.applet.EmbeddedAppletFrame class'. |
|
357 |
^ false |
|
358 |
]. |
|
359 |
embeddedAppletFrame := jEmbeddedAppletFrameClass new. |
|
360 |
embeddedAppletFrame instVarNamed:'pData' put:self. |
|
361 |
||
362 |
toolkit := Java classForName:'java.awt.Toolkit'. |
|
363 |
toolkit := toolkit invoke:#getDefaultToolkit. |
|
364 |
peer := toolkit |
|
365 |
perform:#'createFrame(Ljava/awt/Frame;)Ljava/awt/peer/FramePeer;' |
|
366 |
with:embeddedAppletFrame. |
|
367 |
||
368 |
(embeddedAppletFrame respondsTo:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;Ljava/lang/Integer;)V') |
|
369 |
ifTrue:[ |
|
370 |
"/ 3.01 netscape |
|
371 |
embeddedAppletFrame |
|
372 |
perform:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;Ljava/lang/Integer;)V' |
|
373 |
with:jDocumentURL |
|
374 |
with:jCodeBaseURL |
|
375 |
with:jArchiveURL |
|
376 |
with:attribs |
|
377 |
with:appletContext |
|
378 |
with:(Java as_Integer:id). |
|
379 |
] ifFalse:[ |
|
380 |
"/ oldStyle netscape |
|
381 |
embeddedAppletFrame |
|
382 |
perform:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;I)V' |
|
383 |
with:jDocumentURL |
|
384 |
with:jCodeBaseURL |
|
385 |
with:attribs |
|
386 |
with:appletContext |
|
387 |
with:id. |
|
388 |
]. |
|
389 |
||
390 |
embeddedAppletFrame instVarNamed:'peer' put:peer. |
|
391 |
||
392 |
self javaPeer:peer. |
|
393 |
||
394 |
jMozillaAppletContextClass instVarNamed:'debug' put:1. |
|
395 |
||
396 |
^ true |
|
397 |
||
398 |
"Created: / 28.1.1998 / 21:23:25 / cg" |
|
288 | 399 |
"Modified: / 29.1.1998 / 20:55:00 / cg" |
282 | 400 |
! ! |
401 |
||
303 | 402 |
!JavaEmbeddedFrameView methodsFor:'resizing'! |
403 |
||
404 |
sizeChanged:how |
|
405 |
super sizeChanged:how. |
|
406 |
^ self. |
|
407 |
embeddedAppletFrame notNil ifTrue:[ |
|
408 |
(embeddedAppletFrame perform:#'isResizable()Z') ~~ 0 ifTrue:[ |
|
409 |
self windowGroup sensor |
|
410 |
pushDamageEvent:(WindowEvent |
|
411 |
for:self |
|
412 |
type:#configureX:y:width:height: |
|
413 |
arguments:(Array with:left with:top with:width with:height)). |
|
414 |
"/ embeddedAppletFrame |
|
415 |
"/ perform:#'appletResize(II)V' |
|
416 |
"/ with:self width |
|
417 |
"/ with:self height. |
|
418 |
] |
|
419 |
] |
|
420 |
||
421 |
"Modified: / 1.2.1998 / 19:15:07 / cg" |
|
422 |
! ! |
|
423 |
||
233 | 424 |
!JavaEmbeddedFrameView class methodsFor:'documentation'! |
425 |
||
426 |
version |
|
311
b23c5e132b8c
hardterminate javaThread, if it did not terminate after 10 tries.
cg
parents:
303
diff
changeset
|
427 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.6 1998/02/05 11:10:33 cg Exp $' |
233 | 428 |
! ! |