JavaView subclass:#JavaEmbeddedFrameView
instanceVariableNames:'codeURL codeBaseURL documentURL archiveURL parameterDictionary
embeddedAppletFrame applet appletID appletThread
infoDisplayReceiver autoSetupApplet autoStartApplet
autoDestroyApplet'
classVariableNames:'NextSequentialAppletID'
poolDictionaries:''
category:'Java-Views-Support'
!
!JavaEmbeddedFrameView methodsFor:'accessing'!
appletID
"return the value of the instance variable 'appletID' (automatically generated)"
^ appletID
"Created: / 28.1.1998 / 21:08:54 / cg"
!
appletID:something
"set the value of the instance variable 'appletID' (automatically generated)"
appletID := something.
"Created: / 28.1.1998 / 21:08:54 / cg"
!
appletThread
^ appletThread
"Created: / 28.1.1998 / 21:39:42 / cg"
!
archiveURL:anArchiveURLString
archiveURL := anArchiveURLString
"Created: / 28.1.1998 / 21:00:38 / cg"
!
codeBaseURL:aCodeBaseURLString
codeBaseURL := aCodeBaseURLString
"Created: / 28.1.1998 / 20:59:34 / cg"
!
codeURL:aCodeURLString
codeURL := aCodeURLString
"Created: / 28.1.1998 / 21:10:11 / cg"
!
documentURL:aDocumentURLString
documentURL := aDocumentURLString
"Created: / 28.1.1998 / 21:00:03 / cg"
"Modified: / 28.1.1998 / 21:00:28 / cg"
!
embeddedAppletFrame
^ embeddedAppletFrame
"Created: / 28.1.1998 / 21:39:35 / cg"
!
infoDisplayReceiver
"return the value of the instance variable 'infoDisplayReceiver' (automatically generated)"
^ infoDisplayReceiver
"Created: / 28.1.1998 / 21:43:54 / cg"
!
infoDisplayReceiver:something
"set the value of the instance variable 'infoDisplayReceiver' (automatically generated)"
infoDisplayReceiver := something.
"Created: / 28.1.1998 / 21:43:54 / cg"
!
parameterDictionary:aParameterDictionary
parameterDictionary := aParameterDictionary
"Created: / 28.1.1998 / 21:01:20 / cg"
! !
!JavaEmbeddedFrameView methodsFor:'applet control'!
appletDESTROY
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_DESTROY').
"Created: / 28.1.1998 / 21:41:45 / cg"
!
appletDISPOSE
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_DISPOSE').
"Created: / 28.1.1998 / 21:41:57 / cg"
!
appletINIT
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_INIT').
"Created: / 28.1.1998 / 21:17:51 / cg"
!
appletLOAD
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_LOAD').
"Created: / 28.1.1998 / 21:17:37 / cg"
!
appletSTART
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_START').
"Created: / 28.1.1998 / 21:18:01 / cg"
!
appletSTOP
embeddedAppletFrame
perform:#'sendEvent(I)V'
with:(embeddedAppletFrame class instVarNamed:'APPLET_STOP').
"Created: / 28.1.1998 / 21:41:33 / cg"
!
autoDestroyApplet:aBoolean
"set/clear the autoDestroy flag.
If set, the applet will be shutDown whenever the I get destroyed.
if clear, the applet is not automatically shutDown and must be
terminated by someone else.
The default is false."
autoDestroyApplet := aBoolean.
"Created: / 29.1.1998 / 15:18:50 / cg"
"Modified: / 29.1.1998 / 15:21:01 / cg"
!
autoSetupApplet:aBoolean
"set/clear the autoSetup flag.
If set, the appletFrame will be setup whenever the I get realized
for the first time.
If clear, the frame is not automatically setup and must be
setup by someone else.
The default is true."
autoSetupApplet := aBoolean.
"Created: / 29.1.1998 / 15:18:41 / cg"
"Modified: / 29.1.1998 / 20:45:37 / cg"
!
autoStartApplet:aBoolean
"set/clear the autoStart flag.
If set, the applet will be loaded & started whenever the I get realized
for the first time.
If clear, the applet is not automatically started and must be
started by someone else.
The default is false."
autoStartApplet := aBoolean.
"Created: / 29.1.1998 / 15:18:41 / cg"
"Modified: / 29.1.1998 / 15:20:54 / cg"
!
startApplet
self startAppletThread.
self appletLOAD.
self appletINIT.
self appletSTART
"Modified: / 28.1.1998 / 21:30:24 / cg"
!
startAppletThread
|appletName|
appletThread := JavaProcess
for:[
"/ passnotifications to the documentFrame ...
Object informationSignal handle:[:ex |
JavaVM javaConsoleStream showCR:ex errorString.
ex proceed.
] do:[
Object activityNotificationSignal handle:[:ex |
infoDisplayReceiver notNil ifTrue:[
infoDisplayReceiver infoDisplay:ex errorString.
] ifFalse:[
Transcript showCR:ex errorString
].
ex proceed.
] do:[
[
embeddedAppletFrame perform:#'run()V'.
] valueNowOrOnUnwindDo:[
appletThread terminateAllSubprocesses.
Transcript showCR:'JAVA applet startup finished'.
]
]
]
]
priority:(Processor activePriority - 1).
appletName := codeURL asFilename withoutSuffix baseName.
appletThread name:('JAVA-applet ''' , appletName , ''' [startup]').
appletThread resume.
^ appletThread.
"Created: / 28.1.1998 / 21:30:32 / cg"
"Modified: / 28.1.1998 / 21:44:03 / cg"
!
stopApplet
|n|
(appletThread notNil
and:[appletThread isDead not])ifTrue:[
'EmbeddedAppletFrame [info]: send APPLET_STOP ...' infoPrintCR.
self appletSTOP.
'EmbeddedAppletFrame [info]: send APPLET_DESTROY ...' infoPrintCR.
self appletDESTROY.
'EmbeddedAppletFrame [info]: send APPLET_DISPOSE ...' infoPrintCR.
self appletDISPOSE.
"/
"/ give it a chance to stop ...
"/
Processor yield.
[appletThread isDead] whileFalse:[
n := 0.
[n < 10 and:[appletThread isDead not]] whileTrue:[
Delay waitForSeconds:0.1.
n := n + 1.
].
appletThread isDead ifFalse:[
Transcript showCR:'EmbeddedAppletFrame [info]: JAVA thread did not stop - shooting down ...'.
appletThread terminate.
].
].
].
appletThread := nil
"Modified: / 29.1.1998 / 15:27:30 / cg"
! !
!JavaEmbeddedFrameView methodsFor:'initialize / release'!
destroy
autoDestroyApplet == true ifTrue:[
self stopApplet
].
super destroy.
"Created: / 29.1.1998 / 15:21:45 / cg"
"Modified: / 29.1.1998 / 15:28:26 / cg"
!
realize
super realize.
autoSetupApplet ~~ false ifTrue:[
self setupAppletFrame
].
autoStartApplet == true ifTrue:[
embeddedAppletFrame notNil ifTrue:[
self startApplet
]
]
"Created: / 29.1.1998 / 15:21:30 / cg"
"Modified: / 29.1.1998 / 20:51:41 / cg"
! !
!JavaEmbeddedFrameView methodsFor:'private'!
setupAppletFrame
|jMozillaAppletContextClass appletContext
jEmbeddedAppletFrameClass
toolkit peer attribs id
jCodeBaseURL jDocumentURL jArchiveURL|
embeddedAppletFrame notNil ifTrue:[
"/ already setup
^ self
].
codeBaseURL isNil ifTrue:[
^ self
].
Java startupJavaSystem.
jCodeBaseURL := Java as_URL:codeBaseURL.
documentURL notNil ifTrue:[
jDocumentURL := Java as_URL:documentURL.
].
archiveURL notNil ifTrue:[
jArchiveURL := Java as_URL:archiveURL.
].
id := appletID.
id isNil ifTrue:[
NextSequentialAppletID isNil ifTrue:[
NextSequentialAppletID := 1.
].
id := NextSequentialAppletID.
NextSequentialAppletID := NextSequentialAppletID + 1
].
attribs := Dictionary new.
width notNil ifTrue:[attribs at:'width' put:width printString].
height notNil ifTrue:[attribs at:'height' put:height printString].
codeURL notNil ifTrue:[attribs at:'code' put:codeURL].
parameterDictionary notNil ifTrue:[
attribs declareAllFrom:parameterDictionary
].
attribs := Java as_Hashtable:attribs.
"/ this makes it a modzilla frame ...
jMozillaAppletContextClass := Java classForName:'netscape.applet.MozillaAppletContext'.
jMozillaAppletContextClass isNil ifTrue:[
self warn:'no netscape.applet.MozillaAppletContext class'.
^ false
].
appletContext := jMozillaAppletContextClass new.
jEmbeddedAppletFrameClass := Java classForName:'netscape.applet.EmbeddedAppletFrame'.
jEmbeddedAppletFrameClass isNil ifTrue:[
self warn:'no netscape.applet.EmbeddedAppletFrame class'.
^ false
].
embeddedAppletFrame := jEmbeddedAppletFrameClass new.
embeddedAppletFrame instVarNamed:'pData' put:self.
toolkit := Java classForName:'java.awt.Toolkit'.
toolkit := toolkit invoke:#getDefaultToolkit.
peer := toolkit
perform:#'createFrame(Ljava/awt/Frame;)Ljava/awt/peer/FramePeer;'
with:embeddedAppletFrame.
(embeddedAppletFrame respondsTo:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;Ljava/lang/Integer;)V')
ifTrue:[
"/ 3.01 netscape
embeddedAppletFrame
perform:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;Ljava/lang/Integer;)V'
with:jDocumentURL
with:jCodeBaseURL
with:jArchiveURL
with:attribs
with:appletContext
with:(Java as_Integer:id).
] ifFalse:[
"/ oldStyle netscape
embeddedAppletFrame
perform:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;I)V'
with:jDocumentURL
with:jCodeBaseURL
with:attribs
with:appletContext
with:id.
].
embeddedAppletFrame instVarNamed:'peer' put:peer.
self javaPeer:peer.
jMozillaAppletContextClass instVarNamed:'debug' put:1.
^ true
"Created: / 28.1.1998 / 21:23:25 / cg"
"Modified: / 29.1.1998 / 20:55:00 / cg"
! !
!JavaEmbeddedFrameView class methodsFor:'documentation'!
version
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.4 1998/01/29 20:25:49 cg Exp $'
! !