patched Jmol and code for embedding JmolAppConsole in a JPanel (JAL-638)
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index 2c34762..c852a1a 100644 (file)
@@ -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)
   {