+/*******************************************************************************
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ *******************************************************************************/
package jalview.javascript;\r
\r
import java.awt.Color;\r
+import java.util.ArrayList;\r
+\r
import jalview.api.AlignmentViewPanel;\r
import jalview.api.FeatureRenderer;\r
import jalview.api.SequenceRenderer;\r
import jalview.ext.jmol.JmolCommands;\r
import jalview.structure.StructureListener;\r
import jalview.structure.StructureMapping;\r
+import jalview.structure.StructureMappingcommandSet;\r
import jalview.structure.StructureSelectionManager;\r
\r
+/**\r
+ * Propagate events involving PDB structures associated with sequences to a\r
+ * javascript function. Generally, the javascript handler is called with a\r
+ * series of arguments like (eventname, ... ). As of Jalview 2.7, the following\r
+ * different types of events are supported:\r
+ * <ul>\r
+ * <li>mouseover: javascript function called with arguments <pre>\r
+ * ['mouseover',String(pdb file URI), String(pdb file chain ID), String(residue\r
+ * number moused over), String(atom index corresponding to residue)]</pre></li>\r
+ * <li>colourstruct: javascript function called with arguments <pre>\r
+ * ['colourstruct',String(alignment view id),String(number of javascript message\r
+ * chunks to collect),String(length of first chunk in set of messages - or zero\r
+ * for null message)]</pre><br>\r
+ * The message contains a series of Jmol script commands that will colour\r
+ * structures according to their associated sequences in the current view. Use\r
+ * jalview\r
+ * .javascript.JalviewLiteJsApi.getJsMessage('colourstruct',String(alignment\r
+ * view id)) to retrieve successive chunks of the message.</li>\r
+ * </ul>\r
+ * \r
+ * @author Jim Procter (jprocter)\r
+ * \r
+ */\r
public class MouseOverStructureListener extends JSFunctionExec implements\r
JsCallBack, StructureListener\r
{\r
}\r
;\r
\r
- // Form a colour command for the given alignment panel\r
- final String[] colcommands = JmolCommands.getColourBySequenceCommand(\r
+ \r
+ // Form a colour command from the given alignment panel for each distinct structure \r
+ ArrayList<String[]> ccomands=new ArrayList<String[]>();\r
+ ArrayList<String> pdbfn=new ArrayList<String>();\r
+ StructureMappingcommandSet[] colcommands=JmolCommands.getColourBySequenceCommand(\r
ssm, modelSet, sequence, sr, fr,\r
((AlignmentViewPanel) source).getAlignment());\r
- if (colcommands==null)\r
- {\r
- // \r
+ if (colcommands==null) {\r
return;\r
}\r
+ int sz=0;\r
+ for (jalview.structure.StructureMappingcommandSet ccset: colcommands) {\r
+ sz+=ccset.commands.length;\r
+ ccomands.add(ccset.commands);\r
+ pdbfn.add(ccset.mapping);\r
+ }\r
+ \r
String mclass,mhandle;\r
+ String ccomandset[] = new String[sz];\r
+ sz=0;\r
+ for (String[] ccset: ccomands) {\r
+ System.arraycopy(ccset, 0, ccomandset, sz, ccset.length);\r
+ sz+=ccset.length;\r
+ }\r
if (jvlite.isJsMessageSetChanged(mclass="colourstruct",mhandle=((jalview.appletgui.AlignmentPanel) source).av\r
- .getViewId(), colcommands)) {\r
- jvlite.setJsMessageSet(mclass, mhandle , colcommands);\r
+ .getViewId(), ccomandset)) {\r
+ jvlite.setJsMessageSet(mclass, mhandle , ccomandset);\r
// and notify javascript handler\r
String st[] = new String[]\r
{\r
"colourstruct",\r
""\r
+ ((jalview.appletgui.AlignmentPanel) source).av\r
- .getViewId(), ""+colcommands.length, ""+(colcommands[0]!=null ? colcommands[0].length() : 0)};\r
+ .getViewId(), ""+ccomandset.length, jvlite.arrayToSeparatorList(pdbfn.toArray(new String[pdbfn.size()]))\r
+ };\r
try\r
{\r
executeJavascriptFunction(\r
{\r
System.err.println("Couldn't execute callback with "\r
+ _listenerfn + " using args { " + st[0] + ", "\r
- + st[1] + ", " + st[2] + "," + st[3] + "\n");\r
+ + st[1] + ", " + st[2] + "," + st[3]+"}"); // + ","+st[4]+"\n");\r
ex.printStackTrace();\r
\r
}\r