From: jprocter Date: Mon, 13 Sep 2010 18:24:06 +0000 (+0000) Subject: patched Jmol and code for embedding JmolAppConsole in a JPanel (JAL-638) X-Git-Tag: Release_2_6~48 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=6486a5333807ca300db4a28a6bf9899f5dddf5a6 patched Jmol and code for embedding JmolAppConsole in a JPanel (JAL-638) --- diff --git a/.classpath b/.classpath index 82fde23..ccbed55 100644 --- a/.classpath +++ b/.classpath @@ -18,8 +18,7 @@ - - - + + diff --git a/appletlib/JmolApplet-12.1.11_dev_patched.jar b/appletlib/JmolApplet-12.1.11_dev_patched.jar new file mode 100644 index 0000000..5a7c6f2 Binary files /dev/null and b/appletlib/JmolApplet-12.1.11_dev_patched.jar differ diff --git a/appletlib/JmolApplet-12.1.5.jar b/appletlib/JmolApplet-12.1.5.jar deleted file mode 100644 index 42db0d3..0000000 Binary files a/appletlib/JmolApplet-12.1.5.jar and /dev/null differ diff --git a/lib/Jmol-12.1.5.jar b/lib/Jmol-12.1.11_dev_patched.jar similarity index 69% rename from lib/Jmol-12.1.5.jar rename to lib/Jmol-12.1.11_dev_patched.jar index 9f36d65..d4f255a 100644 Binary files a/lib/Jmol-12.1.5.jar and b/lib/Jmol-12.1.11_dev_patched.jar differ diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 3afa805..3a2abcf 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -113,4 +113,10 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } + @Override + public void showConsole(boolean show) + { + appletJmolBinding.showConsole(show); + } + } \ No newline at end of file diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index 53c2f1c..b7fb311 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -121,4 +121,11 @@ public class ExtJmol extends JalviewJmolBinding pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe); } } + + @Override + public void showConsole(boolean show) + { + // This never gets called because we haven't overriden the associated Jmol's console + System.err.println("WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="+show); + } } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 2c34762..c852a1a 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -24,6 +24,8 @@ import java.applet.Applet; import java.awt.*; import java.awt.event.*; +import javax.swing.JPanel; + import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.SequenceStructureBinding; @@ -36,6 +38,8 @@ import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; import org.jmol.viewer.JmolConstants; +import org.jmol.viewer.Viewer; +import org.openscience.jmol.app.jmolpanel.AppConsole; import jalview.schemes.*; @@ -982,7 +986,6 @@ public abstract class JalviewJmolBinding implements StructureListener, case JmolConstants.CALLBACK_MEASURE: case JmolConstants.CALLBACK_CLICK: - default: System.err.println("Unhandled callback " + type + " " + data[1].toString()); @@ -1289,6 +1292,11 @@ public abstract class JalviewJmolBinding implements StructureListener, public abstract void refreshGUI(); /** + * called to show or hide the associated console window container. + * @param show + */ + public abstract void showConsole(boolean show); + /** * @param renderPanel * @param jmolfileio * - when true will initialise jmol's file IO system (should be false @@ -1302,11 +1310,95 @@ public abstract class JalviewJmolBinding implements StructureListener, String htmlName, URL documentBase, URL codeBase, String commandOptions) { - viewer = JmolViewer.allocateViewer(renderPanel, + 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 htmlName + * @param documentBase + * @param codeBase + * @param commandOptions + * @param consolePanel - panel to contain Jmol console + * @param buttonsToShow - buttons to show on the console, in ordr + */ + public void allocateViewer(Component renderPanel, boolean jmolfileio, + String htmlName, URL documentBase, URL codeBase, + String commandOptions, final Container consolePanel, String buttonsToShow) + { + viewer = JmolViewer.allocateViewer(renderPanel, (jmolfileio ? new SmarterJmolAdapter() : null), htmlName + ((Object) this).toString(), documentBase, codeBase, commandOptions, this); + console = new AppConsole(viewer, null, consolePanel, + buttonsToShow); + viewer.setConsole(new JmolAppConsoleInterface() { + + @Override + public JmolScriptEditorInterface getScriptEditor() + { + return console.getScriptEditor(); + } + + @Override + public JmolAppConsoleInterface getAppConsole(Viewer viewer, + Component display) + { + return console; + } + + public String getText() + { + return console.getText(); + } + + @Override + public Object getMyMenuBar() + { + return console.getMyMenuBar(); + } + + @Override + public void setVisible(boolean b) + { + showConsole(b); + } + + @Override + public void sendConsoleEcho(String strEcho) + { + console.sendConsoleEcho(strEcho); + + } + + @Override + public void sendConsoleMessage(String strInfo) + { + console.sendConsoleMessage(strInfo); + } + + @Override + public void zap() + { + console.zap(); + } + + @Override + public void dispose() + { + console.dispose(); + } + + + }); + + } + + protected org.jmol.api.JmolAppConsoleInterface console = null; public void setLoadingFromArchive(boolean loadingFromArchive) { diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 74a9c22..0cc04f7 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -40,6 +40,7 @@ import org.jmol.api.*; import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; import org.jmol.viewer.JmolConstants; +import org.openscience.jmol.app.jmolpanel.AppConsole; public class AppJmol extends GStructureViewer implements Runnable, SequenceStructureBinding @@ -47,8 +48,8 @@ public class AppJmol extends GStructureViewer implements Runnable, { AppJmolBinding jmb; - ScriptWindow scriptWindow; - + JPanel scriptWindow; + JSplitPane splitPane; RenderPanel renderPanel; @@ -332,7 +333,15 @@ public class AppJmol extends GStructureViewer implements Runnable, this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER); jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(), getBounds().width, getBounds().height); - jmb.allocateViewer(renderPanel, true, "", null, null, ""); + if (scriptWindow == null) + { + BorderLayout bl = new BorderLayout(); + bl.setHgap(0); + bl.setVgap(0); + scriptWindow = new JPanel(bl); + }; + + jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow, null); jmb.newJmolPopup(true, "Jmol", true); jmb.evalStateCommand(command); jmb.setFinishedInit(true); @@ -777,11 +786,8 @@ public class AppJmol extends GStructureViewer implements Runnable, { } } - public void showConsole(boolean showConsole) { - if (scriptWindow == null) - scriptWindow = new ScriptWindow(this); if (showConsole) { @@ -791,15 +797,19 @@ public class AppJmol extends GStructureViewer implements Runnable, splitPane.setTopComponent(renderPanel); splitPane.setBottomComponent(scriptWindow); this.getContentPane().add(splitPane, BorderLayout.CENTER); + splitPane.setDividerLocation(getHeight() - 200); + scriptWindow.setVisible(true); + scriptWindow.validate(); + splitPane.validate(); } - splitPane.setDividerLocation(getHeight() - 200); - splitPane.validate(); } else { if (splitPane != null) - splitPane.setVisible(false); + { + splitPane.setVisible(false); + } splitPane = null; diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 5727386..2a0e2a7 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -5,11 +5,14 @@ package jalview.gui; import java.util.BitSet; +import javax.swing.JPanel; + import jalview.bin.Cache; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import org.jmol.popup.JmolPopup; +import org.openscience.jmol.app.jmolpanel.AppConsole; public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding { @@ -53,19 +56,19 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding public void sendConsoleEcho(String strEcho) { - if (appJmolWindow.scriptWindow != null) + if (console != null) { - appJmolWindow.scriptWindow.sendConsoleEcho(strEcho); + console.sendConsoleEcho(strEcho); } } public void sendConsoleMessage(String strStatus) { - if (appJmolWindow.scriptWindow != null && strStatus != null) + if (console != null && strStatus != null) // && !strStatus.equals("Script completed")) // should we squash the script completed string ? { - appJmolWindow.scriptWindow.sendConsoleMessage(strStatus); + console.sendConsoleMessage(strStatus); } } @@ -104,9 +107,10 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding public void notifyScriptTermination(String strStatus, int msWalltime) { - if (appJmolWindow.scriptWindow != null) - appJmolWindow.scriptWindow.notifyScriptTermination(strStatus, - msWalltime); + // todo - script termination doesn't happen ? + //if (console != null) + //console.notifyScriptTermination(strStatus, + // msWalltime); } public void showUrl(String url) @@ -134,6 +138,9 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } + public void showConsole(boolean b) { + appJmolWindow.showConsole(b); + } /** * add the given sequences to the mapping scope for the given pdb file handle @@ -153,5 +160,4 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } } } - } \ No newline at end of file