Merge branch 'bug/JAL-4214_system_freeze_when_opening_file_using_gui_in_linux' into...
[jalview.git] / src / jalview / gui / AppJmol.java
index a14fabb..950f129 100644 (file)
@@ -32,6 +32,12 @@ 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;
@@ -365,9 +371,9 @@ public class AppJmol extends StructureViewerBase
       }
       if (waitTotal > waitMax)
       {
-        System.err.println("Timed out waiting for Jmol to load files after "
+        jalview.bin.Console.errPrintln("Timed out waiting for Jmol to load files after "
                 + waitTotal + "ms");
-        // System.err.println("finished: " + jmb.isFinishedInit()
+        // jalview.bin.Console.errPrintln("finished: " + jmb.isFinishedInit()
         // + "; loaded: " + Arrays.toString(jmb.getPdbFile())
         // + "; files: " + files.toString());
         jmb.getStructureFiles();
@@ -475,13 +481,13 @@ public class AppJmol extends StructureViewerBase
             .toLowerCase(Locale.ROOT);
     final ImageExporter exporter = new ImageExporter(writer,
             getProgressIndicator(), type, getTitle());
-    // hack to pass back and throw to caller
+    
     final Throwable[] exceptions = new Throwable[1];
     exceptions[0] = null;
     final AppJmol us = this;
     try
     {
-      SwingUtilities.invokeAndWait(new Runnable()
+      Thread runner = Executors.defaultThreadFactory().newThread(new Runnable()
       {
         @Override
         public void run()
@@ -496,13 +502,12 @@ public class AppJmol extends StructureViewerBase
           }
         }
       });
-    } catch (InvocationTargetException e)
+      runner.start();
+      do { Thread.sleep(25); } while (runner.isAlive());
+    } catch (Throwable e)
     {
       throw new ImageOutputException(
               "Unexpected error when generating image", e);
-    } catch (InterruptedException e)
-    {
-      Console.debug("Interrupted whilst waiting for image export", e);
     }
     if (exceptions[0] != null)
     {
@@ -527,7 +532,7 @@ public class AppJmol extends StructureViewerBase
               .openURL("http://wiki.jmol.org");// http://jmol.sourceforge.net/docs/JmolUserGuide/");
     } catch (Exception ex)
     {
-      System.err.println("Show Jmol help failed with: " + ex.getMessage());
+      jalview.bin.Console.errPrintln("Show Jmol help failed with: " + ex.getMessage());
     }
   }