Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / js / SwingJS.js
index a9bac7c..458acbe 100644 (file)
-// SwingJS.js\r
-\r
-// BH 7/24/2015 9:09:39 AM allows setting Info.resourcePath\r
-// BH 4/28/2015 10:15:32 PM adds getAppletHtml \r
-// BH 4/2/2015 5:17:44 PM  adds SwingJS.getJavaResource(path)\r
-\r
-// BH 3/27/2015 6:34:49 AM  just a shell\r
-\r
-if(typeof(jQuery)=="undefined") alert ("Note -- jQuery is required for SwingJS, but it's not defined.")\r
-\r
-if (typeof(SwingJS) == "undefined") {\r
-\r
-  SwingJS = {};\r
-\r
-(function (SwingJS, $) {\r
-\r
-       SwingJS.getApplet = function(id, Info, checkOnly) {\r
-               return SwingJS._Applet._get(id, Info, checkOnly);\r
-       }\r
-\r
-  SwingJS.getJavaResource = function(path, isJavaPath) {\r
-               if (path.indexOf("http") != 0) {\r
-      var applet = Jmol._applets[java.lang.Thread.currentThread().getName()];\r
-      path = (!isJavaPath && applet.__Info.resourcePath || applet.__Info.j2sPath) + "/" + path\r
-      }      \r
-    System.out.println("Swingjs.js getJavaResource " + path)\r
-    var s = Jmol._getFileData(path);\r
-    if (s.indexOf("[Exception") == 0)\r
-      return null; \r
-    if (path.lastIndexOf(".css") == path.length - 4) {\r
-      path = path.substring(0, path.lastIndexOf("/") + 1) + "images/";\r
-      s = s.replace(/images\//g, path)\r
-      jQuery("head").append(jQuery("<style type='text/css'>" + s + "</style>"));\r
-      return s;\r
-    } else if (path.lastIndexOf(".js") == path.length - 3) {\r
-      try {\r
-        eval(s);\r
-      } catch (e) {\r
-      alert("error processing " + s)\r
-        return null;\r
-      }\r
-    }\r
-    return s; \r
-  }\r
-\r
-       // optional Info here   \r
-       SwingJS.getAppletHtml = function(applet, Info) {\r
-               if (Info) {\r
-                       var d = SwingJS._document;\r
-                       SwingJS._document = null;\r
-                       applet = SwingJS.getApplet(applet, Info);\r
-                       SwingJS._document = d;\r
-               }  \r
-               return applet._code;\r
-       }\r
-\r
-       SwingJS._Applet = function(id, Info, checkOnly){\r
-               window[id] = this;\r
-               this._appletType = "SwingJS._Applet" + (Info.isSigned ? " (signed)" : "");\r
-               this._isJava = true;\r
-               this._availableParams = null; // all allowed\r
-               if (checkOnly)\r
-                       return this;\r
-               this._isSigned = Info.isSigned;\r
-               this._readyFunction = Info.readyFunction;\r
-               this._ready = false;\r
-               this._isJava = true; \r
-               this._isInfoVisible = false;\r
-               this._applet = null;\r
-               this._memoryLimit = Info.memoryLimit || 512;\r
-               this._canScript = function(script) {return true;};\r
-               this._savedOrientations = [];\r
-               this._initialize = function(jarPath, jarFile) {\r
-                       var doReport = false;\r
-                       SwingJS._jarFile && (jarFile = SwingJS._jarFile);\r
-                       if(this._jarFile) {\r
-                               var f = this._jarFile;\r
-                               if(f.indexOf("/") >= 0) {\r
-                                       alert ("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.");\r
-                                       var ok = prompt("Do you want to use applet " + f + "? ", "yes or no")\r
-                                       if(ok == "yes") {\r
-                                               jarPath = f.substring(0, f.lastIndexOf("/"));\r
-                                               jarFile = f.substring(f.lastIndexOf("/") + 1);\r
-                                       } else {\r
-                                               doReport = true;\r
-                                       }\r
-                               } else {\r
-                                       jarFile = f;\r
-                               }\r
-                               this_isSigned = Info.isSigned = (jarFile.indexOf("Signed") >= 0);\r
-                       }\r
-                       this._jarPath = Info.jarPath = jarPath || ".";\r
-                       this._jarFile = Info.jarFile = jarFile;\r
-                       if (doReport)\r
-                               alert ("The web page URL was ignored. Continuing using " + this._jarFile + ' in directory "' + this._jarPath + '"');\r
-                       // could do something like this: Jmol.controls == undefined || Jmol.controls._onloadResetForms();               \r
-               }               \r
-               this._create(id, Info);\r
-               return this;\r
-       }\r
-\r
-       ;(function(Applet, proto) {\r
-  \r
-       Applet._get = function(id, Info, checkOnly) {\r
-\r
-               checkOnly || (checkOnly = false);\r
-               Info || (Info = {});\r
-               var DefaultInfo = {\r
-      code: "swingjs.test.TanSugd3S",\r
-      uncompressed: true,\r
-                       color: "#FFFFFF", // applet object background color\r
-                       width: 300,\r
-                       height: 300,\r
-                       serverURL: "http://your.server.here/jsmol.php",\r
-         console: null,  // div for where the JavaScript console will be.\r
-                       readyFunction: null,\r
-                       use: "HTML5",//other options include JAVA\r
-                       jarPath: "java",\r
-                       jarFile: "[code].jar",\r
-                       j2sPath: "j2s",\r
-                       disableJ2SLoadMonitor: false,\r
-                       disableInitialConsole: false,\r
-                       debug: false\r
-               };       \r
-    \r
-    // Jmol here\r
-    \r
-               Jmol._addDefaultInfo(Info, DefaultInfo);\r
-    Info.jarFile && Info.code && Info.jarFile.replace(/\[code\]/,Info.code);\r
-               Jmol._debugAlert = Info.debug;\r
-               Info.serverURL && (Jmol._serverUrl = Info.serverURL);\r
-\r
-               var javaAllowed = false;\r
-               var applet = null;\r
-               var List = Info.use.toUpperCase().split("#")[0].split(" ");\r
-               for (var i = 0; i < List.length; i++) {\r
-                       switch (List[i]) {\r
-                       case "JAVA":\r
-                               javaAllowed = true;\r
-                               if (Jmol.featureDetection.supportsJava())\r
-                                       applet = new Applet(id, Info, checkOnly);\r
-                               break;\r
-                       case "HTML5":               \r
-                       if (Jmol.featureDetection.allowHTML5){\r
-                                 applet = Applet._getCanvas(id, Info, checkOnly);\r
-        } else {\r
-          List.push("JAVA");\r
-        }\r
-                               break;\r
-                       }\r
-                       if (applet != null)\r
-                               break;            \r
-               }\r
-               if (applet == null) {\r
-                       if (checkOnly || !javaAllowed)\r
-                               applet = {_appletType : "none" };\r
-                       else if (javaAllowed)\r
-                       applet = new Applet(id, Info);\r
-               }\r
-\r
-               // keyed to both its string id and itself\r
-               return (checkOnly ? applet : Jmol._registerApplet(id, applet));  \r
-       }\r
-\r
-       Applet._getCanvas = function(id, Info, checkOnly) {\r
-    Info._isLayered = true;\r
-    Info._isSwing = true;\r
-    Info._platform = "";\r
-               Jmol._Canvas2D.prototype = Jmol._jsSetPrototype(new Applet(id, Info, true));\r
-               return new Jmol._Canvas2D(id, Info, Info.code, checkOnly);\r
-       };\r
-\r
-       /*  AngelH, mar2007:\r
-               By (re)setting these variables in the webpage before calling Jmol.getApplet(),\r
-               a custom message can be provided (e.g. localized for user's language) when no Java is installed.\r
-       */\r
-       Applet._noJavaMsg =\r
-                       "Either you do not have Java applets enabled in your web<br />browser or your browser is blocking this applet.<br />\\r
-                       Check the warning message from your browser and/or enable Java applets in<br />\\r
-                       your web browser preferences, or install the Java Runtime Environment from <a href='http://www.java.com'>www.java.com</a>";\r
-\r
-       Applet._setCommonMethods = function(p) {\r
-               p._showInfo = proto._showInfo;  \r
-///            p._search = proto._search;\r
-               p._getName = proto._getName;\r
-               p._readyCallback = proto._readyCallback;\r
-       }\r
-\r
-       Applet._createApplet = function(applet, Info, params) {\r
-               applet._initialize(Info.jarPath, Info.jarFile);\r
-               var jarFile = applet._jarFile;\r
-               var jnlp = ""\r
-               if (Jmol._isFile) {\r
-                       // local installations need jnlp here and should reference JmolApplet(Signed).jar, not JmolApplet(Signed)0.jar  \r
-                       jarFile = jarFile.replace(/0\.jar/,".jar");\r
-                       //jnlp = " jnlp_href=\"" + jarFile.replace(/\.jar/,".jnlp") + "\"";\r
-               }\r
-               // size is set to 100% of containers' size, but only if resizable. \r
-               // Note that resizability in MSIE requires: \r
-               // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\r
-               var w = (applet._containerWidth.indexOf("px") >= 0 ? applet._containerWidth : "100%");\r
-               var h = (applet._containerHeight.indexOf("px") >= 0 ? applet._containerHeight : "100%");\r
-               var widthAndHeight = " style=\"width:" + w + ";height:" + h + "\" ";\r
-               var attributes = "name='" + applet._id + "_object' id='" + applet._id + "_object' " + "\n"\r
-                               + widthAndHeight + jnlp + "\n"\r
-               params.codebase = applet._jarPath;\r
-               params.codePath = params.codebase + "/";\r
-               if (params.codePath.indexOf("://") < 0) {\r
-                       var base = document.location.href.split("#")[0].split("?")[0].split("/");\r
-                       base[base.length - 1] = params.codePath;\r
-                       params.codePath = base.join("/");\r
-               }\r
-               params.archive = jarFile;\r
-               params.mayscript = 'true';\r
-               params.java_arguments = "-Xmx" + Math.round(Info.memoryLimit || applet._memoryLimit) + "m";\r
-               params.permissions = (applet._isSigned ? "all-permissions" : "sandbox");\r
-               params.documentLocation = document.location.href;\r
-               params.documentBase = document.location.href.split("#")[0].split("?")[0];\r
-\r
-               params.jarPath = Info.jarPath;\r
-               Jmol._syncedApplets.length && (params.synccallback = "Jmol._mySyncCallback");\r
-               applet._startupScript && (params.script = applet._startupScript);\r
-               var t = "\n"; \r
-               for (var i in params)\r
-                       if(params[i])\r
-                               t += "  <param name='"+i+"' value='"+params[i]+"' />\n";\r
-               if (Jmol.featureDetection.useIEObject || Jmol.featureDetection.useHtml4Object) {\r
-                       t = "<object " + attributes\r
-                               + (Jmol.featureDetection.useIEObject ? \r
-                                        " classid='clsid:8AD9C840-044E-11D1-B3E9-00805F499D93' codebase='http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab'>"\r
-                                : " type='application/x-java-applet'>")\r
-                                + t + "<p style='background-color:yellow;" + widthAndHeight.split('"')[1] \r
-                               + ";text-align:center;vertical-align:middle;'>\n" + Applet._noJavaMsg + "</p></object>\n";\r
-               } else { // use applet tag\r
-                       t = "<applet " + attributes\r
-                               + " code='" + params.code + "' codebase='" + applet._jarPath + "' archive='" + jarFile + "' mayscript='true'>\n"\r
-                               + t + "<table bgcolor='yellow'><tr><td align='center' valign='middle' " + widthAndHeight + ">\n"\r
-                               + Applet._noJavaMsg + "</td></tr></table></applet>\n";\r
-               }\r
-               if (applet._deferApplet)\r
-                       applet._javaCode = t, t="";\r
-               t = Jmol._getWrapper(applet, true) + t + Jmol._getWrapper(applet, false) \r
-                       + (Info.addSelectionOptions ? Jmol._getGrabberOptions(applet) : "");\r
-               if (Jmol._debugAlert)\r
-                       alert (t);\r
-               applet._code = Jmol._documentWrite(t);\r
-       }\r
-\r
-       proto._newApplet = function(viewerOptions) {\r
-               this._viewerOptions = viewerOptions;\r
-    // for now assigning this._applet here instead of in readyCallback\r
-               this._appletPanel = new swingjs.JSAppletPanel(viewerOptions);\r
-    this._appletPanel.start();\r
-       }\r
-       \r
-       proto._addCoreFiles = function() {\r
-               Jmol._addCoreFile("swingjs", this._j2sPath, this.__Info.preloadCore);\r
-               if (Jmol._debugCode) {\r
-               // no min package for that\r
-                       Jmol._addExec([this, null, "swingjs.JSAppletPanel", "load " + this.__Info.code]);\r
-      \r
-               }\r
-  }\r
-  \r
-       proto._create = function(id, Info){\r
-               Jmol._setObject(this, id, Info);\r
-               var params = {\r
-                       syncId: Jmol._syncId,\r
-                       progressbar: "true",                      \r
-                       progresscolor: "blue",\r
-                       boxbgcolor: this._color || "black",\r
-                       boxfgcolor: "white",\r
-                       boxmessage: "Downloading Applet ...",\r
-                       //script: (this._color ? "background \"" + this._color +"\"": ""),\r
-                       code: Info.appletClass + ".class"\r
-               };\r
-\r
-               Jmol._setAppletParams(this._availableParams, params, Info);\r
-               function sterilizeInline(model) {\r
-                       model = model.replace(/\r|\n|\r\n/g, (model.indexOf("|") >= 0 ? "\\/n" : "|")).replace(/'/g, "&#39;");\r
-                       if(Jmol._debugAlert)\r
-                               alert ("inline model:\n" + model);\r
-                       return model;\r
-               }\r
-\r
-               params.loadInline = (Info.inlineModel ? sterilizeInline(Info.inlineModel) : "");\r
-               params.appletReadyCallback = "Jmol._readyCallback";\r
-               if (Jmol._syncedApplets.length)\r
-                       params.synccallback = "Jmol._mySyncCallback";\r
-               params.java_arguments = "-Xmx" + Math.round(Info.memoryLimit || this._memoryLimit) + "m";\r
-\r
-               this._initialize(Info.jarPath, Info.jarFile);\r
-               Applet._createApplet(this, Info, params);\r
-       }\r
-\r
-\r
-       proto._restoreState = function(clazzName, state) {\r
-   // applet-dependent\r
-       }\r
-\r
-       proto._readyCallback = function(id, fullid, isReady) {\r
-               if (!isReady)\r
-                       return; // ignore -- page is closing\r
-               Jmol._setDestroy(this);\r
-               this._ready = true;\r
-               var script = this._readyScript;\r
-               if (this._defaultModel)\r
-                       Jmol._search(this, this._defaultModel, (script ? ";" + script : ""));\r
-               else if (script)\r
-                       this._script(script);\r
-               else if (this._src)\r
-                       this._script('load "' + this._src + '"');\r
-               this._showInfo(true);\r
-               this._showInfo(false);\r
-               Jmol.Cache.setDragDrop(this);\r
-               this._readyFunction && this._readyFunction(this);\r
-               Jmol._setReady(this);\r
-               var app = this._2dapplet;\r
-               if (app && app._isEmbedded && app._ready && app.__Info.visible)\r
-                       this._show2d(true);\r
-       }\r
-\r
-       proto._showInfo = function(tf) {\r
-               if(tf && this._2dapplet)\r
-                       this._2dapplet._show(false);\r
-               Jmol.$html(Jmol.$(this, "infoheaderspan"), this._infoHeader);\r
-               if (this._info)\r
-                       Jmol.$html(Jmol.$(this, "infodiv"), this._info);\r
-               if ((!this._isInfoVisible) == (!tf))\r
-                       return;\r
-               this._isInfoVisible = tf;\r
-               // 1px does not work for MSIE\r
-               if (this._isJava) {\r
-                       var x = (tf ? 2 : "100%");\r
-                       Jmol.$setSize(Jmol.$(this, "appletdiv"), x, x);\r
-               }\r
-               Jmol.$setVisible(Jmol.$(this, "infotablediv"), tf);\r
-               Jmol.$setVisible(Jmol.$(this, "infoheaderdiv"), tf);\r
-               this._show(!tf);\r
-       }\r
-\r
-       proto._show = function(tf) {\r
-               var x = (!tf ? 2 : "100%");\r
-               Jmol.$setSize(Jmol.$(this, "object"), x, x);\r
-               if (!this._isJava)\r
-                       Jmol.$setVisible(Jmol.$(this, "appletdiv"), tf);\r
-       }\r
-\r
-       proto._clearConsole = function () {\r
-                       if (this._console == this._id + "_infodiv")\r
-                               this.info = "";\r
-                       if (!self.Clazz)return;\r
-                       Jmol._setConsoleDiv(this._console);\r
-                       Clazz.Console.clear();\r
-               }\r
-\r
-       proto._resizeApplet = function(size) {\r
-               // See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]\r
-               //  Special case: an empty value for width or height is accepted, meaning no change in that dimension.\r
-\r
-               /*\r
-                * private functions\r
-                */\r
-               function _getAppletSize(size, units) {\r
-                       /* Accepts single number, 2-value array, or object with width and height as mroperties, each one can be one of:\r
-                        percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)\r
-                        [width, height] array of strings is returned, with units added if specified.\r
-                        Percent is relative to container div or element (which should have explicitly set size).\r
-                        */\r
-                       var width, height;\r
-                       if(( typeof size) == "object" && size != null) {\r
-                               width = size[0]||size.width;\r
-                               height = size[1]||size.height;\r
-                       } else {\r
-                               width = height = size;\r
-                       }\r
-                       return [_fixDim(width, units), _fixDim(height, units)];\r
-               }\r
-\r
-               function _fixDim(x, units) {\r
-                       var sx = "" + x;\r
-                       return (sx.length == 0 ? (units ? "" : Jmol._allowedJmolSize[2]) \r
-                               : sx.indexOf("%") == sx.length - 1 ? sx \r
-                               : (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%" \r
-                               : (isNaN(x = Math.floor(x)) ? Jmol._allowedJmolSize[2] \r
-                               : x < Jmol._allowedJmolSize[0] ? Jmol._allowedJmolSize[0] \r
-                               : x > Jmol._allowedJmolSize[1] ? Jmol._allowedJmolSize[1] \r
-                               : x)\r
-                               + (units ? units : "")\r
-                       );\r
-               }\r
-\r
-               var sz = _getAppletSize(size, "px");\r
-               var d = Jmol._getElement(this, "appletinfotablediv");\r
-               d.style.width = sz[0];\r
-               d.style.height = sz[1];\r
-               this._containerWidth = sz[0];\r
-               this._containerHeight = sz[1];\r
-               if (this._is2D)\r
-                       Jmol._repaint(this, true);\r
-       }\r
-\r
-       proto._cover = function (doCover) {\r
-    // from using getAppletHtml()\r
-               this._newCanvas(false);\r
-               this._showInfo(false);\r
-               this._init();\r
-       };\r
-\r
-\r
-  \r
-})(SwingJS._Applet, SwingJS._Applet.prototype);\r
-\r
-})(SwingJS, jQuery);\r
-\r
-} // SwingJS undefined\r
+// SwingJS.js
+
+// BH 7/24/2015 9:09:39 AM allows setting Info.resourcePath
+// BH 4/28/2015 10:15:32 PM adds getAppletHtml 
+// BH 4/2/2015 5:17:44 PM  adds SwingJS.getJavaResource(path)
+
+// BH 3/27/2015 6:34:49 AM  just a shell
+
+if(typeof(jQuery)=="undefined") alert ("Note -- jQuery is required for SwingJS, but it's not defined.")
+
+if (typeof(SwingJS) == "undefined") {
+
+  SwingJS = {};
+
+(function (SwingJS, $) {
+
+       SwingJS.getApplet = function(id, Info, checkOnly) {
+               return SwingJS._Applet._get(id, Info, checkOnly);
+       }
+
+  SwingJS.getJavaResource = function(path, isJavaPath) {
+               if (path.indexOf("http") != 0) {
+      var applet = Jmol._applets[java.lang.Thread.currentThread().getName()];
+      path = (!isJavaPath && applet.__Info.resourcePath || applet.__Info.j2sPath) + "/" + path
+      }      
+    System.out.println("Swingjs.js getJavaResource " + path)
+    var s = Jmol._getFileData(path);
+    if (s.indexOf("[Exception") == 0)
+      return null; 
+    if (path.lastIndexOf(".css") == path.length - 4) {
+      path = path.substring(0, path.lastIndexOf("/") + 1) + "images/";
+      s = s.replace(/images\//g, path)
+      jQuery("head").append(jQuery("<style type='text/css'>" + s + "</style>"));
+      return s;
+    } else if (path.lastIndexOf(".js") == path.length - 3) {
+      try {
+        eval(s);
+      } catch (e) {
+      alert("error processing " + s)
+        return null;
+      }
+    }
+    return s; 
+  }
+
+       // optional Info here   
+       SwingJS.getAppletHtml = function(applet, Info) {
+               if (Info) {
+                       var d = SwingJS._document;
+                       SwingJS._document = null;
+                       applet = SwingJS.getApplet(applet, Info);
+                       SwingJS._document = d;
+               }  
+               return applet._code;
+       }
+
+       SwingJS._Applet = function(id, Info, checkOnly){
+               window[id] = this;
+               this._appletType = "SwingJS._Applet" + (Info.isSigned ? " (signed)" : "");
+               this._isJava = true;
+               this._availableParams = null; // all allowed
+               if (checkOnly)
+                       return this;
+               this._isSigned = Info.isSigned;
+               this._readyFunction = Info.readyFunction;
+               this._ready = false;
+               this._isJava = true; 
+               this._isInfoVisible = false;
+               this._applet = null;
+               this._memoryLimit = Info.memoryLimit || 512;
+               this._canScript = function(script) {return true;};
+               this._savedOrientations = [];
+               this._initialize = function(jarPath, jarFile) {
+                       var doReport = false;
+                       SwingJS._jarFile && (jarFile = SwingJS._jarFile);
+                       if(this._jarFile) {
+                               var f = this._jarFile;
+                               if(f.indexOf("/") >= 0) {
+                                       alert ("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.");
+                                       var ok = prompt("Do you want to use applet " + f + "? ", "yes or no")
+                                       if(ok == "yes") {
+                                               jarPath = f.substring(0, f.lastIndexOf("/"));
+                                               jarFile = f.substring(f.lastIndexOf("/") + 1);
+                                       } else {
+                                               doReport = true;
+                                       }
+                               } else {
+                                       jarFile = f;
+                               }
+                               this_isSigned = Info.isSigned = (jarFile.indexOf("Signed") >= 0);
+                       }
+                       this._jarPath = Info.jarPath = jarPath || ".";
+                       this._jarFile = Info.jarFile = jarFile;
+                       if (doReport)
+                               alert ("The web page URL was ignored. Continuing using " + this._jarFile + ' in directory "' + this._jarPath + '"');
+                       // could do something like this: Jmol.controls == undefined || Jmol.controls._onloadResetForms();               
+               }               
+               this._create(id, Info);
+               return this;
+       }
+
+       ;(function(Applet, proto) {
+  
+       Applet._get = function(id, Info, checkOnly) {
+
+               checkOnly || (checkOnly = false);
+               Info || (Info = {});
+               var DefaultInfo = {
+      code: "swingjs.test.TanSugd3S",
+      uncompressed: true,
+                       color: "#FFFFFF", // applet object background color
+                       width: 300,
+                       height: 300,
+                       serverURL: "http://your.server.here/jsmol.php",
+         console: null,  // div for where the JavaScript console will be.
+                       readyFunction: null,
+                       use: "HTML5",//other options include JAVA
+                       jarPath: "java",
+                       jarFile: "[code].jar",
+                       j2sPath: "j2s",
+                       disableJ2SLoadMonitor: false,
+                       disableInitialConsole: false,
+                       debug: false
+               };       
+    
+    // Jmol here
+    
+               Jmol._addDefaultInfo(Info, DefaultInfo);
+    Info.jarFile && Info.code && Info.jarFile.replace(/\[code\]/,Info.code);
+               Jmol._debugAlert = Info.debug;
+               Info.serverURL && (Jmol._serverUrl = Info.serverURL);
+
+               var javaAllowed = false;
+               var applet = null;
+               var List = Info.use.toUpperCase().split("#")[0].split(" ");
+               for (var i = 0; i < List.length; i++) {
+                       switch (List[i]) {
+                       case "JAVA":
+                               javaAllowed = true;
+                               if (Jmol.featureDetection.supportsJava())
+                                       applet = new Applet(id, Info, checkOnly);
+                               break;
+                       case "HTML5":               
+                       if (Jmol.featureDetection.allowHTML5){
+                                 applet = Applet._getCanvas(id, Info, checkOnly);
+        } else {
+          List.push("JAVA");
+        }
+                               break;
+                       }
+                       if (applet != null)
+                               break;            
+               }
+               if (applet == null) {
+                       if (checkOnly || !javaAllowed)
+                               applet = {_appletType : "none" };
+                       else if (javaAllowed)
+                       applet = new Applet(id, Info);
+               }
+
+               // keyed to both its string id and itself
+               return (checkOnly ? applet : Jmol._registerApplet(id, applet));  
+       }
+
+       Applet._getCanvas = function(id, Info, checkOnly) {
+    Info._isLayered = true;
+    Info._isSwing = true;
+    Info._platform = "";
+               Jmol._Canvas2D.prototype = Jmol._jsSetPrototype(new Applet(id, Info, true));
+               return new Jmol._Canvas2D(id, Info, Info.code, checkOnly);
+       };
+
+       /*  AngelH, mar2007:
+               By (re)setting these variables in the webpage before calling Jmol.getApplet(),
+               a custom message can be provided (e.g. localized for user's language) when no Java is installed.
+       */
+       Applet._noJavaMsg =
+                       "Either you do not have Java applets enabled in your web<br />browser or your browser is blocking this applet.<br />\
+                       Check the warning message from your browser and/or enable Java applets in<br />\
+                       your web browser preferences, or install the Java Runtime Environment from <a href='http://www.java.com'>www.java.com</a>";
+
+       Applet._setCommonMethods = function(p) {
+               p._showInfo = proto._showInfo;  
+///            p._search = proto._search;
+               p._getName = proto._getName;
+               p._readyCallback = proto._readyCallback;
+       }
+
+       Applet._createApplet = function(applet, Info, params) {
+               applet._initialize(Info.jarPath, Info.jarFile);
+               var jarFile = applet._jarFile;
+               var jnlp = ""
+               if (Jmol._isFile) {
+                       // local installations need jnlp here and should reference JmolApplet(Signed).jar, not JmolApplet(Signed)0.jar  
+                       jarFile = jarFile.replace(/0\.jar/,".jar");
+                       //jnlp = " jnlp_href=\"" + jarFile.replace(/\.jar/,".jnlp") + "\"";
+               }
+               // size is set to 100% of containers' size, but only if resizable. 
+               // Note that resizability in MSIE requires: 
+               // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+               var w = (applet._containerWidth.indexOf("px") >= 0 ? applet._containerWidth : "100%");
+               var h = (applet._containerHeight.indexOf("px") >= 0 ? applet._containerHeight : "100%");
+               var widthAndHeight = " style=\"width:" + w + ";height:" + h + "\" ";
+               var attributes = "name='" + applet._id + "_object' id='" + applet._id + "_object' " + "\n"
+                               + widthAndHeight + jnlp + "\n"
+               params.codebase = applet._jarPath;
+               params.codePath = params.codebase + "/";
+               if (params.codePath.indexOf("://") < 0) {
+                       var base = document.location.href.split("#")[0].split("?")[0].split("/");
+                       base[base.length - 1] = params.codePath;
+                       params.codePath = base.join("/");
+               }
+               params.archive = jarFile;
+               params.mayscript = 'true';
+               params.java_arguments = "-Xmx" + Math.round(Info.memoryLimit || applet._memoryLimit) + "m";
+               params.permissions = (applet._isSigned ? "all-permissions" : "sandbox");
+               params.documentLocation = document.location.href;
+               params.documentBase = document.location.href.split("#")[0].split("?")[0];
+
+               params.jarPath = Info.jarPath;
+               Jmol._syncedApplets.length && (params.synccallback = "Jmol._mySyncCallback");
+               applet._startupScript && (params.script = applet._startupScript);
+               var t = "\n"; 
+               for (var i in params)
+                       if(params[i])
+                               t += "  <param name='"+i+"' value='"+params[i]+"' />\n";
+               if (Jmol.featureDetection.useIEObject || Jmol.featureDetection.useHtml4Object) {
+                       t = "<object " + attributes
+                               + (Jmol.featureDetection.useIEObject ? 
+                                        " classid='clsid:8AD9C840-044E-11D1-B3E9-00805F499D93' codebase='http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab'>"
+                                : " type='application/x-java-applet'>")
+                                + t + "<p style='background-color:yellow;" + widthAndHeight.split('"')[1] 
+                               + ";text-align:center;vertical-align:middle;'>\n" + Applet._noJavaMsg + "</p></object>\n";
+               } else { // use applet tag
+                       t = "<applet " + attributes
+                               + " code='" + params.code + "' codebase='" + applet._jarPath + "' archive='" + jarFile + "' mayscript='true'>\n"
+                               + t + "<table bgcolor='yellow'><tr><td align='center' valign='middle' " + widthAndHeight + ">\n"
+                               + Applet._noJavaMsg + "</td></tr></table></applet>\n";
+               }
+               if (applet._deferApplet)
+                       applet._javaCode = t, t="";
+               t = Jmol._getWrapper(applet, true) + t + Jmol._getWrapper(applet, false) 
+                       + (Info.addSelectionOptions ? Jmol._getGrabberOptions(applet) : "");
+               if (Jmol._debugAlert)
+                       alert (t);
+               applet._code = Jmol._documentWrite(t);
+       }
+
+       proto._newApplet = function(viewerOptions) {
+               this._viewerOptions = viewerOptions;
+    // for now assigning this._applet here instead of in readyCallback
+               this._appletPanel = new swingjs.JSAppletPanel(viewerOptions);
+    this._appletPanel.start();
+       }
+       
+       proto._addCoreFiles = function() {
+               Jmol._addCoreFile("swingjs", this._j2sPath, this.__Info.preloadCore);
+               if (Jmol._debugCode) {
+               // no min package for that
+                       Jmol._addExec([this, null, "swingjs.JSAppletPanel", "load " + this.__Info.code]);
+      
+               }
+  }
+  
+       proto._create = function(id, Info){
+               Jmol._setObject(this, id, Info);
+               var params = {
+                       syncId: Jmol._syncId,
+                       progressbar: "true",                      
+                       progresscolor: "blue",
+                       boxbgcolor: this._color || "black",
+                       boxfgcolor: "white",
+                       boxmessage: "Downloading Applet ...",
+                       //script: (this._color ? "background \"" + this._color +"\"": ""),
+                       code: Info.appletClass + ".class"
+               };
+
+               Jmol._setAppletParams(this._availableParams, params, Info);
+               function sterilizeInline(model) {
+                       model = model.replace(/\r|\n|\r\n/g, (model.indexOf("|") >= 0 ? "\\/n" : "|")).replace(/'/g, "&#39;");
+                       if(Jmol._debugAlert)
+                               alert ("inline model:\n" + model);
+                       return model;
+               }
+
+               params.loadInline = (Info.inlineModel ? sterilizeInline(Info.inlineModel) : "");
+               params.appletReadyCallback = "Jmol._readyCallback";
+               if (Jmol._syncedApplets.length)
+                       params.synccallback = "Jmol._mySyncCallback";
+               params.java_arguments = "-Xmx" + Math.round(Info.memoryLimit || this._memoryLimit) + "m";
+
+               this._initialize(Info.jarPath, Info.jarFile);
+               Applet._createApplet(this, Info, params);
+       }
+
+
+       proto._restoreState = function(clazzName, state) {
+   // applet-dependent
+       }
+
+       proto._readyCallback = function(id, fullid, isReady) {
+               if (!isReady)
+                       return; // ignore -- page is closing
+               Jmol._setDestroy(this);
+               this._ready = true;
+               var script = this._readyScript;
+               if (this._defaultModel)
+                       Jmol._search(this, this._defaultModel, (script ? ";" + script : ""));
+               else if (script)
+                       this._script(script);
+               else if (this._src)
+                       this._script('load "' + this._src + '"');
+               this._showInfo(true);
+               this._showInfo(false);
+               Jmol.Cache.setDragDrop(this);
+               this._readyFunction && this._readyFunction(this);
+               Jmol._setReady(this);
+               var app = this._2dapplet;
+               if (app && app._isEmbedded && app._ready && app.__Info.visible)
+                       this._show2d(true);
+       }
+
+       proto._showInfo = function(tf) {
+               if(tf && this._2dapplet)
+                       this._2dapplet._show(false);
+               Jmol.$html(Jmol.$(this, "infoheaderspan"), this._infoHeader);
+               if (this._info)
+                       Jmol.$html(Jmol.$(this, "infodiv"), this._info);
+               if ((!this._isInfoVisible) == (!tf))
+                       return;
+               this._isInfoVisible = tf;
+               // 1px does not work for MSIE
+               if (this._isJava) {
+                       var x = (tf ? 2 : "100%");
+                       Jmol.$setSize(Jmol.$(this, "appletdiv"), x, x);
+               }
+               Jmol.$setVisible(Jmol.$(this, "infotablediv"), tf);
+               Jmol.$setVisible(Jmol.$(this, "infoheaderdiv"), tf);
+               this._show(!tf);
+       }
+
+       proto._show = function(tf) {
+               var x = (!tf ? 2 : "100%");
+               Jmol.$setSize(Jmol.$(this, "object"), x, x);
+               if (!this._isJava)
+                       Jmol.$setVisible(Jmol.$(this, "appletdiv"), tf);
+       }
+
+       proto._clearConsole = function () {
+                       if (this._console == this._id + "_infodiv")
+                               this.info = "";
+                       if (!self.Clazz)return;
+                       Jmol._setConsoleDiv(this._console);
+                       Clazz.Console.clear();
+               }
+
+       proto._resizeApplet = function(size) {
+               // See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]
+               //  Special case: an empty value for width or height is accepted, meaning no change in that dimension.
+
+               /*
+                * private functions
+                */
+               function _getAppletSize(size, units) {
+                       /* Accepts single number, 2-value array, or object with width and height as mroperties, each one can be one of:
+                        percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
+                        [width, height] array of strings is returned, with units added if specified.
+                        Percent is relative to container div or element (which should have explicitly set size).
+                        */
+                       var width, height;
+                       if(( typeof size) == "object" && size != null) {
+                               width = size[0]||size.width;
+                               height = size[1]||size.height;
+                       } else {
+                               width = height = size;
+                       }
+                       return [_fixDim(width, units), _fixDim(height, units)];
+               }
+
+               function _fixDim(x, units) {
+                       var sx = "" + x;
+                       return (sx.length == 0 ? (units ? "" : Jmol._allowedJmolSize[2]) 
+                               : sx.indexOf("%") == sx.length - 1 ? sx 
+                               : (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%" 
+                               : (isNaN(x = Math.floor(x)) ? Jmol._allowedJmolSize[2] 
+                               : x < Jmol._allowedJmolSize[0] ? Jmol._allowedJmolSize[0] 
+                               : x > Jmol._allowedJmolSize[1] ? Jmol._allowedJmolSize[1] 
+                               : x)
+                               + (units ? units : "")
+                       );
+               }
+
+               var sz = _getAppletSize(size, "px");
+               var d = Jmol._getElement(this, "appletinfotablediv");
+               d.style.width = sz[0];
+               d.style.height = sz[1];
+               this._containerWidth = sz[0];
+               this._containerHeight = sz[1];
+               if (this._is2D)
+                       Jmol._repaint(this, true);
+       }
+
+       proto._cover = function (doCover) {
+    // from using getAppletHtml()
+               this._newCanvas(false);
+               this._showInfo(false);
+               this._init();
+       };
+
+
+  
+})(SwingJS._Applet, SwingJS._Applet.prototype);
+
+})(SwingJS, jQuery);
+
+} // SwingJS undefined