Merge branch 'Release_2_7_Branch' into develop
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 1 Mar 2012 12:07:04 +0000 (12:07 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 1 Mar 2012 12:07:04 +0000 (12:07 +0000)
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/gui/AppJmol.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/RestInputParamEditDialog.java
src/jalview/util/Platform.java
src/jalview/ws/rest/RestServiceDescription.java

index 90c28c7..7f949c7 100644 (file)
@@ -357,7 +357,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
       for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)\r
       {\r
         StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);\r
-\r
+        // RACE CONDITION - getMapping only returns Jmol loaded filenames once Jmol callback has completed. \r
         if (mapping == null || mapping.length < 1)\r
           continue;\r
 \r
@@ -690,10 +690,17 @@ public abstract class JalviewJmolBinding implements StructureListener,
       String mset[] = new String[viewer.getModelCount()];\r
       _modelFileNameMap = new int[mset.length];\r
       int j = 1;\r
-      mset[0] = viewer.getModelFileName(0);\r
+      String m=viewer.getModelFileName(0);\r
+      if (m!=null)\r
+      {\r
+        mset[0] = new File(m).getAbsolutePath();\r
+      }\r
       for (int i = 1; i < mset.length; i++)\r
       {\r
-        mset[j] = viewer.getModelFileName(i);\r
+        m=viewer.getModelFileName(i);\r
+        if (m!=null) {\r
+          mset[j] = new File(m).getAbsolutePath();\r
+        }\r
         _modelFileNameMap[j] = i; // record the model index for the filename\r
         // skip any additional models in the same file (NMR structures)\r
         if ((mset[j] == null ? mset[j] != mset[j - 1]\r
@@ -869,8 +876,17 @@ public abstract class JalviewJmolBinding implements StructureListener,
       try\r
       {\r
         // recover PDB filename for the model hovered over.\r
-        pdbfilename = viewer\r
-                .getModelFileName(new Integer(mdlId).intValue() - 1);\r
+        int _mp=_modelFileNameMap.length-1,\r
+                mnumber=new Integer(mdlId).intValue() - 1;\r
+        while(mnumber<_modelFileNameMap[_mp])\r
+        {\r
+          _mp--;\r
+        }\r
+        pdbfilename = modelFileNames[_mp];\r
+        if (pdbfilename==null) {pdbfilename=new File(viewer\r
+                .getModelFileName(mnumber)).getAbsolutePath();\r
+        }\r
+        \r
       } catch (Exception e)\r
       {\r
       }\r
@@ -1130,7 +1146,8 @@ public abstract class JalviewJmolBinding implements StructureListener,
           }\r
           else\r
           {\r
-            if (matches = pdbentry[pe].getFile().equals(fileName))\r
+            File fl;\r
+            if (matches = (fl=new File(pdbentry[pe].getFile())).equals(new File(fileName)))\r
             {\r
               foundEntry = true;\r
               // TODO: Jmol can in principle retrieve from CLASSLOADER but\r
@@ -1141,7 +1158,6 @@ public abstract class JalviewJmolBinding implements StructureListener,
               String protocol = AppletFormatAdapter.URL;\r
               try\r
               {\r
-                File fl = new java.io.File(pdbentry[pe].getFile());\r
                 if (fl.exists())\r
                 {\r
                   protocol = AppletFormatAdapter.FILE;\r
@@ -1151,9 +1167,10 @@ public abstract class JalviewJmolBinding implements StructureListener,
               } catch (Error e)\r
               {\r
               }\r
-              ;\r
+              //Explicitly map to the filename used by Jmol ;\r
               pdb = ssm.setMapping(sequence[pe], chains[pe],\r
-                      pdbentry[pe].getFile(), protocol);\r
+                      fileName, protocol);\r
+                      //pdbentry[pe].getFile(), protocol);\r
 \r
             }\r
           }\r
@@ -1164,7 +1181,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
             {\r
               String chid = new String(pdb.id + ":"\r
                       + ((MCview.PDBChain) pdb.chains.elementAt(i)).id);\r
-              chainFile.put(chid, pdbentry[pe].getFile());\r
+              chainFile.put(chid, fileName);\r
               chainNames.addElement(chid);\r
             }\r
             notifyLoaded = true;\r
index 955ad7b..e942b88 100644 (file)
@@ -35,6 +35,7 @@ import jalview.structure.*;
 import jalview.datamodel.PDBEntry;
 import jalview.io.*;
 import jalview.schemes.*;
+import jalview.util.Platform;
 
 public class AppJmol extends GStructureViewer implements Runnable,
         SequenceStructureBinding, ViewSetProvider
@@ -321,7 +322,6 @@ public class AppJmol extends GStructureViewer implements Runnable,
     openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
   }
   private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, SequenceI[][] seqs) {
-    boolean promptUser=pdbentrys.length==1;
     progressBar = ap.alignFrame;
     jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
     addAlignmentPanel(ap);
@@ -335,24 +335,11 @@ public class AppJmol extends GStructureViewer implements Runnable,
     setSize(400, 400); // probably should be a configurable/dynamic default here
     initMenus();
     worker=null;
-    String filelist="";
-//    for (PDBEntry pe: pdbentrys)
-//    {
-//      if (pe.getFile()==null)
       {
         addingStructures = false;
         worker = new Thread(this);
         worker.start();
-//        break;
       }
-//      filelist+=" \""+pe.getFile()+"\"";
-              
-/*    }
-    if (worker==null)
-    {
-      initJmol("load"+(pdbentrys.length>1 ? " APPEND" : "") + filelist);
-    }
-*/
     this.addInternalFrameListener(new InternalFrameAdapter()
     {
       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
@@ -736,9 +723,11 @@ public class AppJmol extends GStructureViewer implements Runnable,
           {
             // just transfer the file name from the first sequence's first
             // PDBEntry
-            jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
-                    .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
-            files.append(" \"" + file + "\"");
+            file = new File(((PDBEntry) pdbseq
+                    .getSequenceAt(0).getPDBId().elementAt(0)).getFile()).getAbsolutePath();
+            jmb.pdbentry[pi].setFile(file);
+            
+            files.append(" \"" + Platform.escapeString(file) + "\"");
           }
           else
           {
@@ -761,7 +750,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
           }
           if (file != null)
           {
-            files.append(" \"" + file + "\"");
+            files.append(" \"" + Platform.escapeString(file) + "\"");
           }
         }
       }
index dc1ef4f..6d55c32 100644 (file)
@@ -38,6 +38,7 @@ import jalview.datamodel.SequenceI;
 import jalview.schemabinding.version2.*;
 import jalview.schemes.*;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.Platform;
 import jalview.util.jarInputStreamProvider;
 
 /**
@@ -610,7 +611,8 @@ public class Jalview2XML
 
                 for (int smap = 0; smap < jmol.jmb.sequence[peid].length; smap++)
                 {
-                  if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
+//                  if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
+                  if (jds==jmol.jmb.sequence[peid][smap])
                   {
                     StructureState state = new StructureState();
                     state.setVisible(true);
@@ -1820,9 +1822,9 @@ public class Jalview2XML
         }
         ;
         out.close();
-
-        alreadyLoadedPDB.put(pdbId, outFile.getAbsolutePath());
-        return outFile.getAbsolutePath();
+        String t=outFile.getAbsolutePath();
+        alreadyLoadedPDB.put(pdbId, t);
+        return t;
       }
       else
       {
@@ -2624,12 +2626,13 @@ public class Jalview2XML
               }
               if (ids[p].getFile() != null)
               {
+                File mapkey=new File(ids[p].getFile());
                 Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2])
-                        .get(ids[p].getFile());
+                        .get(mapkey);
                 if (seqstrmaps == null)
                 {
                   ((Hashtable) jmoldat[2]).put(
-                          new File(ids[p].getFile()).toString(),
+                          mapkey,
                           seqstrmaps = new Object[]
                           { pdbFile, ids[p].getId(), new Vector(),
                               new Vector() });
@@ -2662,7 +2665,7 @@ public class Jalview2XML
           Object[] svattrib = entry.getValue();
           int[] geom = (int[]) svattrib[0];
           String state = (String) svattrib[1];
-          Hashtable<String, Object[]> oldFiles = (Hashtable<String, Object[]>) svattrib[2];
+          Hashtable<File, Object[]> oldFiles = (Hashtable<File, Object[]>) svattrib[2];
           final boolean useinJmolsuperpos = ((boolean[]) svattrib[3])[0], usetoColourbyseq = ((boolean[]) svattrib[3])[1], jmolColouring = ((boolean[]) svattrib[3])[2];
           int x = geom[0], y = geom[1], width = geom[2], height = geom[3];
           // collate the pdbfile -> sequence mappings from this view
@@ -2726,6 +2729,8 @@ public class Jalview2XML
               {
                 newFileLoc = new StringBuffer();
               }
+              do {
+                // look for next filename in load statement
               newFileLoc.append(state.substring(cp,
                       ncp = (state.indexOf("\"", ncp + 1) + 1)));
               String oldfilenam = state.substring(ncp,
@@ -2733,9 +2738,8 @@ public class Jalview2XML
               // recover the new mapping data for this old filename
               // have to normalize filename - since Jmol and jalview do filename
               // translation differently.
-              Object[] filedat = oldFiles.get(new File(oldfilenam)
-                      .toString());
-              newFileLoc.append(((String) filedat[0]));
+              Object[] filedat = oldFiles.get(new File(oldfilenam));
+              newFileLoc.append(Platform.escapeString((String) filedat[0]));
               pdbfilenames.addElement((String) filedat[0]);
               pdbids.addElement((String) filedat[1]);
               seqmaps.addElement((SequenceI[]) ((Vector<SequenceI>) filedat[2])
@@ -2743,6 +2747,7 @@ public class Jalview2XML
               newFileLoc.append("\"");
               cp = ecp + 1; // advance beyond last \" and set cursor so we can
                             // look for next file statement.
+              } while ((ncp=state.indexOf("/*file*/",cp))>-1);
             }
             if (cp > 0)
             {
@@ -2755,7 +2760,7 @@ public class Jalview2XML
                       .print("Ignoring incomplete Jmol state for PDB ids: ");
               newFileLoc = new StringBuffer(state);
               newFileLoc.append("; load append ");
-              for (String id : oldFiles.keySet())
+              for (File id : oldFiles.keySet())
               {
                 // add this and any other pdb files that should be present in
                 // the viewer
@@ -2853,7 +2858,7 @@ public class Jalview2XML
 
             // add mapping for sequences in this view to an already open Jmol
             // instance
-            for (String id : oldFiles.keySet())
+            for (File id : oldFiles.keySet())
             {
               // add this and any other pdb files that should be present in the
               // viewer
index 2fa931f..9cf73f4 100644 (file)
@@ -26,8 +26,6 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.event.ListSelectionEvent;
 
-import com.sun.tools.corba.se.idl.InvalidArgument;
-
 import net.miginfocom.swing.MigLayout;
 
 import jalview.jbgui.GRestInputParamEditDialog;
index 2218f5d..3e508eb 100644 (file)
@@ -51,4 +51,23 @@ public class Platform
     // TODO: determine nominal limits for most platforms.\r
     return 2046; // this is the max length for a windows NT system.\r
   }\r
+\r
+  /**\r
+   * escape a string according to the local platform's escape character\r
+   * @param file\r
+   * @return escaped file\r
+   */\r
+  public static String escapeString(String file)\r
+  {\r
+    StringBuffer f=new StringBuffer();\r
+    int p=0,lastp=0;\r
+    while ((p=file.indexOf('\\',lastp))>-1)\r
+    {\r
+      f.append(file.subSequence(lastp,p));\r
+      f.append("\\\\");\r
+      lastp=p+1;\r
+    }\r
+    f.append(file.substring(lastp));\r
+    return f.toString();\r
+  }\r
 }\r
index 7ae922c..e0c56da 100644 (file)
@@ -44,7 +44,6 @@ import javax.swing.JViewport;
 
 import com.stevesoft.pat.Regex;
 import com.sun.org.apache.xml.internal.serialize.OutputFormat.DTD;
-import com.sun.tools.doclets.internal.toolkit.util.DocFinder.Output;
 
 public class RestServiceDescription
 {