From af1bb2283d7b4efb3d1f487d2831178b39f075fd Mon Sep 17 00:00:00 2001 From: James Procter Date: Thu, 6 Jul 2023 16:00:03 +0100 Subject: [PATCH] =?utf8?q?JAL-4217=20wrap=20imageExport=20CLI=20method's=20c?= =?utf8?q?all=20to=20imageExport=20in=20a=20separate=20thread=20and=20hang=20?= =?utf8?q?around=20until=20it=20completes=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/gui/AppJmol.java | 16 ++++++++++------ src/jalview/gui/ImageExporter.java | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index a14fabb..930a750 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -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; @@ -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,11 @@ public class AppJmol extends StructureViewerBase } } }); - } catch (InvocationTargetException e) + 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) { diff --git a/src/jalview/gui/ImageExporter.java b/src/jalview/gui/ImageExporter.java index f337b39..4ea30d9 100644 --- a/src/jalview/gui/ImageExporter.java +++ b/src/jalview/gui/ImageExporter.java @@ -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", -- 1.7.10.2