+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
+ */
+ @Override
+ public void setMouseoverListener(String listener)
+ {
+ setMouseoverListener(currentAlignFrame, listener);
+ }
+
+ private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#setMouseoverListener(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ @Override
+ public void setMouseoverListener(AlignFrame af, String listener)
+ {
+ if (listener != null)
+ {
+ listener = listener.trim();
+ if (listener.length() == 0)
+ {
+ System.err
+ .println("jalview Javascript error: Ignoring empty function for mouseover listener.");
+ return;
+ }
+ }
+ jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(
+ this, af, listener);
+ javascriptListeners.addElement(mol);
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .addStructureViewerListener(mol);
+ if (debug)
+ {
+ System.err.println("Added a mouseover listener for "
+ + ((af == null) ? "All frames" : "Just views for "
+ + af.getAlignViewport().getSequenceSetId()));
+ System.err.println("There are now " + javascriptListeners.size()
+ + " listeners in total.");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#setSelectionListener(java.lang.String)
+ */
+ @Override
+ public void setSelectionListener(String listener)
+ {
+ setSelectionListener(null, listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ @Override
+ public void setSelectionListener(AlignFrame af, String listener)
+ {
+ if (listener != null)
+ {
+ listener = listener.trim();
+ if (listener.length() == 0)
+ {
+ System.err
+ .println("jalview Javascript error: Ignoring empty function for selection listener.");
+ return;
+ }
+ }
+ jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(
+ this, af, listener);
+ javascriptListeners.addElement(mol);
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .addSelectionListener(mol);
+ if (debug)
+ {
+ System.err.println("Added a selection listener for "
+ + ((af == null) ? "All frames" : "Just views for "
+ + af.getAlignViewport().getSequenceSetId()));
+ System.err.println("There are now " + javascriptListeners.size()
+ + " listeners in total.");
+ }
+ }
+
+ /**
+ * Callable from javascript to register a javascript function to pass events
+ * to a structure viewer.
+ *
+ * @param listener
+ * the name of a javascript function
+ * @param modelSet
+ * a token separated list of PDB file names listened for
+ * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public void setStructureListener(String listener, String modelSet)
+ {
+ if (listener != null)
+ {
+ listener = listener.trim();
+ if (listener.length() == 0)
+ {
+ System.err
+ .println("jalview Javascript error: Ignoring empty function for selection listener.");
+ return;
+ }
+ }
+ MouseOverStructureListener mol = new MouseOverStructureListener(this,
+ listener, separatorListToArray(modelSet));
+ javascriptListeners.addElement(mol);
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .addStructureViewerListener(mol);
+ if (debug)
+ {
+ System.err.println("Added a javascript structure viewer listener '"
+ + listener + "'");
+ System.err.println("There are now " + javascriptListeners.size()
+ + " listeners in total.");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#removeJavascriptListener(jalview.appletgui
+ * .AlignFrame, java.lang.String)
+ */
+ @Override
+ public void removeJavascriptListener(AlignFrame af, String listener)
+ {
+ if (listener != null)
+ {
+ listener = listener.trim();
+ if (listener.length() == 0)
+ {
+ listener = null;
+ }
+ }
+ boolean rprt = false;
+ for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;)
+ {
+ Object lstn = javascriptListeners.elementAt(ms);
+ JsCallBack lstner = (JsCallBack) lstn;
+ if ((af == null || lstner.getAlignFrame() == af)
+ && (listener == null || lstner.getListenerFunction().equals(
+ listener)))
+ {
+ javascriptListeners.removeElement(lstner);
+ msSize--;
+ if (lstner instanceof SelectionListener)
+ {
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .removeSelectionListener((SelectionListener) lstner);
+ }
+ else
+ {
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .removeStructureViewerListener(lstner, null);
+ }
+ rprt = debug;
+ if (debug)
+ {
+ System.err.println("Removed listener '" + listener + "'");
+ }
+ }
+ else
+ {
+ ms++;
+ }
+ }
+ if (rprt)
+ {
+ System.err.println("There are now " + javascriptListeners.size()
+ + " listeners in total.");
+ }
+ }
+
+ @Override
+ public void stop()
+ {
+ System.err.println("Applet " + getName() + " stop().");
+ tidyUp();
+ }
+
+ @Override
+ public void destroy()
+ {
+ System.err.println("Applet " + getName() + " destroy().");
+ tidyUp();
+ }
+
+ private void tidyUp()
+ {
+ removeAll();
+ if (currentAlignFrame != null && currentAlignFrame.viewport != null
+ && currentAlignFrame.viewport.applet != null)
+ {
+ AlignViewport av = currentAlignFrame.viewport;
+ currentAlignFrame.closeMenuItem_actionPerformed();
+ av.applet = null;
+ currentAlignFrame = null;
+ }
+ if (javascriptListeners != null)
+ {
+ while (javascriptListeners.size() > 0)
+ {
+ jalview.javascript.JSFunctionExec mol = javascriptListeners
+ .elementAt(0);
+ javascriptListeners.removeElement(mol);
+ if (mol instanceof SelectionListener)
+ {
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .removeSelectionListener((SelectionListener) mol);
+ }
+ else
+ {
+ StructureSelectionManager.getStructureSelectionManager(this)
+ .removeStructureViewerListener(mol, null);
+ }
+ mol.jvlite = null;
+ }
+ }
+ if (jsFunctionExec != null)
+ {
+ jsFunctionExec.stopQueue();
+ jsFunctionExec.jvlite = null;
+ }
+ initialAlignFrame = null;
+ jsFunctionExec = null;
+ javascriptListeners = null;
+ StructureSelectionManager.release(this);
+ }
+
+ private jalview.javascript.JSFunctionExec jsFunctionExec;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#mouseOverStructure(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public void mouseOverStructure(final String pdbResNum,
+ final String chain, final String pdbfile)
+ {
+ final StructureSelectionManagerProvider me = this;
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ StructureSelectionManager.getStructureSelectionManager(me)
+ .mouseOverStructure(new Integer(pdbResNum).intValue(),
+ chain, pdbfile);
+ if (debug)
+ {
+ System.err.println("mouseOver for '" + pdbResNum
+ + "' in chain '" + chain + "' in structure '" + pdbfile
+ + "'");
+ }
+ } catch (NumberFormatException e)
+ {
+ System.err.println("Ignoring invalid residue number string '"
+ + pdbResNum + "'");
+ }
+
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#scrollViewToIn(jalview.appletgui.AlignFrame,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public void scrollViewToIn(final AlignFrame alf, final String topRow,
+ final String leftHandColumn)
+ {
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ alf.scrollTo(new Integer(topRow).intValue(), new Integer(
+ leftHandColumn).intValue());
+
+ } catch (Exception ex)
+ {
+ System.err.println("Couldn't parse integer arguments (topRow='"
+ + topRow + "' and leftHandColumn='" + leftHandColumn
+ + "')");
+ ex.printStackTrace();
+ }
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.javascript.JalviewLiteJsApi#scrollViewToRowIn(jalview.appletgui
+ * .AlignFrame, java.lang.String)
+ */
+ @Override
+ public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
+ {
+
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ alf.scrollToRow(new Integer(topRow).intValue());
+
+ } catch (Exception ex)
+ {
+ System.err.println("Couldn't parse integer arguments (topRow='"
+ + topRow + "')");
+ ex.printStackTrace();
+ }
+
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.javascript.JalviewLiteJsApi#scrollViewToColumnIn(jalview.appletgui
+ * .AlignFrame, java.lang.String)
+ */
+ @Override
+ public void scrollViewToColumnIn(final AlignFrame alf,
+ final String leftHandColumn)
+ {
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ alf.scrollToColumn(new Integer(leftHandColumn).intValue());
+
+ } catch (Exception ex)
+ {
+ System.err
+ .println("Couldn't parse integer arguments (leftHandColumn='"
+ + leftHandColumn + "')");
+ ex.printStackTrace();
+ }
+ }
+ });
+
+ }
+