+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
+ */
+ public void loadAnnotation(String annotation)
+ {
+ loadAnnotationFrom(getDefaultTargetFrame(), annotation);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ public void loadAnnotationFrom(AlignFrame alf, String annotation)
+ {
+ if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(),
+ annotation, AppletFormatAdapter.PASTE))
+ {
+ alf.alignPanel.fontChanged();
+ alf.alignPanel.setScrollValues(0, 0);
+ }
+ else
+ {
+ alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)
+ */
+ public void loadFeatures(String features, boolean autoenabledisplay)
+ {
+ loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ public boolean loadFeaturesFrom(AlignFrame alf, String features,
+ boolean autoenabledisplay)
+ {
+ return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE,
+ autoenabledisplay);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)
+ */
+ public String getFeatures(String format)
+ {
+ return getFeaturesFrom(getDefaultTargetFrame(), format);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getFeaturesFrom(jalview.appletgui.AlignFrame,
+ * java.lang.String)
+ */
+ public String getFeaturesFrom(AlignFrame alf, String format)
+ {
+ return alf.outputFeatures(false, format);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#getAnnotation()
+ */
+ public String getAnnotation()
+ {
+ return getAnnotationFrom(getDefaultTargetFrame());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getAnnotationFrom(jalview.appletgui.AlignFrame
+ * )
+ */
+ public String getAnnotationFrom(AlignFrame alf)
+ {
+ return alf.outputAnnotations(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#newView()
+ */
+ public AlignFrame newView()
+ {
+ return newViewFrom(getDefaultTargetFrame());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#newView(java.lang.String)
+ */
+ public AlignFrame newView(String name)
+ {
+ return newViewFrom(getDefaultTargetFrame(), name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame)
+ */
+ public AlignFrame newViewFrom(AlignFrame alf)
+ {
+ return alf.newView(null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame,
+ * java.lang.String)
+ */
+ public AlignFrame newViewFrom(AlignFrame alf, String name)
+ {
+ return alf.newView(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#loadAlignment(java.lang.String,
+ * java.lang.String)
+ */
+ public AlignFrame loadAlignment(String text, String title)
+ {
+ Alignment al = null;
+
+ String format = new IdentifyFile().Identify(text,
+ AppletFormatAdapter.PASTE);
+ try
+ {
+ al = new AppletFormatAdapter().readFile(text,
+ AppletFormatAdapter.PASTE, format);
+ if (al.getHeight() > 0)
+ {
+ return new AlignFrame(al, this, title, false);
+ }
+ } catch (java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#setMouseoverListener(java.lang.String)
+ */
+ 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)
+ */
+ 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)
+ */
+ public void setSelectionListener(String listener)
+ {
+ setSelectionListener(null, listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#setSelectionListener(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ 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.");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
+ * java.lang.String)
+ */
+ 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;
+ }
+ }
+ jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.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)
+ */
+ 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.");
+ }
+ }
+
+ public void stop()
+ {
+ System.err.println("Applet " + getName() + " stop().");
+ tidyUp();
+ }
+
+ 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)
+ */
+ 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)
+ */
+ 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();
+ }
+ }
+ });
+
+ }
+
+ // //////////////////////////////////////////////
+ // //////////////////////////////////////////////
+
+ public static int lastFrameX = 200;
+
+ public static int lastFrameY = 200;
+
+ boolean fileFound = true;
+
+ String file = "No file";
+
+ Button launcher = new Button("Start Jalview");
+
+ /**
+ * The currentAlignFrame is static, it will change if and when the user
+ * selects a new window. Note that it will *never* point back to the embedded
+ * AlignFrame if the applet is started as embedded on the page and then
+ * afterwards a new view is created.
+ */
+ public AlignFrame currentAlignFrame = null;
+
+ /**
+ * This is the first frame to be displayed, and does not change. API calls
+ * will default to this instance if currentAlignFrame is null.
+ */
+ AlignFrame initialAlignFrame = null;
+
+ boolean embedded = false;
+
+ private boolean checkForJmol = true;
+
+ private boolean checkedForJmol = false; // ensure we don't check for jmol
+
+ // every time the app is re-inited
+
+ public boolean jmolAvailable = false;
+
+ private boolean alignPdbStructures = false;
+
+ /**
+ * use an external structure viewer exclusively (no jmols or MCViews will be
+ * opened by JalviewLite itself)
+ */
+ public boolean useXtrnalSviewer = false;
+
+ public static boolean debug = false;
+
+ static String builddate = null, version = null, installation = null;
+
+ private static void initBuildDetails()
+ {
+ if (builddate == null)