JAL-3364 tweaks to override of FIGURE_FIXEDIDWIDTH for split frame image feature/JAL-3364splitFrameImage
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 20 Aug 2019 09:07:26 +0000 (10:07 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 20 Aug 2019 09:07:26 +0000 (10:07 +0100)
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/SeqCanvas.java

index 716c237..c1d4249 100644 (file)
@@ -1081,8 +1081,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
   public int printWrappedAlignment(int pageWidth, int pageHeight, int pageNumber,
           Graphics g, boolean clipToPage)
   {
-    getSeqPanel().seqCanvas.calculateWrappedGeometry(getWidth(),
-            getHeight());
+    final SeqCanvas seqCanvas = getSeqPanel().seqCanvas;
+    seqCanvas.calculateWrappedGeometry(seqCanvas.getWidth(),
+            seqCanvas.getHeight());
     int annotationHeight = 0;
     if (av.isShowAnnotation())
     {
@@ -1102,7 +1103,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     int maxwidth = av.getAlignment().getVisibleWidth();
 
-    int resWidth = getSeqPanel().seqCanvas
+    int resWidth = seqCanvas
             .getWrappedCanvasWidth(pageWidth - idWidth);
     av.getRanges().setViewportStartAndWidth(0, resWidth);
 
@@ -1133,7 +1134,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     idCanvas.drawIdsWrapped((Graphics2D) g, av, 0, totalHeight);
 
     g.translate(idWidth, 0);
-    getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth,
+    seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth,
             totalHeight, 0);
     g.translate(-idWidth, 0);
 
@@ -1225,27 +1226,31 @@ public class AlignmentPanel extends GAlignmentPanel implements
        * if exporting a split frame image, the graphics object has 
        * width: maximum of the top and bottom image widths
        * height: sum of the top and bottom image heights
-       * if 'protein scaled to codons' and 'auto id width', fudge
-       * to a fixed width (and restore preferences afterwards)
+       * Any preferences for auto or fixed id width are overridden here
+       * with the actual id widths, and restored after export
        */
       AlignmentPanel complement = null;
-      AlignmentDimension dim1 = getAlignmentDimension();
-      AlignmentDimension dim2 = new AlignmentDimension(0, 0);
+      final int idWidth = getIdPanel().getWidth();
+      int complementIdWidth = 0;
 
       if (forSplitFrame)
       {
         complement = ((AlignViewport) av.getCodingComplement())
                 .getAlignPanel();
+        Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
+        Cache.setProperty("FIGURE_FIXEDIDWIDTH", String.valueOf(idWidth));
+      }
+      AlignmentDimension dim1 = getAlignmentDimension();
+      AlignmentDimension dim2 = new AlignmentDimension(0, 0);
+
+      if (forSplitFrame)
+      {
+        complementIdWidth = complement.getIdPanel().getWidth();
+        Cache.setProperty("FIGURE_FIXEDIDWIDTH", String.valueOf(complementIdWidth));
         dim2 = complement.getAlignmentDimension();
-        if (Boolean.valueOf(autoIdWidth) && av.isScaleProteinAsCdna())
-        {
-          int w1 = this.getVisibleIdWidth(false);
-          int w2 = complement.getVisibleIdWidth(false);
-          Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
-          Cache.setProperty("FIGURE_FIXEDIDWIDTH",
-                  String.valueOf(Math.max(w1, w2)));
-        }
+        Cache.setProperty("FIGURE_FIXEDIDWIDTH", String.valueOf(idWidth));
       }
+
       final int graphicsHeight = dim1.height + dim2.height
               + borderBottomOffset;
       final int graphicsWidth = Math.max(dim1.width, dim2.width);
@@ -1281,6 +1286,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
          */
         // to debug location of next write to Graphics:
         // graphics.drawString("Hello world", 0, 0);
+        Cache.setProperty("FIGURE_FIXEDIDWIDTH",
+                String.valueOf(complementIdWidth));
         if (av.getCodingComplement().getWrapAlignment())
         {
           complement.printWrappedAlignment(dim2.width,
@@ -1307,7 +1314,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     } finally
     {
       /*
-       * restore preference settings in case they were fudged
+       * restore preference settings in case they were overridden
        */
       if (autoIdWidth == null)
       {
index 5f67cb5..70afc5a 100755 (executable)
@@ -561,7 +561,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
   {
     int wrappedWidthInResidues = calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-
     av.setWrappedWidth(wrappedWidthInResidues);
 
     ViewportRanges ranges = av.getRanges();