JAL-3364 initial version of export split frame
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sun, 14 Jul 2019 14:14:23 +0000 (15:14 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sun, 14 Jul 2019 14:14:23 +0000 (15:14 +0100)
src/jalview/gui/AlignmentPanel.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/math/AlignmentDimension.java

index 92b9a50..b554343 100644 (file)
@@ -1151,7 +1151,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
   {
-    int boarderBottomOffset = 5;
+    int borderBottomOffset = 5;
     long pSessionId = System.currentTimeMillis();
     headless = (System.getProperty("java.awt.headless") != null
             && System.getProperty("java.awt.headless").equals("true"));
@@ -1166,7 +1166,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
     try
     {
-      AlignmentDimension aDimension = getAlignmentDimension();
+      // todo splitFrame a parameter (optional menu item choice)
+      boolean splitFrame = av.getCodingComplement() != null;
+      AlignmentDimension aDimension = getAlignmentDimension(splitFrame);
       try
       {
         jalview.util.ImageMaker im;
@@ -1188,30 +1190,48 @@ public class AlignmentPanel extends GAlignmentPanel implements
         }
 
         im = new jalview.util.ImageMaker(this, type, imageAction,
-                aDimension.getWidth(),
-                aDimension.getHeight() + boarderBottomOffset, file,
+                aDimension.width, aDimension.height + borderBottomOffset,
+                file,
                 imageTitle, alignFrame, pSessionId, headless);
         Graphics graphics = im.getGraphics();
-        if (av.getWrapAlignment())
+        if (graphics != null)
         {
-          if (graphics != null)
+          if (av.getWrapAlignment())
           {
-            printWrappedAlignment(aDimension.getWidth(),
-                    aDimension.getHeight() + boarderBottomOffset, 0,
+            printWrappedAlignment(aDimension.width,
+                    aDimension.height + borderBottomOffset, 0,
                     graphics);
-            im.writeImage();
           }
-        }
-        else
-        {
-          if (graphics != null)
+          else
           {
-            printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
+            printUnwrapped(aDimension.width, aDimension.height, 0,
                     graphics, graphics);
-            im.writeImage();
           }
-        }
 
+          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);
+            }
+          }
+
+          im.writeImage();
+        }
       } catch (OutOfMemoryError err)
       {
         // Be noisy here.
@@ -1229,7 +1249,55 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
   }
 
-  public AlignmentDimension getAlignmentDimension()
+  /**
+   * 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)
+    {
+      return d1;
+    }
+    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);
+  }
+
+  /**
+   * 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>
+   * 
+   * @return
+   */
+  AlignmentDimension getAlignmentDimension()
   {
     int maxwidth = av.getAlignment().getVisibleWidth();
 
@@ -1260,8 +1328,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
       height += getAnnotationPanel().adjustPanelHeight() + 3;
     }
-    return new AlignmentDimension(width, height);
 
+    return new AlignmentDimension(width, height);
   }
 
   /**
index 948578a..6ebe287 100644 (file)
@@ -238,11 +238,11 @@ public class HtmlSvgOutput extends HTMLOutput
       setProgressMessage(null);
       setProgressMessage(MessageManager.formatMessage(
               "status.exporting_alignment_as_x_file", "HTML"));
-      AlignmentDimension aDimension = ap.getAlignmentDimension();
+      AlignmentDimension aDimension = ap.getAlignmentDimension(false);
       SVGGraphics2D idPanelGraphics = new SVGGraphics2D(
-              aDimension.getWidth(), aDimension.getHeight());
+              aDimension.width, aDimension.height);
       SVGGraphics2D alignPanelGraphics = new SVGGraphics2D(
-              aDimension.getWidth(), aDimension.getHeight());
+              aDimension.width, aDimension.height);
 
       String renderStyle = jalview.bin.Cache.getDefault("HTML_RENDERING",
               "Prompt each time");
@@ -271,12 +271,12 @@ public class HtmlSvgOutput extends HTMLOutput
       }
       if (ap.av.getWrapAlignment())
       {
-        printWrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
+        printWrapped(aDimension.width, aDimension.height, 0,
                 alignPanelGraphics);
       }
       else
       {
-        printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
+        printUnwrapped(aDimension.width, aDimension.height, 0,
                 idPanelGraphics, alignPanelGraphics);
       }
 
index b227f98..04e5ace 100644 (file)
@@ -22,34 +22,13 @@ package jalview.math;
 
 public class AlignmentDimension
 {
-  private int width;
+  public final int width;
 
-  private int height;
+  public final int height;
 
   public AlignmentDimension(int width, int height)
   {
     this.width = width;
     this.height = height;
   }
-
-  public int getWidth()
-  {
-    return width;
-  }
-
-  public void setWidth(int width)
-  {
-    this.width = width;
-  }
-
-  public int getHeight()
-  {
-    return height;
-  }
-
-  public void setHeight(int height)
-  {
-    this.height = height;
-  }
-
 }