Merge branch 'develop' into features/JAL-4220_showSymbolsBelowConsensusThresholdAsGaps features/JAL-4220_showSymbolsBelowConsensusThresholdAsGaps
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 6 Jul 2023 17:21:34 +0000 (18:21 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 6 Jul 2023 17:21:34 +0000 (18:21 +0100)
src/jalview/bin/Commands.java
src/jalview/gui/AppJmol.java
src/jalview/gui/Desktop.java
src/jalview/gui/ImageExporter.java
test/jalview/analysis/TestAlignSeq.java

index 7f493e0..84effe0 100644 (file)
@@ -574,17 +574,22 @@ public class Commands
             Console.error("Failed to import and open structure view.");
             continue;
           }
-          while (sv.isBusy())
+          try
           {
-            try {
-              Thread.sleep(25);
-            }
-            catch (Exception x)
             {
-              
+              while (sv.isBusy())
+                Thread.sleep(25);
+              if (sv.isBusy())
+              {
+                Console.debug(
+                        "Waiting for viewer for " + structureFilepath);
+              }
             }
-          }
+          } catch (Exception x)
+          {
 
+          }
+          Console.debug("Successfully opened viewer for "+structureFilepath);
           String structureImageFilename = ArgParser.getValueFromSubValOrArg(
                   avm, av, Arg.STRUCTUREIMAGE, subVals);
           if (sv != null && structureImageFilename != null)
@@ -624,12 +629,13 @@ public class Commands
             }
             BitmapImageSizing userBis = ImageMaker
                     .parseScaleWidthHeightStrings(scale, width, height);
+            // TODO MAKE THIS VIEWER INDEPENDENT!!
             switch (StructureViewer.getViewerType())
             {
             case JMOL:
               try
               {
-                Thread.sleep(1000);
+                Thread.sleep(1000); // WHY ???
               } catch (InterruptedException e)
               {
                 // TODO Auto-generated catch block
@@ -641,8 +647,11 @@ public class Commands
               {
                 AppJmol jmol = (AppJmol) sview;
                 try { 
+                  Console.debug("Rendering image to "+structureImageFile);
                   jmol.makePDBImage(structureImageFile, imageType, renderer,
                         userBis);
+                  Console.debug("Finished Rendering image to "+structureImageFile);
+
                 }
                 catch (ImageOutputException ioexc)
                 {
index 1758b5b..49eae98 100644 (file)
@@ -28,9 +28,16 @@ import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 import java.io.File;
+import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
 
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
@@ -472,11 +479,48 @@ public class AppJmol extends StructureViewerBase
     };
     String view = MessageManager.getString("action.view")
             .toLowerCase(Locale.ROOT);
-    ImageExporter exporter = new ImageExporter(writer,
+    final ImageExporter exporter = new ImageExporter(writer,
             getProgressIndicator(), type, getTitle());
     
-    exporter.doExport(file, this, width, height, view, renderer, userBis);
-    
+    final Throwable[] exceptions = new Throwable[1];
+    exceptions[0] = null;
+    final AppJmol us = this;
+    try
+    {
+      Thread runner = Executors.defaultThreadFactory().newThread(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          try
+          {
+            exporter.doExport(file, us, width, height, view, renderer,
+                    userBis);
+          } catch (Throwable t)
+          {
+            exceptions[0] = t;
+          }
+        }
+      });
+      runner.start();
+      do { Thread.sleep(25); } while (runner.isAlive());
+    } catch (Throwable e)
+    {
+      throw new ImageOutputException(
+              "Unexpected error when generating image", e);
+    }
+    if (exceptions[0] != null)
+    {
+      if (exceptions[0] instanceof ImageOutputException)
+      {
+        throw ((ImageOutputException) exceptions[0]);
+      }
+      else
+      {
+        throw new ImageOutputException(
+                "Unexpected error when generating image", exceptions[0]);
+      }
+    }
   }
 
   @Override
index 36d6434..12ff20b 100644 (file)
@@ -1078,7 +1078,36 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     setKeyBindings(frame);
 
-    desktop.add(frame);
+    // Since the latest FlatLaf patch, we occasionally have problems showing structureViewer frames...
+    int tries=3;
+    boolean shown=false;
+    Exception last=null;
+    do
+    {
+      try
+      {
+        desktop.add(frame);
+        shown=true;
+      } catch (IllegalArgumentException iaex)
+      {
+        last=iaex;
+        tries--;
+        jalview.bin.Console.info(
+                "Squashed IllegalArgument Exception (" + tries + " left) for "+frame.getTitle(),
+                iaex);
+        try
+        {
+          Thread.sleep(5);
+        } catch (InterruptedException iex)
+        {
+        }
+        ;
+      }
+    } while (!shown && tries > 0);
+    if (!shown)
+    {
+      jalview.bin.Console.error("Serious Problem whilst showing window "+frame.getTitle(),last);
+    }
 
     windowMenu.add(menuItem);
 
index f337b39..4ea30d9 100644 (file)
@@ -124,6 +124,11 @@ public class ImageExporter
      */
     if (file == null && !Jalview.isHeadlessMode())
     {
+      if (Desktop.instance.isInBatchMode())
+      {
+        // defensive error report - we could wait for user input.. I  guess ?
+        throw(new ImageOutputException("Need an output file to render to when exporting images in batch mode!"));
+      }
       JalviewFileChooser chooser = imageType.getFileChooser();
       chooser.setFileView(new JalviewFileView());
       MessageManager.formatMessage("label.create_image_of",
index 62250eb..44bea81 100644 (file)
@@ -121,7 +121,9 @@ public class TestAlignSeq
     assertEquals(as.getAStr1(), as.getAStr2().toUpperCase(Locale.ROOT));
 
     Mapping s1tos2 = as.getMappingFromS1(false);
-    checkMapping(s1tos2,s1,ns2);
+    assertEquals("ASdFA",as.getAStr2());
+    // verify mapping is consistent between original all-caps sequences
+    checkMapping(s1tos2,s1,s2);
   }
 
   @Test(groups = { "Functional" })