From: jprocter Date: Mon, 14 Feb 2011 10:46:29 +0000 (+0000) Subject: JAL-621 - also renamed list of javascript handlers X-Git-Tag: Release_2_7~263 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=af1471fa3d7d3cb32d203e81d394838608dd1c96;p=jalview.git JAL-621 - also renamed list of javascript handlers --- diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 7ae7007..1801eb1 100755 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -710,7 +710,7 @@ public class JalviewLite extends Applet setMouseoverListener(currentAlignFrame, listener); } - private Vector mouseoverListeners = new Vector(); + private Vector javascriptListeners = new Vector(); public void setMouseoverListener(AlignFrame af, String listener) { @@ -726,7 +726,7 @@ public class JalviewLite extends Applet } jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener( this, af, listener); - mouseoverListeners.addElement(mol); + javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager() .addStructureViewerListener(mol); if (debug) @@ -734,7 +734,7 @@ public class JalviewLite extends Applet System.err.println("Added a mouseover listener for " + ((af == null) ? "All frames" : "Just views for " + af.getAlignViewport().getSequenceSetId())); - System.err.println("There are now " + mouseoverListeners.size() + System.err.println("There are now " + javascriptListeners.size() + " listeners in total."); } } @@ -758,7 +758,7 @@ public class JalviewLite extends Applet } jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender( this, af, listener); - mouseoverListeners.addElement(mol); + javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager() .addSelectionListener(mol); if (debug) @@ -766,11 +766,34 @@ public class JalviewLite extends Applet System.err.println("Added a selection listener for " + ((af == null) ? "All frames" : "Just views for " + af.getAlignViewport().getSequenceSetId())); - System.err.println("There are now " + mouseoverListeners.size() + System.err.println("There are now " + javascriptListeners.size() + " listeners in total."); } } + public void setStructureListener(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.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(this, listener); + javascriptListeners.addElement(mol); + StructureSelectionManager.getStructureSelectionManager() + .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."); + } + } /** * remove any callback using the given listener function and associated with * the given alignFrame (or null for all callbacks) @@ -791,15 +814,15 @@ public class JalviewLite extends Applet } } boolean rprt = false; - for (int ms = 0, msSize = mouseoverListeners.size(); ms < msSize;) + for (int ms = 0, msSize = javascriptListeners.size(); ms < msSize;) { - Object lstn = mouseoverListeners.elementAt(ms); + Object lstn = javascriptListeners.elementAt(ms); JsCallBack lstner = (JsCallBack) lstn; if ((af == null || lstner.getAlignFrame() == af) && (listener == null || lstner.getListenerFunction().equals( listener))) { - mouseoverListeners.removeElement(lstner); + javascriptListeners.removeElement(lstner); msSize--; if (lstner instanceof SelectionListener) { @@ -824,19 +847,19 @@ public class JalviewLite extends Applet } if (rprt) { - System.err.println("There are now " + mouseoverListeners.size() + System.err.println("There are now " + javascriptListeners.size() + " listeners in total."); } } public void stop() { - if (mouseoverListeners != null) + if (javascriptListeners != null) { - while (mouseoverListeners.size() > 0) + while (javascriptListeners.size() > 0) { - Object mol = mouseoverListeners.elementAt(0); - mouseoverListeners.removeElement(mol); + Object mol = javascriptListeners.elementAt(0); + javascriptListeners.removeElement(mol); if (mol instanceof SelectionListener) { StructureSelectionManager.getStructureSelectionManager() @@ -860,10 +883,19 @@ public class JalviewLite extends Applet * @param chain * @param pdbfile */ - public void mouseOverStructure(int pdbResNum, String chain, String pdbfile) + public void mouseOverStructure(String pdbResNum, String chain, String pdbfile) { + try { StructureSelectionManager.getStructureSelectionManager() - .mouseOverStructure(pdbResNum, chain, pdbfile); + .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+"'"); + } } // ////////////////////////////////////////////// @@ -905,6 +937,11 @@ public class JalviewLite extends Applet 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; @@ -1000,6 +1037,11 @@ public class JalviewLite extends Applet System.err.println("Build Date : " + getBuildDate()); } + String externalsviewer = getParameter("externalstructureviewer"); + if (externalsviewer!=null) + { + useXtrnalSviewer=externalsviewer.trim().toLowerCase().equals("true"); + } /** * if true disable the check for jmol */ @@ -1578,6 +1620,10 @@ public class JalviewLite extends Applet // Accumulate pdbs here if they are heading for the same view (if // alignPdbStructures is true) Vector pdbs = new Vector(); + // create a lazy matcher if we're asked to + jalview.analysis.SequenceIdMatcher matcher = (applet.getDefaultParameter("relaxedidmatch", false)) ? new jalview.analysis.SequenceIdMatcher( + newAlignFrame.getAlignViewport().getAlignment().getSequencesArray()) : null; + do { if (pdbFileCount > 0) @@ -1600,8 +1646,8 @@ public class JalviewLite extends Applet String sequence = applet.getParameter("PDBSEQ"); if (sequence != null) seqs = new SequenceI[] - { (Sequence) newAlignFrame.getAlignViewport() - .getAlignment().findName(sequence) }; + { matcher==null ? (Sequence) newAlignFrame.getAlignViewport() + .getAlignment().findName(sequence) : matcher.findIdMatch(sequence) }; } else @@ -1620,8 +1666,8 @@ public class JalviewLite extends Applet tmp2.addElement(st2.nextToken()); seqstring = st2.nextToken(); } - tmp.addElement((Sequence) newAlignFrame.getAlignViewport() - .getAlignment().findName(seqstring)); + tmp.addElement(matcher==null ? (Sequence) newAlignFrame.getAlignViewport() + .getAlignment().findName(seqstring) : matcher.findIdMatch(seqstring)); } seqs = new SequenceI[tmp.size()]; diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java new file mode 100644 index 0000000..4cdf123 --- /dev/null +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -0,0 +1,80 @@ +package jalview.javascript; + +import java.awt.Color; + +import jalview.appletgui.AlignFrame; +import jalview.bin.JalviewLite; +import jalview.structure.StructureListener; +import jalview.structure.StructureSelectionManager; + +public class MouseOverStructureListener extends JSFunctionExec implements + JsCallBack, StructureListener +{ + + String _listenerfn; + public MouseOverStructureListener(JalviewLite applet, String listenerCb) + { + super(applet); + _listenerfn = listenerCb; + + } + @Override + public String[] getPdbFile() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void mouseOverStructure(int atomIndex, String strInfo) + { + + // StructureSelectionManager.getStructureSelectionManager().mouseOverStructure(atomIndex, chain, pdbfile) + // TODO Auto-generated method stub + + } + + @Override + public void highlightAtom(int atomIndex, int pdbResNum, String chain, + String pdbId) + { + String[] st=new String[0]; + try { + executeJavascriptFunction(_listenerfn, st = new String[] { "mouseover",""+pdbId, ""+chain, ""+(pdbResNum), ""+atomIndex}); + } 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(); + + } + + } + + @Override + public void updateColours(Object source) + { + // TODO Auto-generated method stub + + } + + @Override + public Color getColour(int atomIndex, int pdbResNum, String chain, + String pdbId) + { + return null; + } + + @Override + public AlignFrame getAlignFrame() + { + // associated with all alignframes, always. + return null; + } + + @Override + public String getListenerFunction() + { + return _listenerfn; + } + +}