1 // Jalview Priliminary applet-generation code.
2 // author: Bob Hanson hansonr@stolaf.edu
8 $(document).ready(function() {
9 if (document.location.href.toLowerCase().indexOf("_use=java") < 0)
10 Jalview.processAllAppletElements(self.JalviewInfo);
14 Jalview.processAllAppletElements = function(PageInfo) {
15 var applets = document.getElementsByTagName("applet");
17 for (var i = 0; i < applets.length; i++)
19 for (var i = 0; i < apps.length; i++) {
20 Jalview.processAppletElement(apps[i], PageInfo);
24 Jalview.processAppletElement = function(element, UserInfo) {
26 var code = element.getAttribute("code");
27 var parent = element.parentElement;
28 if (code != "jalview.bin.JalviewLite") {
34 main: "jalview.bin.Jalview",
36 resourcePath: "examples",
38 serverURL: 'https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php',
39 j2sPath: 'swingjs/j2s',
41 startButton:'Start Jalview',
43 embedInternalFrames:false,
45 allowJavascript: true,
48 var text = element.outerHTML;
49 var args = Info.args = text.replace(/[\n\t]/g, " ").split("<param ");
51 // overwrite default parameters with UserInfo (global JalviewInfo):
54 for (var i in UserInfo) {
55 Info[i] = UserInfo[i];
58 // generate name/value pairs for parameters in Applet tag
60 Info.j2sAppletID = Info.j2sAppletID
61 || element.getAttribute("name")
62 || element.getAttribute("id")
63 || Info.idPrefix.replace(/%ID%/g, "jalview" + ++Jalview.jvid);
65 //Info.jalview_SCREEN_X= 10,Info.jalview_SCREEN_Y= 10;
66 //Info.jalview_EMBEDDED= true;
67 //Info.jalview_SCREEN_WIDTH = 400;
68 //Info.jalview_SCREEN_HEIGHT = 100;
71 var addParam = function(key,value) {
72 args.push("name=\"" + key + "\" value=\"" + value + "\"");
77 var v = ("" + Info[i] || "null").replace(/\"/g,"'");
78 addParam("Info." + i, v);
83 element.JalviewInfo = Info;
84 var btn = document.createElement("button");
85 btn.appletElement = element;
86 var a = element.getAttribute("width");
87 //a && (btn.style.width = (a || 140) + "px");
88 a = element.getAttribute("height");
89 //a && (btn.style.height = (a || 25) + "px");
90 btn.jvparent = parent;
91 if (Info.startButton) {
92 btn.innerHTML = Info.startButton;
93 parent.replaceChild(btn, element);
94 $(btn).click(Jalview.doStartJalview);
96 parent.removeChild(element);
97 Jalview.doStartJalview({target:btn});
103 Jalview.doStartJalview = function(e) {
104 e.target.disabled = true;
105 var element = e.target.appletElement;
106 var parent = e.target.jvparent;
107 var Info = element.JalviewInfo;
108 var id = Info.j2sAppletID;
109 var d = document.createElement("div");
110 d.id = id + "-desktop-div";
111 if (Info.hideDesktop) {
112 d.style.display = "none";
113 d.style.width = d.style.height = "0px";
115 d.style.width = "300px", d.style.height = "70px";
117 parent.appendChild(d);
118 d = document.createElement("div");
119 d.id = id + "-alignment-div";
120 if (Info.embedInternalFrames) {
123 d.style.display = "none";
124 d.style.width = d.style.height = "0px";
126 if (Info.allowJavascript) {
127 if (Info.readyFunction) {
128 var c = Info.readyFunction;
129 Info.readyFunction = function(a){
131 c.apply(null, arguments);
134 Info.readyFunction = function(a) {Jalview._setAPI(a)};
137 var app = SwingJS.getApplet(id, Info);
140 Jalview._setAPI = function(app) {
142 // Create a map of nonqualified methods to qualified methods
143 // based on parameter type.
144 var cl = Class.forName$S("jalview.bin.Jalview");
145 if (!cl.$clazz$.getInstance$) {
146 System.err.println(app.__Info.main + " has no getInstance() method; interface creation skipped.");
149 var instance = app._instance = cl.$clazz$.getInstance$();
150 var apply = function(args, methods) {
151 return methods[args.length].apply(instance, args);
153 var getMap = function(cl) {
154 var methods = cl.getMethods$();
155 var p = cl.$clazz$.prototype;
157 for (var i = 0, n = methods.length; i < n; i++) {
158 var qname = methods[i].name;
159 if (cl.$clazz$[qname])
160 continue; // static method
161 var s = qname.split("$");
164 continue; // $init$, $cinit$
167 System.err.println(app._id + "." + name + " is " + qname);
169 (m = map[name])||(m = map[name] = []);
170 var j = p[qname].length;
172 System.err.println(app._id + ".instance." + qname + " must be called directly.");
173 app[qname] = p[qname];
175 System.out.println(app._id + "." + name + "(" + j + ") aliases " + app._id + ".instance." + qname);
181 var getFunc = function(map,i) {
182 return function(){return apply(arguments,map[i])};
184 var map = getMap(Clazz._4Name(app.__Info.main));
188 app[i] = getFunc(map,i);
190 System.err.println(app._id + " contains " + n + " JavaScript interface methods");