From: <mo...@us...> - 2012-04-27 20:02:54
|
Revision: 17061 http://jmol.svn.sourceforge.net/jmol/?rev=17061&view=rev Author: molusc2 Date: 2012-04-27 20:02:46 +0000 (Fri, 27 Apr 2012) Log Message: ----------- added resizeApplet() method to jmolApplet. Not yet tested with MSIE for resize. Modified Paths: -------------- trunk/Jmol/appletweb/JmolApi.js trunk/Jmol/appletweb/JmolApplet.js trunk/Jmol/appletweb/JmolCore.js Modified: trunk/Jmol/appletweb/JmolApi.js =================================================================== --- trunk/Jmol/appletweb/JmolApi.js 2012-04-26 22:23:58 UTC (rev 17060) +++ trunk/Jmol/appletweb/JmolApi.js 2012-04-27 20:02:46 UTC (rev 17061) @@ -57,7 +57,67 @@ Jmol.script = function(applet, script) { applet._script(script); } + + Jmol.scriptWait = function(applet, script) { + return applet._scriptWait(script); + } + + Jmol.scriptEcho = function(applet, script) { + return applet._scriptEcho(script); + } + + Jmol.scriptMessage = function(applet, script) { + return applet._scriptMessage(script); + } + + Jmol.scriptWaitOutput = function(applet, script) { + return applet._scriptWait(script); + } + + Jmol.scriptWaitAsArray = function(applet, script) { + return applet._scriptWait(script); + } + + Jmol.getStatus = function(applet,strStatus) { + return applet._getStatus(strStatus); + } + + Jmol.getPropertyAsArray = function(applet,sKey,sValue) { + return applet._getPropertyAsArray(sKey,sValue); + } + Jmol.getPropertyAsString = function(applet,sKey,sValue) { + return applet._getPropertyAsString(sKey,sValue); + } + + Jmol.getPropertyAsJSON = function(applet,sKey,sValue) { + return applet._getPropertyAsJSON(sKey,sValue); + } + + Jmol.getPropertyAsJavaObject = function(applet,sKey,sValue) { + return applet._getPropertyAsJavaObject(sKey,sValue); + } + + Jmol.evaluate = function(applet,molecularMath) { + return applet._evaluate(molecularMath); + } + + Jmol.saveOrientation = function(applet,id) { + return applet._saveOrientation(id); + } + + Jmol.restoreOrientation = function(applet,id) { + return applet._restoreOrientation(id); + } + + Jmol.restoreOrientationDelayed = function(applet,id,delay) { + return applet._restoreOrientationDelayed(id,delay); + } + + Jmol.resizeApplet = function(applet,size) { + return applet._resizeApplet(size); + } + Jmol.search = function(applet, query, script) { applet._search(query, script); } Modified: trunk/Jmol/appletweb/JmolApplet.js =================================================================== --- trunk/Jmol/appletweb/JmolApplet.js 2012-04-26 22:23:58 UTC (rev 17060) +++ trunk/Jmol/appletweb/JmolApplet.js 2012-04-27 20:02:46 UTC (rev 17061) @@ -45,6 +45,9 @@ this._jmolJarPath = Info.jmolJarPath || "."; this._memoryLimit = Info.memoryLimit || 512; this._canScript = function(script) {return true;}; + this._savedOrientations = []; + this._containerWidth = this._width + ((this._width==parseFloat(this._width))? "px":""); + this._containerHeight = this._height + ((this._height==parseFloat(this._height))? "px":""); /* * private variables @@ -117,7 +120,6 @@ function writeParams() { var t = ""; - console.log(params); for (var i in params) if(params[i]!="") t+=" <param name='"+i+"' value='"+params[i]+"' />\n"; @@ -129,7 +131,7 @@ 'messagecallback','pickcallback','animframecallback','appletreadycallback','atommovedcallback', 'echocallback','evalcallback','hovercallback','language','loadstructcallback','measurecallback', 'minimizationcallback','resizecallback','scriptcallback','statusform','statustext','statustextarea', - 'synccallback']; + 'synccallback','usecommandthread']; for (var i in Info) if(availableValues[i.toLowerCase()]) params[i] = Info [i]; @@ -150,8 +152,8 @@ }; params.appletReadyCallback = this._id + ".readyCallback"; - //var sz = j._applet.getSize(); - var widthAndHeight = " width='" + this._width + "' height='" + this._height + "' "; + //size is set to 100% of containers' size + var widthAndHeight = " width='" + "100%" + "' height='" + "100%" + "' "; var tHeader, tFooter; getParameters(Info); @@ -235,8 +237,8 @@ return; this._isInfoVisible = tf; Jmol._getElement(this, "infotablediv").style.display = (tf ? "block" : "none"); - Jmol._getElement(this, "appletdiv").style.height = (tf ? 1 : this._height) + "px"; - Jmol._getElement(this, "appletdiv").style.width = (tf ? 1 : this._width) + "px"; + Jmol._getElement(this, "appletdiv").style.height = (tf ? "1px" : "100%"); + Jmol._getElement(this, "appletdiv").style.width = (tf ? "1px" : "100%"); if (!tf)//&& Jmol._isMsieRenderBug -- occurring also on Mac systems) alert("returning to applet..."); this._show(!tf); @@ -277,8 +279,8 @@ } Jmol._Applet.prototype._show = function(tf) { - var w = (tf ? this._width : 1) + "px"; - var h = (tf ? this._height : 1) + "px"; + var w = (tf ? "100%" : "1px"); + var h = (tf ? "100%" : "1px"); document.getElementById(this._id).style.width = w; document.getElementById(this._id).style.height = h; } @@ -290,8 +292,169 @@ return; } this._applet.script(script); - } + } + Jmol._Applet.prototype._scriptWait = function(script) { + var Ret = this._scriptWaitAsArray(script); + var s = ""; + for(var i = Ret.length; --i >= 0; ) + for(var j = 0, jj = Ret[i].length; j < jj; j++) + s += Ret[i][j] + "\n"; + return s; + } + + Jmol._Applet.prototype._scriptEcho = function(script) { + // returns a newline-separated list of all echos from a script + var Ret = this._scriptWaitAsArray(script); + var s = ""; + for(var i = Ret.length; --i >= 0; ) + for(var j = Ret[i].length; --j >= 0; ) + if(Ret[i][j][1] == "scriptEcho") + s += Ret[i][j][3] + "\n"; + return s.replace(/ \| /g, "\n"); + } + + Jmol._Applet.prototype._scriptMessage = function(script) { + // returns a newline-separated list of all messages from a script, ending with "script completed\n" + var Ret = this._scriptWaitAsArray(script); + var s = ""; + for(var i = Ret.length; --i >= 0; ) + for(var j = Ret[i].length; --j >= 0; ) + if(Ret[i][j][1] == "scriptStatus") + s += Ret[i][j][3] + "\n"; + return s.replace(/ \| /g, "\n"); + } + + Jmol._Applet.prototype._scriptWaitOutput = function(script) { + var ret = ""; + try { + if(script) { + ret += this._applet.scriptWaitOutput(script); + } + } catch(e) { + } + return ret; + } + + Jmol._Applet.prototype._scriptWaitAsArray = function(script) { + var ret = ""; + try { + this._getStatus("scriptEcho,scriptMessage,scriptStatus,scriptError"); + if(script) { + ret += this._applet.scriptWait(script); + ret = Jmol._evalJSON(ret, "jmolStatus"); + if( typeof ret == "object") + return ret; + } + } catch(e) { + } + return [[ret]]; + } + + Jmol._Applet.prototype._getStatus = function(strStatus) { + return Jmol._sortMessages(this._getPropertyAsArray("jmolStatus",strStatus)); + } + + Jmol._Applet.prototype._getPropertyAsArray = function(sKey,sValue) { + return Jmol._evalJSON(this._getPropertyAsJSON(sKey,sValue),sKey); + } + + Jmol._Applet.prototype._getPropertyAsString = function(sKey,sValue) { + sValue == undefined && ( sValue = ""); + return this._applet.getPropertyAsString(sKey, sValue) + ""; + } + + Jmol._Applet.prototype._getPropertyAsJSON = function(sKey,sValue) { + sValue == undefined && ( sValue = ""); + try { + return (this._applet.getPropertyAsJSON(sKey, sValue) + ""); + } catch(e) { + return ""; + } + } + + Jmol._Applet.prototype._getPropertyAsJavaObject = function(sKey,sValue) { + sValue == undefined && ( sValue = ""); + return this._applet.getProperty(sKey,sValue); + } + + + Jmol._Applet.prototype._evaluate = function(molecularMath) { + //carries out molecular math on a model + + var result = "" + this._getPropertyAsJavaObject("evaluate", molecularMath); + var s = result.replace(/\-*\d+/, ""); + if(s == "" && !isNaN(parseInt(result))) + return parseInt(result); + var s = result.replace(/\-*\d*\.\d*/, "") + if(s == "" && !isNaN(parseFloat(result))) + return parseFloat(result); + return result; + } + + + Jmol._Applet.prototype._saveOrientation = function(id) { + return this._savedOrientations[id] = this._getPropertyAsArray("orientationInfo","info").moveTo; + } + + + Jmol._Applet.prototype._restoreOrientation = function(id) { + var s = this._savedOrientations[id]; + if(!s || s == "") + return s = s.replace(/1\.0/, "0"); + return this._scriptWait(s); + } + + + Jmol._Applet.prototype._restoreOrientationDelayed = function(id,delay) { + arguments.length < 1 && ( delay = 1); + var s = this._savedOrientations[id]; + if(!s || s == "") + return s = s.replace(/1\.0/, delay); + return this._scriptWait(s); + } + + Jmol._Applet.prototype._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 : "")); + } + + function _setDomNodeSize(id, sz){ + var domNode = Jmol._document.getElementById(id); + domNode.style.width = sz[0]; + domNode.style.height = sz[1]; + } + + var sz = _getAppletSize(size, "px"); + console.log(sz) + _setDomNodeSize(this._id+"_appletinfotablediv",sz); + this._containerWidth = sz[0]; + this._containerHeight = sz[1]; + } + Jmol._Applet.prototype._loadFile = function(fileName, params){ this._showInfo(false); params || (params = ""); Modified: trunk/Jmol/appletweb/JmolCore.js =================================================================== --- trunk/Jmol/appletweb/JmolCore.js 2012-04-26 22:23:58 UTC (rev 17060) +++ trunk/Jmol/appletweb/JmolCore.js 2012-04-27 20:02:46 UTC (rev 17061) @@ -68,7 +68,12 @@ _restQueryXml: "<orgPdbQuery><queryType>org.pdb.query.simple.AdvancedKeywordQuery</queryType><description>Text Search</description><keywords>QUERY</keywords></orgPdbQuery>", _restReportUrl: "http://www.pdb.org/pdb/rest/customReport?pdbids=IDLIST&customReportColumns=structureId,structureTitle" }, - _getCanvas: function(){ /* only in JmolCD.js */ return null } + _getCanvas: function(){ /* only in JmolCD.js */ return null }, + _allowedJmolSize: [25, 2048, 300] // min, max, default (pixels) + /* By setting the Jmol.allowedJmolSize[] variable in the webpage + before calling Jmol.getApplet(), limits for applet size can be overriden. + 2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html) + */ } })(document); @@ -96,10 +101,10 @@ height += "px"; if (typeof width !== "string") width += "px"; - var s = (isHeader ? "<div id=\"ID_appletinfotablediv\" style=\"width:Wpx;height:Hpx\"><table><tr><td><div id=\"ID_appletdiv\" style=\"width:Wpx;height:Hpx\">" - : "</div></td></tr><tr><td><div id=\"ID_infotablediv\" style=\"width:Wpx;height:Hpx;display:none\">\ - <table><tr height=\"20\"><td style=\"background:yellow\"><span id=\"ID_infoheaderdiv\"></span></td><td width=\"10\"><a href=\"javascript:Jmol.showInfo(ID,false)\">[x]</a></td></tr>\ - <tr><td colspan=\"2\"><div id=\"ID_infodiv\" style=\"overflow:scroll;width:Wpx;height:" + (applet._height - 15) + "px\"></div></td></tr></table></div></td></tr></table></div>"); + var s = (isHeader ? "<div id=\"ID_appletinfotablediv\" style=\"width:Wpx;height:Hpx\"><div id=\"ID_appletdiv\" style=\"width:100%;height:100%\">" + : "</div><div id=\"ID_infotablediv\" style=\"width:100%;height:100%;display:none\">\ + <table height=\"100%\" width=\"100%\"><tr height=\"20\"><td style=\"background:yellow\"><span id=\"ID_infoheaderdiv\"></span></td><td width=\"10\"><a href=\"javascript:Jmol.showInfo(ID,false)\">[x]</a></td></tr>\ + <tr height=\"*\"><td colspan=\"2\"><div id=\"ID_infodiv\" style=\"overflow:scroll;width:100%;height:100%\"></div></td></tr></table></div></div>"); return s.replace(/Hpx/g, height).replace(/Wpx/g, width).replace(/ID/g, applet._id); } @@ -467,4 +472,42 @@ return e; } + Jmol._evalJSON = function(s,key){ + s = s + ""; + if(!s) + return []; + if(s.charAt(0) != "{") { + if(s.indexOf(" | ") >= 0) + s = s.replace(/\ \|\ /g, "\n"); + return s; + } + var A = jQuery.parseJSON(s); + if(!A) + return; + if(key && A[key]) + A = A[key]; + return A; + } + + Jmol._sortMessages = function(A){ + /* + * private function + */ + function _sortKey0(a,b){ + return (a[0]<b[0]?1:a[0]>b[0]?-1:0); + } + + if(!A || typeof (A) != "object") + return []; + var B = []; + for(var i = A.length - 1; i >= 0; i--) + for(var j = 0, jj= A[i].length; j < jj; j++) + B[B.length] = A[i][j]; + if(B.length == 0) + return; + B = B.sort(_sortKey0); + return B; + } + + })(Jmol); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |