From: Bob H. <ha...@st...> - 2006-02-13 23:25:38
|
JavaScript/Java/JSON/Jmol Funny how those all begin with J.... :) It appears I've underestimated the capabilities of JavaScript. It turns out JSON is irrelevant in this case. Rack it up to learning, I guess. I never would have imagined that the following command would work from a browser: var atomSet = document.getElementById("jmolAppletX") .getProperty("atomInfo","atomno<5") alert(atomSet.get(0).get("info"))) The first of those, .getElementById, is JavaScript. the rest are java methods. It appears that getProperty is returning an object to JavaScript essentially just like it would to any other java component. AND, what's more, the object returned, "atomSet" in this case really is still a Java object. Heck, it's just a pointer -- there's no conversion!!! The class returned is Java "Object" or JavaScript "object", which in this case operates as a Vector, for which .get(0) gets the first member. That Vector entry is a Hashtable, for which get("info") gets the value. return: "[THR]1.N #1" Useful, eh? Similarly: document.getElementById('jmolAppletX') .getProperty('orientationInfo').get('moveTo') returns "moveto 1 -400 345 332 34 0" The common "J", of course, is for "Java". I decided just for fun to see what the methods of that getProperty() return object were -- and to my astonishment discovered all the methods of a Vector. So, what the heck, the JSON idea allows conversion to actual JavaScript objects, but even without JSON, all the properties of the actual Java classes returned by getProperty() can be investigated. You just have to treat them as Java objects and use java methods. We'll have to see if this is a generally robust finding. This sure blurs the distinction between JavaScript and Java.... Bob Hanson -- Robert M. Hanson, ha...@st..., 507-646-3107 Professor of Chemistry, St. Olaf College 1520 St. Olaf Ave., Northfield, MN 55057 mailto:ha...@st... http://www.stolaf.edu/people/hansonr "Imagination is more important than knowledge." - Albert Einstein |