JavaEmbeddedFrameView.st
changeset 397 ff55215c1eac
parent 384 9c0f24e91237
child 417 d60d5b5da5f9
--- a/JavaEmbeddedFrameView.st	Tue Oct 20 13:11:20 1998 +0000
+++ b/JavaEmbeddedFrameView.st	Tue Oct 20 14:10:21 1998 +0000
@@ -9,6 +9,25 @@
 !
 
 
+!JavaEmbeddedFrameView class methodsFor:'support'!
+
+newAppletContext
+    |jMozillaAppletContextClass|
+
+    "/ this makes it a modzilla applet context ...
+    jMozillaAppletContextClass := Java classForName:'netscape.applet.MozillaAppletContext'.
+    jMozillaAppletContextClass isNil ifTrue:[
+        self warn:'no netscape.applet.MozillaAppletContext class'.
+        ^ nil
+    ].
+    jMozillaAppletContextClass instVarNamed:'debug' put:1.
+
+    ^ jMozillaAppletContextClass new.
+
+    "Created: / 20.10.1998 / 15:40:08 / cg"
+    "Modified: / 20.10.1998 / 15:43:47 / cg"
+! !
+
 !JavaEmbeddedFrameView methodsFor:'accessing'!
 
 appletID
@@ -352,7 +371,7 @@
     super realize.
  
     autoSetupApplet ~~ false ifTrue:[
-        self setupAppletFrame
+        self setupAppletFrameIn:nil initializeJava:true
     ].
     autoStartApplet == true ifTrue:[
         embeddedAppletFrame notNil ifTrue:[
@@ -361,13 +380,13 @@
     ]
 
     "Created: / 29.1.1998 / 15:21:30 / cg"
-    "Modified: / 29.1.1998 / 20:51:41 / cg"
+    "Modified: / 20.10.1998 / 15:46:32 / cg"
 ! !
 
 !JavaEmbeddedFrameView methodsFor:'private'!
 
-setupAppletFrame
-    |jMozillaAppletContextClass appletContext
+setupAppletFrameIn:anAppletContextOrNil
+     |appletContext
      jEmbeddedAppletFrameClass jDerivedAppletFrameClass
      toolkit peer attribs id
      jCodeBaseURL jDocumentURL jArchiveURL|
@@ -409,13 +428,15 @@
     ].
     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
+    anAppletContextOrNil notNil ifTrue:[
+        appletContext := anAppletContextOrNil
+    ] ifFalse:[
+        appletContext := self newAppletContext.
+        appletContext isNil ifTrue:[
+            self warn:'no netscape.applet.MozillaAppletContext class'.
+            ^ false
+        ].
     ].
-    appletContext := jMozillaAppletContextClass new.
 
     jEmbeddedAppletFrameClass := Java classForName:'netscape.applet.EmbeddedAppletFrame'.
     jEmbeddedAppletFrameClass isNil ifTrue:[
@@ -483,12 +504,137 @@
 
     self javaPeer:peer.
 
-    jMozillaAppletContextClass instVarNamed:'debug' put:1.
+    ^ true
+
+    "Created: / 20.10.1998 / 15:38:24 / cg"
+    "Modified: / 20.10.1998 / 15:43:36 / cg"
+!
+
+setupAppletFrameIn:anAppletContextOrNil initializeJava:initializeJava
+     |appletContext
+     jEmbeddedAppletFrameClass jDerivedAppletFrameClass
+     toolkit peer attribs id
+     jCodeBaseURL jDocumentURL jArchiveURL|
+
+    embeddedAppletFrame notNil ifTrue:[
+        "/ already setup
+        ^ self
+    ].
+
+    codeBaseURL isNil ifTrue:[
+        ^ self
+    ].
+
+    initializeJava ifTrue:[
+        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.
+
+    anAppletContextOrNil notNil ifTrue:[
+        appletContext := anAppletContextOrNil
+    ] ifFalse:[
+        appletContext := self newAppletContext.
+        appletContext isNil ifTrue:[
+            self warn:'no netscape.applet.MozillaAppletContext class'.
+            ^ false
+        ].
+    ].
+
+    jEmbeddedAppletFrameClass := Java classForName:'netscape.applet.EmbeddedAppletFrame'.
+    jEmbeddedAppletFrameClass isNil ifTrue:[
+        self warn:'no netscape.applet.EmbeddedAppletFrame class'.
+        ^ false
+    ].
+    jDerivedAppletFrameClass := Java classForName:'netscape.applet.DerivedAppletFrame'.
+    jDerivedAppletFrameClass notNil ifTrue:[
+        "/ ns4.0
+        embeddedAppletFrame := jDerivedAppletFrameClass new.
+        isNS40 := true.
+    ] ifFalse:[
+        "/ ns3.x
+        embeddedAppletFrame := jEmbeddedAppletFrameClass new.
+        isNS40 := false.
+    ].
+    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;Z)V')
+    ifTrue:[
+        "/ 4.0 netscape
+        embeddedAppletFrame 
+            perform:#'<init>(Ljava/net/URL;Ljava/net/URL;Ljava/net/URL;Ljava/util/Hashtable;Lnetscape/applet/MozillaAppletContext;Ljava/lang/Integer;Z)V'
+            withArguments:
+                (Array
+                    with:jDocumentURL
+                    with:jCodeBaseURL
+                    with:jArchiveURL
+                    with:attribs
+                    with:appletContext
+                    with:(Java as_Integer:id)
+                    with:0 "/ reloadClasses-boolean
+                ).
+    ] ifFalse:[
+        (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.
 
     ^ true
 
-    "Created: / 28.1.1998 / 21:23:25 / cg"
-    "Modified: / 16.10.1998 / 02:40:52 / cg"
+    "Modified: / 20.10.1998 / 15:43:36 / cg"
+    "Created: / 20.10.1998 / 15:47:04 / cg"
 ! !
 
 !JavaEmbeddedFrameView methodsFor:'resizing'!
@@ -516,5 +662,5 @@
 !JavaEmbeddedFrameView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.8 1998/10/17 12:58:55 cg Exp $'
+    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaEmbeddedFrameView.st,v 1.9 1998/10/20 14:10:21 cg Exp $'
 ! !