import jalview.schemes.*;
public abstract class JalviewJmolBinding implements StructureListener,
- JmolStatusListener, SequenceStructureBinding
+ JmolStatusListener, SequenceStructureBinding, JmolSelectionListener
{
/**
* 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;
*/
}
+ 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());
}
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()
// and shut down jmol
viewer.evalStringQuiet("zap");
viewer.setJmolStatusListener(null);
- lastCommand=null;
+ lastCommand = null;
viewer = null;
}
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
{
if (!colourBySequence)
return;
- if (ssm==null)
+ if (ssm == null)
{
return;
}
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());
*/
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();
String chainId;
if (strInfo.indexOf(":") > -1)
- chainId = strInfo.substring(strInfo.indexOf(":") + 1, strInfo
- .indexOf("."));
+ chainId = strInfo.substring(strInfo.indexOf(":") + 1,
+ strInfo.indexOf("."));
else
{
chainId = " ";
{
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);
}
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");
+ // }
}
{
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:
(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]);
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)
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;
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;i<oldmodels.length;i++)
+ int oldm = 0;
+ for (int i = 0; i < oldmodels.length; i++)
{
- for (int n=0;n<modelfilenames.length; n++)
+ for (int n = 0; n < modelfilenames.length; n++)
{
- if (modelfilenames[n]==oldmodels[i])
+ if (modelfilenames[n] == oldmodels[i])
{
- oldmodels[i]=null;
+ oldmodels[i] = null;
break;
}
}
- if (oldmodels[i]!=null)
+ if (oldmodels[i] != null)
{
oldm++;
}
}
- if (oldm>0)
+ if (oldm > 0)
{
String[] oldmfn = new String[oldm];
- oldm=0;
- for (int i=0;i<oldmodels.length; i++)
+ oldm = 0;
+ for (int i = 0; i < oldmodels.length; i++)
{
- if (oldmodels[i]!=null) {
+ if (oldmodels[i] != null)
+ {
oldmfn[oldm++] = oldmodels[i];
}
}
- // deregister the Jmol instance for these structures - we'll add
- // ourselves again at the end for the current structure set.
+ // deregister the Jmol instance for these structures - we'll add
+ // ourselves again at the end for the current structure set.
ssm.removeStructureViewerListener(this, oldmfn);
}
}
+ refreshPdbEntries();
for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
{
String fileName = modelfilenames[modelnum];
if (fileName != null)
{
+ boolean foundEntry = false;
// search pdbentries and sequences to find correct pdbentry and
// sequence[] pair for this filename
if (pdbentry != null)
{
- boolean foundEntry = false;
for (int pe = 0; pe < pdbentry.length; pe++)
{
if (pdbentry[pe].getFile().equals(fileName))
if (loadedInline)
{
// TODO: replace with getData ?
- pdb = ssm.setMapping(sequence, chains, pdbentry[pe]
- .getFile(), AppletFormatAdapter.PASTE);
+ pdb = ssm.setMapping(sequence, chains,
+ pdbentry[pe].getFile(), AppletFormatAdapter.PASTE);
pdbentry[pe].setFile("INLINE" + pdb.id);
}
else
{
}
;
- pdb = ssm.setMapping(sequence, chains, pdbentry[pe]
- .getFile(), protocol);
+ pdb = ssm.setMapping(sequence, chains,
+ pdbentry[pe].getFile(), protocol);
}
notifyLoaded = true;
}
}
- if (!foundEntry && associateNewStructs)
- {
- // this is a foreign pdb file that jalview doesn't know about - add
- // it
- // to the dataset
- // and try to find a home - either on a matching sequence or as a
- // new
- // sequence.
- String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
- "PDB");
- // parse pdb file into a chain, etc.
- // locate best match for pdb in associated views and add mapping to
- // ssm
- // if properly registered then
- notifyLoaded = true;
- }
+ }
+ if (!foundEntry && associateNewStructs)
+ {
+ // this is a foreign pdb file that jalview doesn't know about - add
+ // it to the dataset and try to find a home - either on a matching
+ // sequence or as a new sequence.
+ String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
+ "PDB");
+ // parse pdb file into a chain, etc.
+ // locate best match for pdb in associated views and add mapping to
+ // ssm
+ // if properly registered then
+ notifyLoaded = true;
+
}
}
}
// FILE LOADED OK
// so finally, update the jmol bits and pieces
- jmolpopup.updateComputedMenus();
+ if (jmolpopup != null)
+ {
+ jmolpopup.updateComputedMenus();
+ }
if (!isLoadingFromArchive())
{
- viewer
- .evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
+ viewer.evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
}
setLoadingFromArchive(false);
// register ourselves as a listener and notify the gui that it needs to
if (notifyLoaded)
{
FeatureRenderer fr = getFeatureRenderer();
- if (fr!=null)
+ if (fr != null)
{
fr.featuresAdded();
}
notifyAtomPicked(iatom, strMeasure, null);
}
- public abstract void notifyScriptTermination(String strStatus, int msWalltime);
+ public abstract void notifyScriptTermination(String strStatus,
+ int msWalltime);
/**
* display a message echoed from the jmol viewer
URL documentBase, URL codeBase, String commandOptions)
{
viewer = JmolViewer.allocateViewer(renderPanel,
- new SmarterJmolAdapter(), htmlName+((Object) this).toString(), documentBase, codeBase,
+ new SmarterJmolAdapter(),
+ htmlName + ((Object) this).toString(), documentBase, codeBase,
commandOptions, this);
}
{
return loadingFromArchive;
}
+
public void setBackgroundColour(java.awt.Color col)
{
jmolHistory(false);