JavaEmbeddedFrameView.st
changeset 282 80e840e0139f
parent 233 fc91b8aba669
child 286 da220fe69de3
--- a/JavaEmbeddedFrameView.st	Wed Jan 28 01:32:20 1998 +0000
+++ b/JavaEmbeddedFrameView.st	Wed Jan 28 20:53:53 1998 +0000
@@ -1,13 +1,278 @@
 JavaView subclass:#JavaEmbeddedFrameView
-	instanceVariableNames:''
-	classVariableNames:''
+	instanceVariableNames:'codeURL codeBaseURL documentURL archiveURL parameterDictionary
+		embeddedAppletFrame applet appletID appletThread
+		infoDisplayReceiver'
+	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"
+!
+
+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"
+! !
+
+!JavaEmbeddedFrameView methodsFor:'private'!
+
+setupAppletFrame
+    |jMozillaAppletContextClass appletContext
+     jEmbeddedAppletFrameClass 
+     toolkit peer attribs id
+     jCodeBaseURL jDocumentURL jArchiveURL|
+
+    jCodeBaseURL := Java as_URL:codeBaseURL.
+    jDocumentURL := Java as_URL:documentURL.
+    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: / 28.1.1998 / 21:37:22 / cg"
+! !
+
 !JavaEmbeddedFrameView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.1 1997/08/18 15:48:26 cg Exp $'
+    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.2 1998/01/28 20:53:53 cg Exp $'
 ! !