update to Jmol series 12 (JAL-582)
[jalview.git] / src / jalview / appletgui / AppletJmol.java
index caaffa2..28eb61a 100644 (file)
@@ -29,6 +29,8 @@ import org.jmol.api.*;
 import org.jmol.adapter.smarter.SmarterJmolAdapter;
 
 import org.jmol.popup.*;
+import org.jmol.viewer.JmolConstants;
+
 import jalview.schemes.*;
 
 public class AppletJmol extends EmbmenuFrame implements StructureListener,
@@ -187,14 +189,10 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
     embedMenuIfNeeded(renderPanel);
     this.add(renderPanel, BorderLayout.CENTER);
     viewer = JmolViewer.allocateViewer(renderPanel,
-            new SmarterJmolAdapter());
-
-    viewer.setAppletContext("jalview", ap.av.applet.getDocumentBase(),
-            ap.av.applet.getCodeBase(), null);
-
-    viewer.setJmolStatusListener(this);
+            new SmarterJmolAdapter(), "jalviewJmol", ap.av.applet.getDocumentBase(),
+            ap.av.applet.getCodeBase(), "", this);
 
-    jmolpopup = JmolPopup.newJmolPopup(viewer);
+    jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
 
     this.addWindowListener(new WindowAdapter()
     {
@@ -706,13 +704,8 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
   {
   }
 
-  public void setCallbackFunction(String callbackType,
-          String callbackFunction)
-  {
-  }
-
   public void notifyFileLoaded(String fullPathName, String fileName,
-          String modelName, Object clientFile, String errorMsg)
+          String modelName, String errorMsg, int modelParts)
   {
     if (errorMsg != null)
     {
@@ -725,6 +718,7 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
 
     if (fileName != null)
     {
+      // TODO: do some checking using the modelPts number of parts against our own estimate of the number of chains
       // FILE LOADED OK
       jmolpopup.updateComputedMenus();
       viewer
@@ -786,15 +780,6 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
       return;
   }
 
-  public void notifyFrameChanged(int frameNo)
-  {
-    boolean isAnimationRunning = (frameNo <= -2);
-  }
-
-  public void notifyScriptStart(String statusMessage, String additionalInfo)
-  {
-  }
-
   public void sendConsoleEcho(String strEcho)
   {
     if (scriptWindow == null)
@@ -823,16 +808,15 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
 
   public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
   {
-    notifyAtomPicked(iatom, strMeasure);
-  }
-
-  public void notifyNewDefaultModeMeasurement(int count, String strInfo)
-  {
+    notifyAtomPicked(iatom, strMeasure, null);
   }
 
-  public void notifyAtomPicked(int atomIndex, String strInfo)
+  public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
   {
-
+    if (strData!=null)
+    {
+      System.err.println("Ignoring additional pick data string "+strData);
+    }
     int chainSeparator = strInfo.indexOf(":");
 
     if (chainSeparator == -1)
@@ -845,7 +829,7 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
       picked += strInfo.substring(strInfo.indexOf(":") + 1, strInfo
               .indexOf("."));
 
-    picked += ".CA";
+    picked = "(("+picked+".CA" + ")|("+picked+".P"+"))";
 
     if (!atomsPicked.contains(picked))
     {
@@ -859,14 +843,15 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
     }
   }
 
-  public void notifyAtomHovered(int atomIndex, String strInfo)
+  public void notifyAtomHovered(int atomIndex, String strInfo, String data)
   {
+    if (data!=null)
+    {
+      System.err.println("Ignoring additional hover info: "+data);
+    }
     mouseOverStructure(atomIndex, strInfo);
   }
 
-  public void sendSyncScript(String script, String appletName)
-  {
-  }
 
   public void showUrl(String url)
   {
@@ -898,9 +883,9 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
     validate();
   }
 
-  public float functionXY(String functionName, int x, int y)
+  public float[][] functionXY(String functionName, int x, int y)
   {
-    return 0;
+    return null ;
   }
 
   // /End JmolStatusListener
@@ -937,4 +922,97 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener,
     }
   }
 
+  @Override
+  public String createImage(String fileName, String type,
+          Object textOrBytes, int quality)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public Hashtable getRegistryInfo()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void notifyCallback(int type, Object[] data)
+  {
+    try {
+    switch (type)
+    {
+    case JmolConstants.CALLBACK_LOADSTRUCT:
+      notifyFileLoaded((String) data[1], (String) data[2], 
+              (String) data[3], (String) data[4], ((Integer) data[5]).intValue());
+              
+      break;
+    case JmolConstants.CALLBACK_PICK:
+      notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1], (String) data[0]);
+      // also highlight in alignment
+    case JmolConstants.CALLBACK_HOVER:
+      notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1], (String) data[0]);
+      break;
+    case JmolConstants.CALLBACK_SCRIPT:
+      notifyScriptTermination((String)data[2], ((Integer)data[3]).intValue());
+      break;
+    case JmolConstants.CALLBACK_ECHO:
+      sendConsoleEcho((String)data[1]);
+      break;
+    case JmolConstants.CALLBACK_MESSAGE:
+      sendConsoleMessage((data==null) ? ((String) null) : (String)data[1]);
+      break;
+    case JmolConstants.CALLBACK_MEASURE:
+    case JmolConstants.CALLBACK_CLICK:
+      default:
+        System.err.println("Unhandled callback "+type+" "+data);
+        break;
+    }
+    }
+    catch (Exception e)
+    {
+      System.err.println("Squashed Jmol callback handler error:");
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public boolean notifyEnabled(int callbackPick)
+  {
+    switch (callbackPick)
+    {
+    case JmolConstants.CALLBACK_ECHO:
+    case JmolConstants.CALLBACK_LOADSTRUCT:
+    case JmolConstants.CALLBACK_MEASURE:
+    case JmolConstants.CALLBACK_MESSAGE:
+    case JmolConstants.CALLBACK_PICK:
+    case JmolConstants.CALLBACK_SCRIPT:
+    case JmolConstants.CALLBACK_HOVER:
+    case JmolConstants.CALLBACK_ERROR:
+      return true;
+    case JmolConstants.CALLBACK_CLICK:
+      case JmolConstants.CALLBACK_ANIMFRAME:
+    case JmolConstants.CALLBACK_MINIMIZATION:
+    case JmolConstants.CALLBACK_RESIZE:
+    case JmolConstants.CALLBACK_SYNC:
+    }
+    return false;
+  }
+
+  @Override
+  public void setCallbackFunction(String callbackType,
+          String callbackFunction)
+  {
+    System.err.println("Ignoring set-callback request to associate "+callbackType+" with function "+callbackFunction);
+    
+  }
+
 }