From 17c7bf45411f86b56a22499a233cf0dc8ae3498e Mon Sep 17 00:00:00 2001 From: gmungoc Date: Sun, 14 Jul 2019 20:37:11 +0100 Subject: [PATCH] JAL-3364 image export handle wrapped and/or unwrapped in split frame --- src/jalview/gui/AlignmentPanel.java | 178 ++++++++++++++--------------------- src/jalview/io/HtmlSvgOutput.java | 2 +- 2 files changed, 74 insertions(+), 106 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index b554343..f2fdad3 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1168,120 +1168,88 @@ public class AlignmentPanel extends GAlignmentPanel implements { // todo splitFrame a parameter (optional menu item choice) boolean splitFrame = av.getCodingComplement() != null; - AlignmentDimension aDimension = getAlignmentDimension(splitFrame); - try + AlignmentDimension dim1 = getAlignmentDimension(); + AlignmentDimension dim2 = new AlignmentDimension(0, 0); + if (splitFrame) { - jalview.util.ImageMaker im; - final String imageAction, imageTitle; - if (type == jalview.util.ImageMaker.TYPE.PNG) - { - imageAction = "Create PNG image from alignment"; - imageTitle = null; - } - else if (type == jalview.util.ImageMaker.TYPE.EPS) - { - imageAction = "Create EPS file from alignment"; - imageTitle = alignFrame.getTitle(); - } - else - { - imageAction = "Create SVG file from alignment"; - imageTitle = alignFrame.getTitle(); - } - - im = new jalview.util.ImageMaker(this, type, imageAction, - aDimension.width, aDimension.height + borderBottomOffset, - file, - imageTitle, alignFrame, pSessionId, headless); - Graphics graphics = im.getGraphics(); - if (graphics != null) - { - if (av.getWrapAlignment()) - { - printWrappedAlignment(aDimension.width, - aDimension.height + borderBottomOffset, 0, - graphics); - } - else - { - printUnwrapped(aDimension.width, aDimension.height, 0, - graphics, graphics); - } + AlignmentPanel comp = ((AlignViewport) av.getCodingComplement()) + .getAlignPanel(); + dim2 = comp.getAlignmentDimension(); + } + final int graphicsHeight = dim1.height + dim2.height; + final int graphicsWidth = Math.max(dim1.width, dim2.width); - if (splitFrame) - { - /* - * append coding complement image - * todo: always top frame first! - */ - int h = getAlignmentDimension(false).height; - graphics.translate(0, h); - AlignmentPanel comp = ((AlignViewport) av.getCodingComplement()) - .getAlignPanel(); - if (av.getCodingComplement().getWrapAlignment()) - { - comp.printWrappedAlignment(aDimension.width, - aDimension.height + borderBottomOffset, 0, graphics); - } - else - { - comp.printUnwrapped(aDimension.width, aDimension.height, 0, - graphics, graphics); - } - } + jalview.util.ImageMaker im; + final String imageAction, imageTitle; + if (type == jalview.util.ImageMaker.TYPE.PNG) + { + imageAction = "Create PNG image from alignment"; + imageTitle = null; + } + else if (type == jalview.util.ImageMaker.TYPE.EPS) + { + imageAction = "Create EPS file from alignment"; + imageTitle = alignFrame.getTitle(); + } + else + { + imageAction = "Create SVG file from alignment"; + imageTitle = alignFrame.getTitle(); + } - im.writeImage(); - } - } catch (OutOfMemoryError err) + im = new jalview.util.ImageMaker(this, type, imageAction, + graphicsWidth, graphicsHeight + borderBottomOffset, file, + imageTitle, alignFrame, pSessionId, headless); + Graphics graphics = im.getGraphics(); + if (graphics == null) { - // Be noisy here. - System.out.println("########################\n" + "OUT OF MEMORY " - + file + "\n" + "########################"); - new OOMWarning("Creating Image for " + file, err); - // System.out.println("Create IMAGE: " + err); - } catch (Exception ex) + return; + } + graphics.setColor(Color.white); + graphics.fillRect(0, 0, graphicsWidth, graphicsHeight); + if (av.getWrapAlignment()) { - ex.printStackTrace(); + printWrappedAlignment(dim1.width, dim1.height + borderBottomOffset, + 0, graphics); + } + else + { + printUnwrapped(dim1.width, dim1.height, 0, graphics, graphics); } - } finally - { - } - } + if (splitFrame) + { + /* + * append coding complement image + * todo: always write top frame first! + */ + graphics.translate(0, dim1.height); + AlignmentPanel comp = ((AlignViewport) av.getCodingComplement()) + .getAlignPanel(); + if (av.getCodingComplement().getWrapAlignment()) + { + comp.printWrappedAlignment(dim2.width, + dim2.height + borderBottomOffset, 0, graphics); + } + else + { + comp.printUnwrapped(dim2.width, dim2.height, 0, graphics, + graphics); + } + } - /** - * Computes and answers the width and height of the alignment in pixels, - * including - *