From: gmungoc Date: Thu, 11 Feb 2021 11:30:20 +0000 (+0000) Subject: JAL-3818 process Jmol callbacks in AWT thread X-Git-Tag: Release_2_11_2_0~34^2~30 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f001dc68c5066e79837f0785c587043a2976e446;p=jalview.git JAL-3818 process Jmol callbacks in AWT thread --- diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 5905d9a..61926dc 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -20,7 +20,6 @@ */ package jalview.ext.jmol; -import java.awt.Color; import java.awt.Container; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; @@ -32,6 +31,8 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; +import javax.swing.SwingUtilities; + import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolSelectionListener; @@ -61,9 +62,7 @@ import jalview.ws.dbsources.Pdb; import javajs.util.BS; public abstract class JalviewJmolBinding extends AAStructureBindingModel - implements JmolStatusListener, JmolSelectionListener, - ComponentListener -{ + implements JmolStatusListener, JmolSelectionListener, ComponentListener { private String lastMessage; /* @@ -82,24 +81,20 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public Viewer jmolViewer; - public JalviewJmolBinding(StructureSelectionManager ssm, - PDBEntry[] pdbentry, SequenceI[][] sequenceIs, - DataSourceType protocol) - { + public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, + DataSourceType protocol) { super(ssm, pdbentry, sequenceIs, protocol); setStructureCommands(new JmolCommands()); /* * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(), - * "jalviewJmol", ap.av.applet .getDocumentBase(), - * ap.av.applet.getCodeBase(), "", this); + * "jalviewJmol", ap.av.applet .getDocumentBase(), ap.av.applet.getCodeBase(), + * "", this); * * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true); */ } - public JalviewJmolBinding(StructureSelectionManager ssm, - SequenceI[][] seqs, Viewer theViewer) - { + public JalviewJmolBinding(StructureSelectionManager ssm, SequenceI[][] seqs, Viewer theViewer) { super(ssm, seqs); jmolViewer = theViewer; @@ -114,13 +109,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * * @return */ - public String getViewerTitle() - { + public String getViewerTitle() { return getViewerTitle("Jmol", true); } - private String jmolScript(String script) - { + private String jmolScript(String script) { Cache.log.debug(">>Jmol>> " + script); String s = jmolViewer.evalStringQuiet(script); // scriptWait(script); BH Cache.log.debug("< executeCommand(StructureCommandI command, - boolean getReply) - { - if (command == null) - { + public List executeCommand(StructureCommandI command, boolean getReply) { + if (command == null) { return null; } String cmd = command.getCommand(); jmolHistory(false); - if (lastCommand == null || !lastCommand.equals(cmd)) - { + if (lastCommand == null || !lastCommand.equals(cmd)) { jmolScript(cmd + "\n"); } jmolHistory(true); @@ -147,22 +136,18 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel return null; } - public void createImage(String file, String type, int quality) - { + public void createImage(String file, String type, int quality) { System.out.println("JMOL CREATE IMAGE"); } @Override - public String createImage(String fileName, String type, - Object textOrBytes, int quality) - { + public String createImage(String fileName, String type, Object textOrBytes, int quality) { System.out.println("JMOL CREATE IMAGE"); return null; } @Override - public String eval(String strEval) - { + public String eval(String strEval) { // System.out.println(strEval); // "# 'eval' is implemented only for the applet."; return null; @@ -172,15 +157,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // ////////////////////////// @Override - public float[][] functionXY(String functionName, int x, int y) - { + public float[][] functionXY(String functionName, int x, int y) { return null; } @Override - public float[][][] functionXYZ(String functionName, int nx, int ny, - int nz) - { + public float[][][] functionXYZ(String functionName, int nx, int ny, int nz) { // TODO Auto-generated method stub return null; } @@ -193,32 +175,26 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel private int _modelFileNameMap[]; @Override - public synchronized String[] getStructureFiles() - { - if (jmolViewer == null) - { + public synchronized String[] getStructureFiles() { + if (jmolViewer == null) { return new String[0]; } - if (modelFileNames == null) - { + if (modelFileNames == null) { int modelCount = jmolViewer.ms.mc; String filePath = null; List mset = new ArrayList<>(); - for (int i = 0; i < modelCount; ++i) - { + for (int i = 0; i < modelCount; ++i) { /* - * defensive check for null as getModelFileName can return null - * even when model count ms.mc is > 0 + * defensive check for null as getModelFileName can return null even when model + * count ms.mc is > 0 */ filePath = jmolViewer.ms.getModelFileName(i); - if (filePath != null && !mset.contains(filePath)) - { + if (filePath != null && !mset.contains(filePath)) { mset.add(filePath); } } - if (!mset.isEmpty()) - { + if (!mset.isEmpty()) { modelFileNames = mset.toArray(new String[mset.size()]); } } @@ -230,8 +206,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * map from string to applet */ @Override - public Map getRegistryInfo() - { + public Map getRegistryInfo() { // TODO Auto-generated method stub return null; } @@ -239,8 +214,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // /////////////////////////////// // JmolStatusListener - public void handlePopupMenu(int x, int y) - { + public void handlePopupMenu(int x, int y) { // jmolpopup.show(x, y); // jmolpopup.jpiShow(x, y); } @@ -249,30 +223,22 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * Highlight zero, one or more atoms on the structure */ @Override - public void highlightAtoms(List atoms) - { - if (atoms != null) - { - if (resetLastRes.length() > 0) - { + public void highlightAtoms(List atoms) { + if (atoms != null) { + if (resetLastRes.length() > 0) { jmolScript(resetLastRes.toString()); resetLastRes.setLength(0); } - for (AtomSpec atom : atoms) - { - highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(), - atom.getChain(), atom.getPdbFile()); + for (AtomSpec atom : atoms) { + highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(), atom.getChain(), atom.getPdbFile()); } } } // jmol/ssm only - public void highlightAtom(int atomIndex, int pdbResNum, String chain, - String pdbfile) - { + public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile) { String modelId = getModelIdForFile(pdbfile); - if (modelId.isEmpty()) - { + if (modelId.isEmpty()) { return; } @@ -282,17 +248,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel StringBuilder cmd = new StringBuilder(64); selection.append("select ").append(String.valueOf(pdbResNum)); selection.append(":"); - if (!chain.equals(" ")) - { + if (!chain.equals(" ")) { selection.append(chain); } selection.append(" /").append(modelId); - cmd.append(selection).append(";wireframe 100;").append(selection) - .append(" and not hetero;").append("spacefill 200;select none"); + cmd.append(selection).append(";wireframe 100;").append(selection).append(" and not hetero;") + .append("spacefill 200;select none"); - resetLastRes.append(selection).append(";wireframe 0;").append(selection) - .append(" and not hetero; spacefill 0;"); + resetLastRes.append(selection).append(";wireframe 0;").append(selection).append(" and not hetero; spacefill 0;"); jmolScript(cmd.toString()); jmolHistory(true); @@ -300,13 +264,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel private boolean debug = true; - private void jmolHistory(boolean enable) - { + private void jmolHistory(boolean enable) { jmolScript("History " + ((debug || enable) ? "on" : "off")); } - public void loadInline(String string) - { + public void loadInline(String string) { loadedInline = true; // TODO: re JAL-623 // viewer.loadInline(strModel, isAppend); @@ -319,171 +281,129 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolViewer.openStringInline(string); } - protected void mouseOverStructure(int atomIndex, final String strInfo) - { + protected void mouseOverStructure(int atomIndex, final String strInfo) { int pdbResNum; int alocsep = strInfo.indexOf("^"); int mdlSep = strInfo.indexOf("/"); int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1; - if (chainSeparator == -1) - { + if (chainSeparator == -1) { chainSeparator = strInfo.indexOf("."); - if (mdlSep > -1 && mdlSep < chainSeparator) - { + if (mdlSep > -1 && mdlSep < chainSeparator) { chainSeparator1 = chainSeparator; chainSeparator = mdlSep; } } // handle insertion codes - if (alocsep != -1) - { - pdbResNum = Integer.parseInt( - strInfo.substring(strInfo.indexOf("]") + 1, alocsep)); + if (alocsep != -1) { + pdbResNum = Integer.parseInt(strInfo.substring(strInfo.indexOf("]") + 1, alocsep)); - } - else - { - pdbResNum = Integer.parseInt( - strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator)); + } else { + pdbResNum = Integer.parseInt(strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator)); } String chainId; - if (strInfo.indexOf(":") > -1) - { - chainId = strInfo.substring(strInfo.indexOf(":") + 1, - strInfo.indexOf(".")); - } - else - { + if (strInfo.indexOf(":") > -1) { + chainId = strInfo.substring(strInfo.indexOf(":") + 1, strInfo.indexOf(".")); + } else { chainId = " "; } String pdbfilename = modelFileNames[0]; // default is first model - if (mdlSep > -1) - { - if (chainSeparator1 == -1) - { + if (mdlSep > -1) { + if (chainSeparator1 == -1) { chainSeparator1 = strInfo.indexOf(".", mdlSep); } - String mdlId = (chainSeparator1 > -1) - ? strInfo.substring(mdlSep + 1, chainSeparator1) - : strInfo.substring(mdlSep + 1); - try - { + String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1, chainSeparator1) + : strInfo.substring(mdlSep + 1); + try { // recover PDB filename for the model hovered over. int mnumber = Integer.valueOf(mdlId).intValue() - 1; - if (_modelFileNameMap != null) - { + if (_modelFileNameMap != null) { int _mp = _modelFileNameMap.length - 1; - while (mnumber < _modelFileNameMap[_mp]) - { + while (mnumber < _modelFileNameMap[_mp]) { _mp--; } pdbfilename = modelFileNames[_mp]; - } - else - { - if (mnumber >= 0 && mnumber < modelFileNames.length) - { + } else { + if (mnumber >= 0 && mnumber < modelFileNames.length) { pdbfilename = modelFileNames[mnumber]; } - if (pdbfilename == null) - { - pdbfilename = new File(jmolViewer.ms.getModelFileName(mnumber)) - .getAbsolutePath(); + if (pdbfilename == null) { + pdbfilename = new File(jmolViewer.ms.getModelFileName(mnumber)).getAbsolutePath(); } } - } catch (Exception e) - { + } catch (Exception e) { } } /* - * highlight position on alignment(s); if some text is returned, - * show this as a second line on the structure hover tooltip + * highlight position on alignment(s); if some text is returned, show this as a + * second line on the structure hover tooltip */ - String label = getSsm().mouseOverStructure(pdbResNum, chainId, - pdbfilename); - if (label != null) - { + String label = getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename); + if (label != null) { // change comma to pipe separator (newline token for Jmol) label = label.replace(',', '|'); StringTokenizer toks = new StringTokenizer(strInfo, " "); StringBuilder sb = new StringBuilder(); - sb.append("select ").append(String.valueOf(pdbResNum)).append(":") - .append(chainId).append("/1"); - sb.append(";set hoverLabel \"").append(toks.nextToken()).append(" ") - .append(toks.nextToken()); + sb.append("select ").append(String.valueOf(pdbResNum)).append(":").append(chainId).append("/1"); + sb.append(";set hoverLabel \"").append(toks.nextToken()).append(" ").append(toks.nextToken()); sb.append("|").append(label).append("\""); executeCommand(new StructureCommand(sb.toString()), false); } } - public void notifyAtomHovered(int atomIndex, String strInfo, String data) - { - if (strInfo.equals(lastMessage)) - { + public void notifyAtomHovered(int atomIndex, String strInfo, String data) { + if (strInfo.equals(lastMessage)) { return; } lastMessage = strInfo; - if (data != null) - { - System.err.println("Ignoring additional hover info: " + data - + " (other info: '" + strInfo + "' pos " + atomIndex + ")"); + if (data != null) { + System.err.println( + "Ignoring additional hover info: " + data + " (other info: '" + strInfo + "' pos " + atomIndex + ")"); } mouseOverStructure(atomIndex, strInfo); } /* * { if (history != null && strStatus != null && - * !strStatus.equals("Script completed")) { history.append("\n" + strStatus); - * } } + * !strStatus.equals("Script completed")) { history.append("\n" + strStatus); } + * } */ - public void notifyAtomPicked(int atomIndex, String strInfo, - String strData) - { + public void notifyAtomPicked(int atomIndex, String strInfo, String strData) { /** - * this implements the toggle label behaviour copied from the original - * structure viewer, mc_view + * this implements the toggle label behaviour copied from the original structure + * viewer, mc_view */ - if (strData != null) - { + if (strData != null) { System.err.println("Ignoring additional pick data string " + strData); } int chainSeparator = strInfo.indexOf(":"); int p = 0; - if (chainSeparator == -1) - { + if (chainSeparator == -1) { chainSeparator = strInfo.indexOf("."); } - String picked = strInfo.substring(strInfo.indexOf("]") + 1, - chainSeparator); + String picked = strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator); String mdlString = ""; - if ((p = strInfo.indexOf(":")) > -1) - { + if ((p = strInfo.indexOf(":")) > -1) { picked += strInfo.substring(p, strInfo.indexOf(".")); } - if ((p = strInfo.indexOf("/")) > -1) - { + if ((p = strInfo.indexOf("/")) > -1) { mdlString += strInfo.substring(p, strInfo.indexOf(" #")); } - picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P" - + mdlString + "))"; + picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P" + mdlString + "))"; jmolHistory(false); - if (!atomsPicked.contains(picked)) - { + if (!atomsPicked.contains(picked)) { jmolScript("select " + picked + ";label %n %r:%c"); atomsPicked.addElement(picked); - } - else - { + } else { jmolViewer.evalString("select " + picked + ";label off"); atomsPicked.removeElement(picked); } @@ -499,37 +419,48 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } @Override - public void notifyCallback(CBK type, Object[] data) - { - try - { - switch (type) - { + public void notifyCallback(CBK type, Object[] data) { + /* + * ensure processed in AWT thread to avoid risk of deadlocks + */ + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + processCallback(type, data); + } + }); + } + + /** + * Processes one callback notification from Jmol + * + * @param type + * @param data + */ + protected void processCallback(CBK type, Object[] data) { + try { + switch (type) { case LOADSTRUCT: - notifyFileLoaded((String) data[1], (String) data[2], - (String) data[3], (String) data[4], - ((Integer) data[5]).intValue()); + notifyFileLoaded((String) data[1], (String) data[2], (String) data[3], (String) data[4], + ((Integer) data[5]).intValue()); break; case PICK: - notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1], - (String) data[0]); + notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1], (String) data[0]); // also highlight in alignment // deliberate fall through case HOVER: - notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1], - (String) data[0]); + notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1], (String) data[0]); break; case SCRIPT: - notifyScriptTermination((String) data[2], - ((Integer) data[3]).intValue()); + notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue()); break; case ECHO: sendConsoleEcho((String) data[1]); break; case MESSAGE: - sendConsoleMessage( - (data == null) ? ((String) null) : (String) data[1]); + sendConsoleMessage((data == null) ? ((String) null) : (String) data[1]); break; case ERROR: // System.err.println("Ignoring error callback."); @@ -542,22 +473,18 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel case CLICK: default: - System.err.println( - "Unhandled callback " + type + " " + data[1].toString()); + System.err.println("Unhandled callback " + type + " " + data[1].toString()); break; } - } catch (Exception e) - { + } catch (Exception e) { System.err.println("Squashed Jmol callback handler error:"); e.printStackTrace(); } } @Override - public boolean notifyEnabled(CBK callbackPick) - { - switch (callbackPick) - { + public boolean notifyEnabled(CBK callbackPick) { + switch (callbackPick) { case ECHO: case LOADSTRUCT: case MEASURE: @@ -577,16 +504,13 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // referrring to new structures. private long loadNotifiesHandled = 0; - public long getLoadNotifiesHandled() - { + public long getLoadNotifiesHandled() { return loadNotifiesHandled; } - public void notifyFileLoaded(String fullPathName, String fileName2, - String modelName, String errorMsg, int modelParts) - { - if (errorMsg != null) - { + public void notifyFileLoaded(String fullPathName, String fileName2, String modelName, String errorMsg, + int modelParts) { + if (errorMsg != null) { fileLoadingError = errorMsg; refreshGUI(); return; @@ -602,38 +526,29 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel modelFileNames = null; boolean notifyLoaded = false; String[] modelfilenames = getStructureFiles(); - if (modelfilenames == null) - { + if (modelfilenames == null) { // Jmol is still loading files! return; } // 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++) - { - for (int n = 0; n < modelfilenames.length; n++) - { - if (modelfilenames[n] == oldmodels[i]) - { + for (int i = 0; i < oldmodels.length; i++) { + for (int n = 0; n < modelfilenames.length; n++) { + if (modelfilenames[n] == oldmodels[i]) { 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++) - { - if (oldmodels[i] != null) - { + for (int i = 0; i < oldmodels.length; i++) { + if (oldmodels[i] != null) { oldmfn[oldm++] = oldmodels[i]; } } @@ -643,45 +558,37 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } } refreshPdbEntries(); - for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++) - { + for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++) { String fileName = modelfilenames[modelnum]; boolean foundEntry = false; StructureFile pdb = null; String pdbfile = null; // model was probably loaded inline - so check the pdb file hashcode - if (loadedInline) - { + if (loadedInline) { // calculate essential attributes for the pdb data imported inline. // prolly need to resolve modelnumber properly - for now just use our // 'best guess' - pdbfile = jmolViewer.getData( - "" + (1 + _modelFileNameMap[modelnum]) + ".0", "PDB"); + pdbfile = jmolViewer.getData("" + (1 + _modelFileNameMap[modelnum]) + ".0", "PDB"); } // search pdbentries and sequences to find correct pdbentry for this // model - for (int pe = 0; pe < getPdbCount(); pe++) - { + for (int pe = 0; pe < getPdbCount(); pe++) { boolean matches = false; addSequence(pe, getSequence()[pe]); - if (fileName == null) - { + if (fileName == null) { if (false) // see JAL-623 - need method of matching pasted data up { - pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], - pdbfile, DataSourceType.PASTE, getIProgressIndicator()); + pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], pdbfile, DataSourceType.PASTE, + getIProgressIndicator()); getPdbEntry(modelnum).setFile("INLINE" + pdb.getId()); matches = true; foundEntry = true; } - } - else - { + } else { File fl = new File(getPdbEntry(pe).getFile()); matches = fl.equals(new File(fileName)); - if (matches) - { + if (matches) { foundEntry = true; // TODO: Jmol can in principle retrieve from CLASSLOADER but // this @@ -689,38 +596,30 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // to be tested. See mantis bug // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605 DataSourceType protocol = DataSourceType.URL; - try - { - if (fl.exists()) - { + try { + if (fl.exists()) { protocol = DataSourceType.FILE; } - } catch (Exception e) - { - } catch (Error e) - { + } catch (Exception e) { + } catch (Error e) { } // Explicitly map to the filename used by Jmol ; - pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], - fileName, protocol, getIProgressIndicator()); + pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], fileName, protocol, getIProgressIndicator()); // pdbentry[pe].getFile(), protocol); } } - if (matches) - { + if (matches) { stashFoundChains(pdb, fileName); notifyLoaded = true; } } - if (!foundEntry && associateNewStructs) - { + 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 = jmolViewer.getData("/" + (modelnum + 1) + ".1", - "PDB"); + String pdbcontent = jmolViewer.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 @@ -736,22 +635,17 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // // potential for deadlock here: // // jmolpopup.updateComputedMenus(); // } - if (!isLoadingFromArchive()) - { - jmolScript( - "model *; select backbone;restrict;cartoon;wireframe off;spacefill off"); + if (!isLoadingFromArchive()) { + jmolScript("model *; select backbone;restrict;cartoon;wireframe off;spacefill off"); } // register ourselves as a listener and notify the gui that it needs to // update itself. getSsm().addStructureViewerListener(this); - if (notifyLoaded) - { + if (notifyLoaded) { FeatureRenderer fr = getFeatureRenderer(null); - if (fr != null) - { + if (fr != null) { FeatureSettingsModelI colours = new Pdb().getFeatureColourScheme(); - ((AppJmol) getViewer()).getAlignmentPanel().av - .applyFeaturesStyle(colours); + ((AppJmol) getViewer()).getAlignmentPanel().av.applyFeaturesStyle(colours); } refreshGUI(); loadNotifiesHandled++; @@ -759,18 +653,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel setLoadingFromArchive(false); } - protected IProgressIndicator getIProgressIndicator() - { + protected IProgressIndicator getIProgressIndicator() { return null; } - public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) - { + public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) { 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 @@ -780,34 +671,29 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public abstract void sendConsoleEcho(String strEcho); /* * { showConsole(true); * - * history.append("\n" + - * strEcho); } + * history.append("\n" + strEcho); } */ // /End JmolStatusListener // ///////////////////////////// /** - * @param strStatus - * status message - usually the response received after a script - * executed + * @param strStatus status message - usually the response received after a + * script executed */ public abstract void sendConsoleMessage(String strStatus); @Override - public void setCallbackFunction(String callbackType, - String callbackFunction) - { - System.err.println("Ignoring set-callback request to associate " - + callbackType + " with function " + callbackFunction); + public void setCallbackFunction(String callbackType, String callbackFunction) { + System.err + .println("Ignoring set-callback request to associate " + callbackType + " with function " + callbackFunction); } - public void showHelp() - { + public void showHelp() { showUrl("http://wiki.jmol.org" // BH 2018 "http://jmol.sourceforge.net/docs/JmolUserGuide/" - , "jmolHelp"); + , "jmolHelp"); } /** @@ -824,10 +710,8 @@ 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); + public static Viewer getJmolData(JmolParser jmolParser) { + return (Viewer) JmolViewer.allocateViewer(null, null, null, null, null, "-x -o -n", jmolParser); } /** @@ -835,75 +719,57 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * * * @param renderPanel - * @param jmolfileio - * - when true will initialise jmol's file IO system (should be false - * in applet context) + * @param jmolfileio - when true will initialise jmol's file IO system + * (should be false in applet context) * @param htmlName * @param documentBase * @param codeBase * @param commandOptions */ - public void allocateViewer(Container renderPanel, boolean jmolfileio, - String htmlName, URL documentBase, URL codeBase, - String commandOptions) - { - allocateViewer(renderPanel, jmolfileio, htmlName, documentBase, - codeBase, commandOptions, null, null); + public void allocateViewer(Container renderPanel, boolean jmolfileio, String htmlName, URL documentBase, URL codeBase, + String commandOptions) { + allocateViewer(renderPanel, jmolfileio, htmlName, documentBase, codeBase, commandOptions, null, null); } /** * * @param renderPanel - * @param jmolfileio - * - when true will initialise jmol's file IO system (should be false - * in applet context) + * @param jmolfileio - when true will initialise jmol's file IO system + * (should be false in applet context) * @param htmlName * @param documentBase * @param codeBase * @param commandOptions - * @param consolePanel - * - panel to contain Jmol console - * @param buttonsToShow - * - buttons to show on the console, in order + * @param consolePanel - panel to contain Jmol console + * @param buttonsToShow - 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) - { + 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) - { + if (commandOptions == null) { commandOptions = ""; } - jmolViewer = (Viewer) JmolViewer.allocateViewer(renderPanel, - (jmolfileio ? new SmarterJmolAdapter() : null), - htmlName + ((Object) this).toString(), documentBase, codeBase, - commandOptions, this); + jmolViewer = (Viewer) JmolViewer.allocateViewer(renderPanel, (jmolfileio ? new SmarterJmolAdapter() : null), + htmlName + ((Object) this).toString(), documentBase, codeBase, commandOptions, this); jmolViewer.setJmolStatusListener(this); // extends JmolCallbackListener - try - { + try { console = createJmolConsole(consolePanel, buttonsToShow); - } catch (Throwable e) - { - System.err.println("Could not create Jmol application console. " - + e.getMessage()); + } catch (Throwable e) { + System.err.println("Could not create Jmol application console. " + e.getMessage()); e.printStackTrace(); } - if (consolePanel != null) - { + if (consolePanel != null) { consolePanel.addComponentListener(this); } } - protected abstract JmolAppConsoleInterface createJmolConsole( - Container consolePanel, String buttonsToShow); + protected abstract JmolAppConsoleInterface createJmolConsole(Container consolePanel, String buttonsToShow); // BH 2018 -- Jmol console is not working due to problems with styled // documents. @@ -911,8 +777,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel protected org.jmol.api.JmolAppConsoleInterface console = null; @Override - public int[] resizeInnerPanel(String data) - { + public int[] resizeInnerPanel(String data) { // Jalview doesn't honour resize panel requests return null; } @@ -920,17 +785,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel /** * */ - protected void closeConsole() - { - if (console != null) - { - try - { + protected void closeConsole() { + if (console != null) { + try { console.setVisible(false); - } catch (Error e) - { - } catch (Exception x) - { + } catch (Error e) { + } catch (Exception x) { } ; console = null; @@ -941,24 +801,21 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * ComponentListener method */ @Override - public void componentMoved(ComponentEvent e) - { + public void componentMoved(ComponentEvent e) { } /** * ComponentListener method */ @Override - public void componentResized(ComponentEvent e) - { + public void componentResized(ComponentEvent e) { } /** * ComponentListener method */ @Override - public void componentShown(ComponentEvent e) - { + public void componentShown(ComponentEvent e) { showConsole(true); } @@ -966,22 +823,17 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * ComponentListener method */ @Override - public void componentHidden(ComponentEvent e) - { + public void componentHidden(ComponentEvent e) { showConsole(false); } @Override - protected String getModelIdForFile(String pdbFile) - { - if (modelFileNames == null) - { + protected String getModelIdForFile(String pdbFile) { + if (modelFileNames == null) { return ""; } - for (int i = 0; i < modelFileNames.length; i++) - { - if (modelFileNames[i].equalsIgnoreCase(pdbFile)) - { + for (int i = 0; i < modelFileNames.length; i++) { + if (modelFileNames[i].equalsIgnoreCase(pdbFile)) { return String.valueOf(i + 1); } } @@ -989,14 +841,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } @Override - protected ViewerType getViewerType() - { + protected ViewerType getViewerType() { return ViewerType.JMOL; } @Override - protected String getModelId(int pdbfnum, String file) - { + protected String getModelId(int pdbfnum, String file) { return String.valueOf(pdbfnum + 1); } @@ -1007,27 +857,23 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * @see https://chemapps.stolaf.edu/jmol/docs/#writemodel */ @Override - public String getSessionFileExtension() - { + public String getSessionFileExtension() { return ".spt"; } @Override - public void selectionChanged(BS arg0) - { + public void selectionChanged(BS arg0) { // TODO Auto-generated method stub } @Override - public SequenceRenderer getSequenceRenderer(AlignmentViewPanel avp) - { + public SequenceRenderer getSequenceRenderer(AlignmentViewPanel avp) { return new jalview.gui.SequenceRenderer(avp.getAlignViewport()); } @Override - public String getHelpURL() - { + public String getHelpURL() { return "http://wiki.jmol.org"; // BH 2018 } }