From 794501173d6cea5fc3a965cee3792ae78304abe9 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 20 Aug 2010 11:54:04 +0000 Subject: [PATCH] extend jmol binding handles selection events and add in a 'refreshPdbEntries' step so the list of PDB entries jalview knows about can be updated before a Jmol notifyUpdate event is handled --- src/jalview/appletgui/AppletJmolBinding.java | 16 ++- src/jalview/ext/jmol/JalviewJmolBinding.java | 173 +++++++++++++++----------- src/jalview/gui/AppJmolBinding.java | 13 ++ 3 files changed, 129 insertions(+), 73 deletions(-) diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 4c29e05..89d053b 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -3,6 +3,8 @@ */ package jalview.appletgui; +import java.util.BitSet; + import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; @@ -12,7 +14,7 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding { /** - * + * Window that contains the bound Jmol instance */ private AppletJmol appletJmolBinding; @@ -99,4 +101,16 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding // do nothing. } + public void selectionChanged(BitSet arg0) + { + // TODO Auto-generated method stub + + } + + public void refreshPdbEntries() + { + // TODO Auto-generated method stub + + } + } \ No newline at end of file diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index af83e48..929411f 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -39,7 +39,7 @@ import org.jmol.viewer.JmolConstants; import jalview.schemes.*; public abstract class JalviewJmolBinding implements StructureListener, - JmolStatusListener, SequenceStructureBinding + JmolStatusListener, SequenceStructureBinding, JmolSelectionListener { /** @@ -48,11 +48,12 @@ public abstract class JalviewJmolBinding implements StructureListener, * time. */ private boolean loadingFromArchive = false; + /** * state flag used to check if the Jmol viewer's paint method can be called */ - private boolean finishedInit=false; - + private boolean finishedInit = false; + public boolean isFinishedInit() { return finishedInit; @@ -134,14 +135,25 @@ public abstract class JalviewJmolBinding implements StructureListener, */ } + public JalviewJmolBinding(JmolViewer viewer2) + { + viewer = viewer2; + viewer.setJmolStatusListener(this); + viewer.addSelectionListener(this); + } + /** - * construct a title string for the viewer window based on the data jalview knows about - * @return + * construct a title string for the viewer window based on the data jalview + * knows about + * + * @return */ - public String getViewerTitle() { - if (sequence==null || pdbentry==null || sequence.length<1 || pdbentry.length<1) + public String getViewerTitle() + { + if (sequence == null || pdbentry == null || sequence.length < 1 + || pdbentry.length < 1) { - return("Jalview Jmol Window"); + return ("Jalview Jmol Window"); } StringBuffer title = new StringBuffer(sequence[0].getName() + ":" + pdbentry[0].getId()); @@ -188,8 +200,7 @@ public abstract class JalviewJmolBinding implements StructureListener, } if (cmd.length() > 0) cmd.setLength(cmd.length() - 4); - evalStateCommand("select *;restrict " + cmd + ";cartoon;center " - + cmd); + evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd); } public void closeViewer() @@ -201,7 +212,7 @@ public abstract class JalviewJmolBinding implements StructureListener, // and shut down jmol viewer.evalStringQuiet("zap"); viewer.setJmolStatusListener(null); - lastCommand=null; + lastCommand = null; viewer = null; } @@ -294,15 +305,17 @@ public abstract class JalviewJmolBinding implements StructureListener, evalStateCommand(command.toString()); } - public void evalStateCommand(String command) { + public void evalStateCommand(String command) + { jmolHistory(false); if (lastCommand == null || !lastCommand.equals(command)) { - viewer.evalStringQuiet(command+"\n"); + viewer.evalStringQuiet(command + "\n"); } jmolHistory(true); lastCommand = command; } + /** * colour any structures associated with sequences in the given alignment * using the getFeatureRenderer() and getSequenceRenderer() renderers but only @@ -312,7 +325,7 @@ public abstract class JalviewJmolBinding implements StructureListener, { if (!colourBySequence) return; - if (ssm==null) + if (ssm == null) { return; } @@ -404,8 +417,8 @@ public abstract class JalviewJmolBinding implements StructureListener, StringBuffer condenseCommand(String command, int pos) { - StringBuffer sb = new StringBuffer(command.substring(0, command - .lastIndexOf("select") + 7)); + StringBuffer sb = new StringBuffer(command.substring(0, + command.lastIndexOf("select") + 7)); command = command.substring(sb.length()); @@ -475,6 +488,13 @@ public abstract class JalviewJmolBinding implements StructureListener, */ public abstract FeatureRenderer getFeatureRenderer(); + /** + * instruct the Jalview binding to update the pdbentries vector if necessary + * prior to matching the jmol view's contents to the list of structure files + * Jalview knows about. + */ + public abstract void refreshPdbEntries(); + private int getModelNum(String modelFileName) { String[] mfn = getPdbFile(); @@ -623,8 +643,8 @@ public abstract class JalviewJmolBinding implements StructureListener, String chainId; if (strInfo.indexOf(":") > -1) - chainId = strInfo.substring(strInfo.indexOf(":") + 1, strInfo - .indexOf(".")); + chainId = strInfo.substring(strInfo.indexOf(":") + 1, + strInfo.indexOf(".")); else { chainId = " "; @@ -660,7 +680,8 @@ public abstract class JalviewJmolBinding implements StructureListener, { if (data != null) { - System.err.println("Ignoring additional hover info: " + data+ " (other info: '" + strInfo + "' pos " + atomIndex + ")"); + System.err.println("Ignoring additional hover info: " + data + + " (other info: '" + strInfo + "' pos " + atomIndex + ")"); } mouseOverStructure(atomIndex, strInfo); } @@ -713,12 +734,11 @@ public abstract class JalviewJmolBinding implements StructureListener, jmolHistory(true); // TODO: in application this happens // -//if (scriptWindow != null) -// { -// scriptWindow.sendConsoleMessage(strInfo); -// scriptWindow.sendConsoleMessage("\n"); -// } - + // if (scriptWindow != null) + // { + // scriptWindow.sendConsoleMessage(strInfo); + // scriptWindow.sendConsoleMessage("\n"); + // } } @@ -730,8 +750,8 @@ public abstract class JalviewJmolBinding implements StructureListener, { case JmolConstants.CALLBACK_LOADSTRUCT: notifyFileLoaded((String) data[1], (String) data[2], - (String) data[3], (String) data[4], ((Integer) data[5]) - .intValue()); + (String) data[3], (String) data[4], + ((Integer) data[5]).intValue()); break; case JmolConstants.CALLBACK_PICK: @@ -743,8 +763,8 @@ public abstract class JalviewJmolBinding implements StructureListener, (String) data[0]); break; case JmolConstants.CALLBACK_SCRIPT: - notifyScriptTermination((String) data[2], ((Integer) data[3]) - .intValue()); + notifyScriptTermination((String) data[2], + ((Integer) data[3]).intValue()); break; case JmolConstants.CALLBACK_ECHO: sendConsoleEcho((String) data[1]); @@ -761,11 +781,12 @@ public abstract class JalviewJmolBinding implements StructureListener, updateUI(); break; case JmolConstants.CALLBACK_MEASURE: - + case JmolConstants.CALLBACK_CLICK: - + default: - System.err.println("Unhandled callback " + type + " " + data[1].toString()); + System.err.println("Unhandled callback " + type + " " + + data[1].toString()); break; } } catch (Exception e) @@ -806,6 +827,9 @@ public abstract class JalviewJmolBinding implements StructureListener, updateUI(); return; } + // the rest of this routine ignores the arguments, and simply interrogates + // the Jmol view to find out what structures it contains, and adds them to + // the structure selection manager. fileLoadingError = null; String[] oldmodels = modelFileNames; modelFileNames = null; @@ -814,49 +838,51 @@ public abstract class JalviewJmolBinding implements StructureListener, String[] modelfilenames = getPdbFile(); ssm = StructureSelectionManager.getStructureSelectionManager(); // first check if we've lost any structures - if (oldmodels!=null && oldmodels.length>0) + if (oldmodels != null && oldmodels.length > 0) { - int oldm=0; - for (int i=0;i0) + if (oldm > 0) { String[] oldmfn = new String[oldm]; - oldm=0; - for (int i=0;i