From 3916d19d9be0e912ddc0a3fd6241f387aec72f76 Mon Sep 17 00:00:00 2001 From: hansonr Date: Tue, 16 Apr 2019 16:06:36 -0500 Subject: [PATCH 1/1] localizes Thread colourby so that it does not cause ThreadStateException in Java --- src/jalview/ext/jmol/JalviewJmolBinding.java | 43 ++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 2cabefa..fa31fd9 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -167,7 +167,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // remove listeners for all structures in viewer getSsm().removeStructureViewerListener(this, this.getStructureFiles()); if (viewer != null) + { viewer.dispose(); + } lastCommand = null; viewer = null; releaseUIResources(); @@ -480,6 +482,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } Thread colourby = null; + /** * Sends a set of colour commands to the structure viewer * @@ -494,7 +497,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() @@ -509,6 +512,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } }); colourby.start(); + this.colourby = colourby; } /** @@ -1154,8 +1158,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; @@ -1331,8 +1334,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void showHelp() { showUrl("http://wiki.jmol.org" - // BH 2018 "http://jmol.sourceforge.net/docs/JmolUserGuide/" - , "jmolHelp"); + // BH 2018 "http://jmol.sourceforge.net/docs/JmolUserGuide/" + , "jmolHelp"); } /** @@ -1356,7 +1359,6 @@ 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, @@ -1404,9 +1406,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel String commandOptions, final Container consolePanel, String buttonsToShow) { - + System.err.println("Allocating Jmol Viewer: " + commandOptions); - + if (commandOptions == null) { commandOptions = ""; @@ -1418,10 +1420,13 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel viewer.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) @@ -1435,8 +1440,8 @@ 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. - + // BH 2018 -- Jmol console is not working due to problems with styled + // documents. protected org.jmol.api.JmolAppConsoleInterface console = null; @@ -1444,20 +1449,20 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void setBackgroundColour(java.awt.Color col) { jmolHistory(false); - jmolScript("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("<