From 4e0bf08fc16e9388bb76cdd3eac84d767d102690 Mon Sep 17 00:00:00 2001 From: James Procter Date: Thu, 6 Jul 2023 15:23:29 +0100 Subject: [PATCH] JAL-4217 wrap imageExport CLI method's call to imageExport in an invokeAndWait --- src/jalview/gui/AppJmol.java | 47 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 1758b5b..a14fabb 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -28,6 +28,7 @@ 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; @@ -472,11 +473,49 @@ 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); - + // 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() + { + @Override + public void run() + { + try + { + exporter.doExport(file, us, width, height, view, renderer, + userBis); + } catch (Throwable t) + { + exceptions[0] = t; + } + } + }); + } catch (InvocationTargetException 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) + { + if (exceptions[0] instanceof ImageOutputException) + { + throw ((ImageOutputException) exceptions[0]); + } + else + { + throw new ImageOutputException( + "Unexpected error when generating image", exceptions[0]); + } + } } @Override -- 1.7.10.2