patched Jmol and code for embedding JmolAppConsole in a JPanel (JAL-638)
authorjprocter <Jim Procter>
Mon, 13 Sep 2010 18:24:06 +0000 (18:24 +0000)
committerjprocter <Jim Procter>
Mon, 13 Sep 2010 18:24:06 +0000 (18:24 +0000)
.classpath
appletlib/JmolApplet-12.1.11_dev_patched.jar [new file with mode: 0644]
appletlib/JmolApplet-12.1.5.jar [deleted file]
lib/Jmol-12.1.11_dev_patched.jar [moved from lib/Jmol-12.1.5.jar with 69% similarity]
src/jalview/appletgui/AppletJmolBinding.java
src/jalview/appletgui/ExtJmol.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/gui/AppJmol.java
src/jalview/gui/AppJmolBinding.java

index 82fde23..ccbed55 100644 (file)
@@ -18,8 +18,7 @@
        <classpathentry kind="lib" path="lib/castor-1.1-cycle-xml.jar" sourcepath="C:/Documents and Settings/JimP/workspace-3.3/castor/src/main/java"/>
        <classpathentry kind="lib" path="lib/JGoogleAnalytics-0.2.1-SNAPSHOT.jar" sourcepath="/JGoogleAnalytics/src/main/java"/>
        <classpathentry kind="lib" path="lib/vamsas-client.jar"/>
-       <classpathentry kind="lib" path="lib/min-jaba-client.jar"/>
-       <classpathentry kind="lib" path="lib/Jmol-12.1.5.jar" sourcepath="D:/InstallsDir/Sources for Development/jmol-12.1.5"/>
-       <classpathentry kind="lib" path="appletlib/JmolApplet-12.1.5.jar" sourcepath="D:/InstallsDir/Sources for Development/jmol-12.1.5"/>
+       <classpathentry kind="lib" path="lib/min-jaba-client.jar" sourcepath="/clustengine/webservices"/>
+       <classpathentry kind="lib" path="lib/Jmol-12.1.11_dev_patched.jar"/>
        <classpathentry kind="output" path="classes"/>
 </classpath>
diff --git a/appletlib/JmolApplet-12.1.11_dev_patched.jar b/appletlib/JmolApplet-12.1.11_dev_patched.jar
new file mode 100644 (file)
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 (file)
index 42db0d3..0000000
Binary files a/appletlib/JmolApplet-12.1.5.jar and /dev/null differ
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 (file)
Binary files a/lib/Jmol-12.1.5.jar and b/lib/Jmol-12.1.11_dev_patched.jar differ
index 3afa805..3a2abcf 100644 (file)
@@ -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
index 53c2f1c..b7fb311 100644 (file)
@@ -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);
+  }
 }
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)
   {
index 74a9c22..0cc04f7 100644 (file)
@@ -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;
 
index 5727386..2a0e2a7 100644 (file)
@@ -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