X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJalviewJmolBinding.java;h=4698e4d5e42d87f54bf3d713a1bcb60eca802c2f;hb=8946f41687f4c822ac8d15ee8551f23f156735c4;hp=88322785ee9fbce68679087362a8bbfcaa40fe6c;hpb=45f6886f7c6059d7ce2dc705df3cecb881ccf2b4;p=jalview.git diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 8832278..4698e4d 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -44,7 +44,6 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.io.File; import java.net.URL; -import java.security.AccessControlException; import java.util.ArrayList; import java.util.BitSet; import java.util.Hashtable; @@ -166,7 +165,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { // remove listeners for all structures in viewer getSsm().removeStructureViewerListener(this, this.getStructureFiles()); - viewer.dispose(); + if (viewer != null) + { + viewer.dispose(); + } lastCommand = null; viewer = null; releaseUIResources(); @@ -472,13 +474,14 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolHistory(false); if (lastCommand == null || !lastCommand.equals(command)) { - viewer.evalStringQuiet(command + "\n"); + jmolScript(command + "\n"); } jmolHistory(true); lastCommand = command; } Thread colourby = null; + /** * Sends a set of colour commands to the structure viewer * @@ -493,7 +496,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel colourby.interrupt(); colourby = null; } - colourby = new Thread(new Runnable() + Thread colourby = new Thread(new Runnable() { @Override public void run() @@ -508,6 +511,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } }); colourby.start(); + this.colourby = colourby; } /** @@ -614,74 +618,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ private int _modelFileNameMap[]; - // //////////////////////////////// - // /StructureListener - // @Override - public synchronized String[] getPdbFilex() - { - if (viewer == null) - { - return new String[0]; - } - if (modelFileNames == null) - { - List mset = new ArrayList<>(); - _modelFileNameMap = new int[viewer.ms.mc]; - String m = viewer.ms.getModelFileName(0); - if (m != null) - { - String filePath = m; - try - { - filePath = new File(m).getAbsolutePath(); - } catch (AccessControlException x) - { - // usually not allowed to do this in applet - System.err.println( - "jmolBinding: Using local file string from Jmol: " + m); - } - if (filePath.indexOf("/file:") != -1) - { - // applet path with docroot - discard as format won't match pdbfile - filePath = m; - } - mset.add(filePath); - _modelFileNameMap[0] = 0; // filename index for first model is always 0. - } - int j = 1; - for (int i = 1; i < viewer.ms.mc; i++) - { - m = viewer.ms.getModelFileName(i); - String filePath = m; - if (m != null) - { - try - { - filePath = new File(m).getAbsolutePath(); - } catch (AccessControlException x) - { - // usually not allowed to do this in applet, so keep raw handle - // System.err.println("jmolBinding: Using local file string from - // Jmol: "+m); - } - } - - /* - * add this model unless it is read from a structure file we have - * already seen (example: 2MJW is an NMR structure with 10 models) - */ - if (!mset.contains(filePath)) - { - mset.add(filePath); - _modelFileNameMap[j] = i; // record the model index for the filename - j++; - } - } - modelFileNames = mset.toArray(new String[mset.size()]); - } - return modelFileNames; - } - @Override public synchronized String[] getStructureFiles() { @@ -738,7 +674,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { if (resetLastRes.length() > 0) { - viewer.evalStringQuiet(resetLastRes.toString()); + jmolScript(resetLastRes.toString()); resetLastRes.setLength(0); } for (AtomSpec atom : atoms) @@ -796,7 +732,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel cmd.append("spacefill 200;select none"); - viewer.evalStringQuiet(cmd.toString()); + jmolScript(cmd.toString()); jmolHistory(true); } @@ -805,7 +741,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel private void jmolHistory(boolean enable) { - viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off")); + jmolScript("History " + ((debug || enable) ? "on" : "off")); } public void loadInline(String string) @@ -876,7 +812,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel try { // recover PDB filename for the model hovered over. - int mnumber = new Integer(mdlId).intValue() - 1; + int mnumber = Integer.valueOf(mdlId).intValue() - 1; if (_modelFileNameMap != null) { int _mp = _modelFileNameMap.length - 1; @@ -934,7 +870,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { /** * this implements the toggle label behaviour copied from the original - * structure viewer, MCView + * structure viewer, mc_view */ if (strData != null) { @@ -965,7 +901,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel if (!atomsPicked.contains(picked)) { - viewer.evalStringQuiet("select " + picked + ";label %n %r:%c"); + jmolScript("select " + picked + ";label %n %r:%c"); atomsPicked.addElement(picked); } else @@ -1153,8 +1089,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // see JAL-623 - need method of matching pasted data up { pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], - pdbfile, DataSourceType.PASTE, - getIProgressIndicator()); + pdbfile, DataSourceType.PASTE, getIProgressIndicator()); getPdbEntry(modelnum).setFile("INLINE" + pdb.getId()); matches = true; foundEntry = true; @@ -1229,7 +1164,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // } if (!isLoadingFromArchive()) { - viewer.evalStringQuiet( + jmolScript( "model *; select backbone;restrict;cartoon;wireframe off;spacefill off"); } // register ourselves as a listener and notify the gui that it needs to @@ -1254,7 +1189,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel return chainNames; } - protected abstract IProgressIndicator getIProgressIndicator(); + protected IProgressIndicator getIProgressIndicator() + { + return null; + } public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) { @@ -1326,7 +1264,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void showHelp() { - showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp"); + showUrl("http://wiki.jmol.org" + // BH 2018 "http://jmol.sourceforge.net/docs/JmolUserGuide/" + , "jmolHelp"); } /** @@ -1350,7 +1290,16 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ public abstract void showConsole(boolean show); + public static Viewer getJmolData(JmolParser jmolParser) + { + return (Viewer) JmolViewer.allocateViewer(null, null, null, null, null, + "-x -o -n", jmolParser); + } + /** + * + * + * * @param renderPanel * @param jmolfileio * - when true will initialise jmol's file IO system (should be false @@ -1381,13 +1330,16 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * @param consolePanel * - panel to contain Jmol console * @param buttonsToShow - * - buttons to show on the console, in ordr + * - buttons to show on the console, in order */ public void allocateViewer(Container renderPanel, boolean jmolfileio, String htmlName, URL documentBase, URL codeBase, String commandOptions, final Container consolePanel, String buttonsToShow) { + + System.err.println("Allocating Jmol Viewer: " + commandOptions); + if (commandOptions == null) { commandOptions = ""; @@ -1399,7 +1351,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel viewer.setJmolStatusListener(this); // extends JmolCallbackListener - console = createJmolConsole(consolePanel, buttonsToShow); + try + { + console = createJmolConsole(consolePanel, buttonsToShow); + } catch (Throwable e) + { + System.err.println("Could not create Jmol application console. " + + e.getMessage()); + e.printStackTrace(); + } if (consolePanel != null) { consolePanel.addComponentListener(this); @@ -1411,17 +1371,32 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel protected abstract JmolAppConsoleInterface createJmolConsole( Container consolePanel, String buttonsToShow); + // BH 2018 -- Jmol console is not working due to problems with styled + // documents. + protected org.jmol.api.JmolAppConsoleInterface console = null; @Override public void setBackgroundColour(java.awt.Color col) { jmolHistory(false); - viewer.evalStringQuiet("background [" + col.getRed() + "," - + col.getGreen() + "," + col.getBlue() + "];"); + jmolScript("background [" + col.getRed() + "," + col.getGreen() + "," + + col.getBlue() + "];"); jmolHistory(true); } + private String jmolScript(String script) + { + + System.err.println(">>Jmol>> " + script); + + String s = viewer.scriptWait(script); + + System.err.println("<