new ajax api methods for linking existing jmol viewers with sequences in an alignframe
[jalview.git] / src / jalview / gui / AppJmol.java
index c18015a..7945fa7 100644 (file)
@@ -26,6 +26,7 @@ import java.awt.event.*;
 import java.io.*;
 
 import jalview.jbgui.GStructureViewer;
+import jalview.bin.Cache;
 import jalview.datamodel.*;
 import jalview.gui.*;
 import jalview.structure.*;
@@ -37,6 +38,7 @@ import jalview.ws.ebi.EBIFetchClient;
 import org.jmol.api.*;
 import org.jmol.adapter.smarter.SmarterJmolAdapter;
 import org.jmol.popup.*;
+import org.jmol.viewer.JmolConstants;
 
 public class AppJmol extends GStructureViewer implements StructureListener,
         JmolStatusListener, Runnable
@@ -84,7 +86,6 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     pdbentry = new PDBEntry();
     pdbentry.setFile(file);
     pdbentry.setId(id);
-    this.chains = chains;
     this.sequence = seq;
     this.ap = ap;
     this.setBounds(bounds);
@@ -226,15 +227,13 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     this.setTitle(title.toString());
     jalview.gui.Desktop.addInternalFrame(this, title.toString(),
             getBounds().width, getBounds().height);
+    // * OK, but safer to assign htmlName, URL bases, comandOptions, and
+    // statusListener now.
 
     viewer = org.jmol.api.JmolViewer.allocateViewer(renderPanel,
-            new SmarterJmolAdapter());
+            new SmarterJmolAdapter(), "", null, null, "", this);
 
-    viewer.setAppletContext("", null, null, "");
-
-    viewer.setJmolStatusListener(this);
-
-    jmolpopup = JmolPopup.newJmolPopup(viewer);
+    jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
 
     viewer.evalStringQuiet(command);
   }
@@ -779,13 +778,8 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     System.out.println("JMOL CREATE IMAGE");
   }
 
-  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)
     {
@@ -798,7 +792,7 @@ public class AppJmol extends GStructureViewer 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
       ssm = StructureSelectionManager.getStructureSelectionManager();
       MCview.PDBfile pdbFile = ssm.setMapping(sequence, chains, pdbentry
@@ -830,15 +824,6 @@ public class AppJmol extends GStructureViewer 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)
@@ -864,15 +849,15 @@ public class AppJmol extends GStructureViewer implements StructureListener,
 
   public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
   {
-    notifyAtomPicked(iatom, strMeasure);
+    notifyAtomPicked(iatom, strMeasure, null);
   }
 
-  public void notifyNewDefaultModeMeasurement(int count, String strInfo)
-  {
-  }
-
-  public void notifyAtomPicked(int atomIndex, String strInfo)
+  public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
   {
+    if (strData!=null)
+    {
+      Cache.log.info("Non null pick data string: "+strData+" (other info: '"+strInfo+"' pos "+atomIndex+")");
+    }
     Matcher matcher = pattern.matcher(strInfo);
     matcher.find();
 
@@ -885,7 +870,7 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     if (chainId != null)
       picked += (":" + chainId.substring(1, chainId.length()));
 
-    picked += ".CA";
+    picked = "(("+picked+".CA" + ")|("+picked+".P"+"))";
 
     if (!atomsPicked.contains(picked))
     {
@@ -908,17 +893,25 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     }
   }
 
-  public void notifyAtomHovered(int atomIndex, String strInfo)
+  public void notifyAtomHovered(int atomIndex, String strInfo, String data)
   {
+    if (data!=null)
+    {
+      Cache.log.info("Non null hover data string: "+data+" (other info: '"+strInfo+"' pos "+atomIndex+")");
+    }
     mouseOverStructure(atomIndex, strInfo);
   }
 
-  public void sendSyncScript(String script, String appletName)
-  {
-  }
-
+  @Override
   public void showUrl(String url)
   {
+    try {
+      jalview.util.BrowserLauncher.openURL(url);
+    } catch (IOException e)
+    {
+      Cache.log.error("Failed to launch Jmol-associated url "+url,e);
+      // TODO: 2.6 : warn user if browser was not configured.
+    }
   }
 
   public void showConsole(boolean showConsole)
@@ -952,9 +945,9 @@ public class AppJmol extends GStructureViewer 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
@@ -1006,4 +999,96 @@ public class AppJmol extends GStructureViewer implements StructureListener,
     return viewId;
   }
 
+  @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)
+    {
+      Cache.log.warn("Squashed Jmol callback handler error: ",e);
+    }
+  }
+
+  @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)
+  {
+    Cache.log.debug("Ignoring set-callback request to associate "+callbackType+" with function "+callbackFunction);
+    
+  }
+
 }