+ final Object source = srce;
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(jvlite);
+ // if (jvlite.debug)
+ // {
+ // ssm.reportMapping();
+ // }
+ if (source instanceof jalview.api.AlignmentViewPanel)
+ {
+ SequenceI[][] sequence = new SequenceI[modelSet.length][];
+ for (int m = 0; m < modelSet.length; m++)
+ {
+ StructureMapping[] sm = ssm.getMapping(modelSet[m]);
+ if (sm != null && sm.length > 0)
+ {
+ sequence[m] = new SequenceI[sm.length];
+ for (int i = 0; i < sm.length; i++)
+ {
+ sequence[m][i] = sm[i].getSequence();
+ }
+ }
+ else
+ {
+ sequence[m] = new SequenceI[0];
+ }
+ // if (jvlite.debug)
+ // {
+ // System.err.println("Mapped '" + modelSet[m] + "' to "
+ // + sequence[m].length + " sequences.");
+ // }
+ }
+
+ SequenceRenderer sr = ((jalview.appletgui.AlignmentPanel) source)
+ .getSequenceRenderer();
+ FeatureRenderer fr = ((jalview.appletgui.AlignmentPanel) source).av
+ .isShowSequenceFeatures() ? new jalview.appletgui.FeatureRenderer(
+ ((jalview.appletgui.AlignmentPanel) source).av) : null;
+ if (fr != null)
+ {
+ ((jalview.appletgui.FeatureRenderer) fr)
+ .transferSettings(((jalview.appletgui.AlignmentPanel) source)
+ .getFeatureRenderer());
+ }
+ ;
+
+ // Form a colour command from the given alignment panel for each distinct
+ // structure
+ ArrayList<String[]> ccomands = new ArrayList<String[]>();
+ ArrayList<String> pdbfn = new ArrayList<String>();
+ StructureMappingcommandSet[] colcommands = JmolCommands
+ .getColourBySequenceCommand(ssm, modelSet, sequence, sr, fr,
+ ((AlignmentViewPanel) source).getAlignment());
+ if (colcommands == null)
+ {
+ return;
+ }
+ int sz = 0;
+ for (jalview.structure.StructureMappingcommandSet ccset : colcommands)
+ {
+ sz += ccset.commands.length;
+ ccomands.add(ccset.commands);
+ pdbfn.add(ccset.mapping);
+ }
+
+ String mclass, mhandle;
+ String ccomandset[] = new String[sz];
+ sz = 0;
+ for (String[] ccset : ccomands)
+ {
+ System.arraycopy(ccset, 0, ccomandset, sz, ccset.length);
+ sz += ccset.length;
+ }
+ if (jvlite.isJsMessageSetChanged(
+ mclass = "colourstruct",
+ mhandle = ((jalview.appletgui.AlignmentPanel) source).av
+ .getViewId(), ccomandset))
+ {
+ jvlite.setJsMessageSet(mclass, mhandle, ccomandset);
+ // and notify javascript handler
+ String st[] = new String[]
+ {
+ "colourstruct",
+ "" + ((jalview.appletgui.AlignmentPanel) source).av.getViewId(),
+ "" + ccomandset.length,
+ jvlite.arrayToSeparatorList(pdbfn.toArray(new String[pdbfn
+ .size()])) };
+ try
+ {
+ executeJavascriptFunction(true, _listenerfn, st);
+ } catch (Exception ex)
+ {
+ System.err.println("Couldn't execute callback with "
+ + _listenerfn + " using args { " + st[0] + ", " + st[1]
+ + ", " + st[2] + "," + st[3] + "}"); // + ","+st[4]+"\n");
+ ex.printStackTrace();
+
+ }
+ }
+ /*
+ * new Thread(new Runnable() { public void run() { // and send to
+ * javascript handler String st[] = new String[0]; int i = 0; for (String
+ * colcommand : colcommands) { // do sync execution for each chunk try {
+ * executeJavascriptFunction( false, _listenerfn, st = new String[] {
+ * "colourstruct", "" + ((jalview.appletgui.AlignmentPanel) source).av
+ * .getViewId(), handle, "" }); } catch (Exception ex) {
+ * System.err.println("Couldn't execute callback with " + _listenerfn +
+ * " using args { " + st[0] + ", " + st[1] + ", " + st[2] + "," + st[3] +
+ * "\n"); ex.printStackTrace();
+ *
+ * } } } }).start();
+ */
+ }