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;
};
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