Merge branch 'bug/JAL-4353_cannot_output_multiple_different_structure_images_for_one_...
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 12 Dec 2023 20:55:49 +0000 (20:55 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 12 Dec 2023 20:55:49 +0000 (20:55 +0000)
src/jalview/gui/AppJmol.java
test/jalview/bin/CommandsTest.java

index 0aa4878..4d0de1b 100644 (file)
@@ -421,6 +421,14 @@ public class AppJmol extends StructureViewerBase
 
   }
 
+  public boolean isRepainting()
+  {
+    if (renderPanel!=null && renderPanel.isVisible())
+    {
+      return renderPanel.repainting;
+    }
+    return false;
+  }
   /**
    * Outputs the Jmol viewer image as an image file, after prompting the user to
    * choose a file and (for EPS) choice of Text or Lineart character rendering
@@ -431,6 +439,13 @@ public class AppJmol extends StructureViewerBase
   @Override
   public void makePDBImage(ImageMaker.TYPE type)
   {
+    while (!isRepainting())
+    {
+      try {
+        Thread.sleep(2);
+      } catch (Exception q)
+      {}
+    }
     try
     {
       makePDBImage(null, type, null,
@@ -627,10 +642,17 @@ public class AppJmol extends StructureViewerBase
       }
       else
       {
-        jmb.jmolViewer.renderScreenImage(g, currentSize.width,
-                currentSize.height);
+        repainting=true;
+        synchronized (jmb)
+        {
+          jmb.jmolViewer.renderScreenImage(g, currentSize.width,
+                  currentSize.height);
+          
+        }
+        repainting=false;
       }
     }
+    volatile boolean repainting=false;
   }
 
   @Override
index c4fbddb..7b42737 100644 (file)
@@ -116,7 +116,8 @@ public class CommandsTest
   }
   */
 
-  @Test(groups = { "Functional", "testTask3" }, dataProvider = "cmdLines")
+  @Test(groups = { "Functional", "testTask3" }, dataProvider = "cmdLines", singleThreaded = true)
+
   public void commandsOpenTest(String cmdLine, boolean cmdArgs,
           int numFrames, String[] sequences)
   {
@@ -168,7 +169,7 @@ public class CommandsTest
   @Test(
     groups =
     { "Functional", "testTask3" },
-    dataProvider = "structureImageOutputFiles")
+    dataProvider = "structureImageOutputFiles",    singleThreaded = true)
   public void structureImageOutputTest(String cmdLine, String[] filenames)
           throws IOException
   {
@@ -190,13 +191,17 @@ public class CommandsTest
         Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
                 + "' has no content from '" + cmdLine + "'");
         // make sure the successive output files get bigger!
-               if (lastFile != null) {
-                       Assert.assertTrue(Files.size(file.toPath()) > Files.size(lastFile.toPath()));
-                       System.out.println("this file: " + file + " +" + Files.size(file.toPath()) + " greater than "
-                                       + Files.size(lastFile.toPath()));
-               }
-               // remember it for next file
-               lastFile = file;
+        if (lastFile != null)
+        {
+          waitForLastWrite(file,25);
+          
+          if (Files.size(file.toPath()) > Files
+                  .size(lastFile.toPath()))
+          Assert.assertTrue(Files.size(file.toPath()) > Files
+                  .size(lastFile.toPath()));
+        }
+        // remember it for next file
+        lastFile = file;
       }
     } catch (Exception x)
     {
@@ -209,7 +214,22 @@ public class CommandsTest
     }
   }
 
-  @Test(groups = "Functional", dataProvider = "argfileOutputFiles")
+  private static long waitForLastWrite(File file, int i) throws IOException
+  {
+    long lastSize,stableSize =Files.size(file.toPath());
+    // wait around until we are sure the file has been completely written.
+    do {
+      lastSize = stableSize;
+      try {
+        Thread.sleep(i);
+      } catch (Exception x) {}
+      stableSize=Files.size(file.toPath());
+    } while (stableSize!=lastSize);
+    return stableSize;
+  }
+
+  @Test(groups = "Functional", dataProvider = "argfileOutputFiles", singleThreaded = true)
+
   public void argFilesGlobAndSubstitutionsTest(String cmdLine,
           String[] filenames) throws IOException
   {