JAL-3364 image export handle wrapped and/or unwrapped in split frame
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sun, 14 Jul 2019 19:37:11 +0000 (20:37 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sun, 14 Jul 2019 19:37:11 +0000 (20:37 +0100)
src/jalview/gui/AlignmentPanel.java
src/jalview/io/HtmlSvgOutput.java

index b554343..f2fdad3 100644 (file)
@@ -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
-   * <ul>
-   * <li>sequence ids</li>
-   * <li>scale above, left or right if shown</li>
-   * <li>sequences</li>
-   * <li>annotations, if shown</li> The alignment may be in wrapped or unwrapped
-   * mode.
-   * <ul>
-   * 
-   * @param splitFrame
-   *                     if true, the combined dimensions of a split frame view
-   *                     are computed: the sum of the two alignments' heights, and
-   *                     the larger of their widths. Any additional height (e.g.
-   *                     for frame titles) should be added separately.
-   * @return
-   */
-  public AlignmentDimension getAlignmentDimension(boolean splitFrame)
-  {
-    AlignmentDimension d1 = getAlignmentDimension();
-    if (!splitFrame)
+      im.writeImage();
+    } catch (OutOfMemoryError err)
     {
-      return d1;
+      // 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)
+    {
+      ex.printStackTrace();
     }
-    AlignmentPanel comp = ((AlignViewport) av.getCodingComplement())
-            .getAlignPanel();
-    AlignmentDimension d2 = comp.getAlignmentDimension();
-
-    int h = d1.height + d2.height;
-    int w = Math.max(d1.width, d2.width);
-
-    return new AlignmentDimension(w, h);
   }
 
   /**
@@ -1297,7 +1265,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * 
    * @return
    */
-  AlignmentDimension getAlignmentDimension()
+  public AlignmentDimension getAlignmentDimension()
   {
     int maxwidth = av.getAlignment().getVisibleWidth();
 
index 6ebe287..1325c10 100644 (file)
@@ -238,7 +238,7 @@ public class HtmlSvgOutput extends HTMLOutput
       setProgressMessage(null);
       setProgressMessage(MessageManager.formatMessage(
               "status.exporting_alignment_as_x_file", "HTML"));
-      AlignmentDimension aDimension = ap.getAlignmentDimension(false);
+      AlignmentDimension aDimension = ap.getAlignmentDimension();
       SVGGraphics2D idPanelGraphics = new SVGGraphics2D(
               aDimension.width, aDimension.height);
       SVGGraphics2D alignPanelGraphics = new SVGGraphics2D(