Allows Jmol to share cached files
[jalview.git] / src / jalview / gui / AppJmol.java
index 7179a18..f937f22 100644 (file)
@@ -140,7 +140,7 @@ public class AppJmol extends StructureViewerBase
         closeViewer(false);
       }
     });
-    initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
+    initJmol(loadStatus, null); // pdbentry, seq, JBPCHECK!
   }
 
   @Override
@@ -199,8 +199,6 @@ public class AppJmol extends StructureViewerBase
     setSize(400, 400); // probably should be a configurable/dynamic default here
     initMenus();
     addingStructures = false;
-    worker = new Thread(this);
-    worker.start();
 
     this.addInternalFrameListener(new InternalFrameAdapter()
     {
@@ -212,6 +210,8 @@ public class AppJmol extends StructureViewerBase
       }
     });
 
+    worker = new Thread(this);
+    worker.start();
   }
 
   /**
@@ -231,7 +231,7 @@ public class AppJmol extends StructureViewerBase
   }
 
 
-  void initJmol(String command)
+  private void initJmol(String command, List<File> files)
   {
     jmb.setFinishedInit(false);
     renderPanel = new RenderPanel();
@@ -255,6 +255,8 @@ public class AppJmol extends StructureViewerBase
     if (command == null)
     {
       command = "";
+    } else if (files != null) {
+               jmb.cacheFiles(files);
     }
     jmb.evalStateCommand(command);
     jmb.evalStateCommand("set hoverDelay=0.1");
@@ -302,7 +304,7 @@ public class AppJmol extends StructureViewerBase
     _started = true;
     try
     {
-      List<String> files = fetchPdbFiles();
+      List<File> files = fetchPdbFiles();
       if (files.size() > 0)
       {
         showFilesInViewer(files);
@@ -321,12 +323,13 @@ public class AppJmol extends StructureViewerBase
    * @param files
    *          list of absolute paths to structure files
    */
-  void showFilesInViewer(List<String> files)
+  void showFilesInViewer(List<File> files)
   {
     long lastnotify = jmb.getLoadNotifiesHandled();
     StringBuilder fileList = new StringBuilder();
-    for (String s : files)
+    for (File f : files)
     {
+      String s = f.getAbsolutePath();
       fileList.append(SPACE).append(QUOTE)
               .append(Platform.escapeString(s)).append(QUOTE);
     }
@@ -336,7 +339,7 @@ public class AppJmol extends StructureViewerBase
     {
       try
       {
-        initJmol("load FILES " + filesString);
+        initJmol("load FILES " + filesString, files);
       } catch (OutOfMemoryError oomerror)
       {
         new OOMWarning("When trying to open the Jmol viewer!", oomerror);
@@ -359,6 +362,7 @@ public class AppJmol extends StructureViewerBase
 
       try
       {
+       jmb.cacheFiles(files);
         jmb.evalStateCommand(command);
       } catch (OutOfMemoryError oomerror)
       {
@@ -453,12 +457,12 @@ public class AppJmol extends StructureViewerBase
    * 
    * @return
    */
-  List<String> fetchPdbFiles()
+  List<File> fetchPdbFiles()
   {
     // todo - record which pdbids were successfully imported.
     StringBuilder errormsgs = new StringBuilder();
 
-    List<String> files = new ArrayList<>();
+    List<File> files = new ArrayList<>();
     String pdbid = "";
     try
     {
@@ -468,7 +472,7 @@ public class AppJmol extends StructureViewerBase
       Pdb pdbclient = new Pdb();
       for (int pi = 0; pi < jmb.getPdbCount(); pi++)
       {
-        String file = jmb.getPdbEntry(pi).getFile();
+        File file = jmb.getPdbEntry(pi).getFileF();
         if (file == null)
         {
           // todo: extract block as method and pull up (also ChimeraViewFrame)
@@ -506,7 +510,7 @@ public class AppJmol extends StructureViewerBase
             // just transfer the file name from the first sequence's first
             // PDBEntry
             file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
-                    .elementAt(0).getFile()).getAbsolutePath();
+                    .elementAt(0).getFile());
             jmb.getPdbEntry(pi).setFile(file);
             files.add(file);
           }
@@ -520,9 +524,10 @@ public class AppJmol extends StructureViewerBase
           if (filesInViewer != null && filesInViewer.length > 0)
           {
             addingStructures = true; // already files loaded.
+            String filename = file.getAbsolutePath();
             for (int c = 0; c < filesInViewer.length; c++)
             {
-              if (filesInViewer[c].equals(file))
+              if (filesInViewer[c].equals(filename))
               {
                 file = null;
                 break;