From: James Procter Date: Thu, 6 Jul 2023 14:23:29 +0000 (+0100) Subject: JAL-4217 wrap imageExport CLI method's call to imageExport in an invokeAndWait X-Git-Tag: Release_2_11_4_0~252 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4e0bf08fc16e9388bb76cdd3eac84d767d102690;p=jalview.git JAL-4217 wrap imageExport CLI method's call to imageExport in an invokeAndWait --- 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