Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / javascript / MouseOverStructureListener.js
1 Clazz.declarePackage ("jalview.javascript");
2 Clazz.load (["jalview.javascript.JSFunctionExec", "$.JsCallBack", "jalview.structure.StructureListener"], "jalview.javascript.MouseOverStructureListener", ["jalview.api.AlignmentViewPanel", "jalview.appletgui.FeatureRenderer", "jalview.ext.jmol.JmolCommands", "jalview.structure.StructureSelectionManager", "java.net.URL", "java.util.ArrayList"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this._listenerfn = null;
5 this.modelSet = null;
6 Clazz.instantialize (this, arguments);
7 }, jalview.javascript, "MouseOverStructureListener", jalview.javascript.JSFunctionExec, [jalview.javascript.JsCallBack, jalview.structure.StructureListener]);
8 Clazz.makeConstructor (c$, 
9 function (jalviewLite, listener, modelList) {
10 Clazz.superConstructor (this, jalview.javascript.MouseOverStructureListener, [jalviewLite]);
11 this._listenerfn = listener;
12 this.modelSet = modelList;
13 if (this.modelSet != null) {
14 for (var i = 0; i < this.modelSet.length; i++) {
15 try {
16 if ( new java.net.URL (this.modelSet[i]).openConnection () != null) {
17 continue;
18 }} catch (x) {
19 if (Clazz.exceptionOf (x, Exception)) {
20 } else {
21 throw x;
22 }
23 }
24 ;try {
25 var db = this.jvlite.getDocumentBase ().toString ();
26 db = db.substring (0, db.lastIndexOf ("/"));
27 if ( new java.net.URL (db + "/" + this.modelSet[i]).openConnection () != null) {
28 this.modelSet[i] = db + "/" + this.modelSet[i];
29 continue;
30 }} catch (x) {
31 if (Clazz.exceptionOf (x, Exception)) {
32 } else {
33 throw x;
34 }
35 }
36 ;try {
37 if ( new java.net.URL (this.jvlite.getCodeBase () + this.modelSet[i]).openConnection () != null) {
38 this.modelSet[i] = this.jvlite.getCodeBase () + this.modelSet[i];
39 continue;
40 }} catch (x) {
41 if (Clazz.exceptionOf (x, Exception)) {
42 } else {
43 throw x;
44 }
45 }
46 ;}
47 }}, "jalview.bin.JalviewLite,~S,~A");
48 Clazz.overrideMethod (c$, "getPdbFile", 
49 function () {
50 return this.modelSet;
51 });
52 Clazz.defineMethod (c$, "mouseOverStructure", 
53 function (atomIndex, strInfo) {
54 }, "~N,~S");
55 Clazz.overrideMethod (c$, "highlightAtoms", 
56 function (atoms) {
57 for (var atom, $atom = atoms.iterator (); $atom.hasNext () && ((atom = $atom.next ()) || true);) {
58 try {
59 this.executeJavascriptFunction (this._listenerfn,  Clazz.newArray (-1, ["mouseover", "" + atom.getPdbFile (), "" + atom.getChain (), "" + (atom.getPdbResNum ()), "" + atom.getAtomIndex ()]));
60 } catch (ex) {
61 if (Clazz.exceptionOf (ex, Exception)) {
62 System.err.println ("Couldn't execute callback with " + this._listenerfn + " for atomSpec: " + atom);
63 ex.printStackTrace ();
64 } else {
65 throw ex;
66 }
67 }
68 }
69 }, "java.util.List");
70 Clazz.overrideMethod (c$, "updateColours", 
71 function (srce) {
72 var source = srce;
73 var ssm = jalview.structure.StructureSelectionManager.getStructureSelectionManager (this.jvlite);
74 if (Clazz.instanceOf (source, jalview.api.AlignmentViewPanel)) {
75 var sequence =  new Array (this.modelSet.length);
76 for (var m = 0; m < this.modelSet.length; m++) {
77 var sm = ssm.getMapping (this.modelSet[m]);
78 if (sm != null && sm.length > 0) {
79 sequence[m] =  new Array (sm.length);
80 for (var i = 0; i < sm.length; i++) {
81 sequence[m][i] = sm[i].getSequence ();
82 }
83 } else {
84 sequence[m] =  new Array (0);
85 }}
86 var sr = (source).getSequenceRenderer ();
87 var fr = (source).av.isShowSequenceFeatures () ?  new jalview.appletgui.FeatureRenderer ((source).av) : null;
88 if (fr != null) {
89 (fr).transferSettings ((source).getFeatureRenderer ());
90 };var ccomands =  new java.util.ArrayList ();
91 var pdbfn =  new java.util.ArrayList ();
92 var colcommands = jalview.ext.jmol.JmolCommands.getColourBySequenceCommand (ssm, this.modelSet, sequence, sr, fr, (source).getAlignment ());
93 if (colcommands == null) {
94 return;
95 }var sz = 0;
96 for (var ccset, $ccset = 0, $$ccset = colcommands; $ccset < $$ccset.length && ((ccset = $$ccset[$ccset]) || true); $ccset++) {
97 sz += ccset.commands.length;
98 ccomands.add (ccset.commands);
99 pdbfn.add (ccset.mapping);
100 }
101 var mclass;
102 var mhandle;
103 var ccomandset =  new Array (sz);
104 sz = 0;
105 for (var ccset, $ccset = ccomands.iterator (); $ccset.hasNext () && ((ccset = $ccset.next ()) || true);) {
106 System.arraycopy (ccset, 0, ccomandset, sz, ccset.length);
107 sz += ccset.length;
108 }
109 if (this.jvlite.isJsMessageSetChanged (mclass = "colourstruct", mhandle = (source).av.getViewId (), ccomandset)) {
110 this.jvlite.setJsMessageSet (mclass, mhandle, ccomandset);
111 var st =  Clazz.newArray (-1, ["colourstruct", "" + (source).av.getViewId (), "" + ccomandset.length, this.jvlite.arrayToSeparatorList (pdbfn.toArray ( new Array (pdbfn.size ())))]);
112 try {
113 this.executeJavascriptFunction (true, this._listenerfn, st);
114 } catch (ex) {
115 if (Clazz.exceptionOf (ex, Exception)) {
116 System.err.println ("Couldn't execute callback with " + this._listenerfn + " using args { " + st[0] + ", " + st[1] + ", " + st[2] + "," + st[3] + "}");
117 ex.printStackTrace ();
118 } else {
119 throw ex;
120 }
121 }
122 }}}, "~O");
123 Clazz.overrideMethod (c$, "getAlignFrame", 
124 function () {
125 return null;
126 });
127 Clazz.overrideMethod (c$, "getListenerFunction", 
128 function () {
129 return this._listenerfn;
130 });
131 Clazz.defineMethod (c$, "finalise", 
132 function () {
133 this.jvlite = null;
134 Clazz.superCall (this, jalview.javascript.MouseOverStructureListener, "finalize", []);
135 });
136 Clazz.overrideMethod (c$, "releaseReferences", 
137 function (svl) {
138 }, "~O");
139 Clazz.overrideMethod (c$, "isListeningFor", 
140 function (seq) {
141 return true;
142 }, "jalview.datamodel.SequenceI");
143 });