JAL-3364 tweaks to override of FIGURE_FIXEDIDWIDTH for split frame image
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index b77f9db..c1d4249 100644 (file)
@@ -565,9 +565,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   /**
    * update alignment layout for viewport settings
-   * 
-   * @param wrap
-   *          DOCUMENT ME!
    */
   public void updateLayout()
   {
@@ -614,6 +611,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     idSpaceFillerPanel1.setVisible(!wrap);
 
+    AlignViewportI complement = av.getCodingComplement();
+    if (complement != null)
+    {
+      SplitFrame splitFrame = (SplitFrame) alignFrame
+              .getSplitViewContainer();
+      splitFrame.adjustLayout();
+    }
     repaint();
   }
 
@@ -1077,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())
     {
@@ -1098,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);
 
@@ -1129,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);
 
@@ -1211,8 +1216,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     * split frame with 'protein scaled to codons' and 'auto id width'
     */
 
-    final boolean autoIdWidth = Cache.getDefault("FIGURE_AUTOIDWIDTH",
-            false);
+    final String autoIdWidth = Cache.getProperty("FIGURE_AUTOIDWIDTH");
     final Integer fixedIdWidth = Cache
             .getIntegerProperty("FIGURE_FIXEDIDWIDTH");
 
@@ -1222,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 (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);
@@ -1278,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,
@@ -1304,12 +1314,25 @@ public class AlignmentPanel extends GAlignmentPanel implements
     } finally
     {
       /*
-       * restore preference settings in case they were fudged
+       * restore preference settings in case they were overridden
        */
-      Cache.setProperty("FIGURE_AUTOIDWIDTH",
-              String.valueOf(autoIdWidth));
-      Cache.setProperty("FIGURE_FIXEDIDWIDTH",
-              String.valueOf(fixedIdWidth));
+      if (autoIdWidth == null)
+      {
+        Cache.removeProperty("FIGURE_AUTOIDWIDTH");
+      }
+      else
+      {
+        Cache.setProperty("FIGURE_AUTOIDWIDTH", autoIdWidth);
+      }
+      if (fixedIdWidth == null)
+      {
+        Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
+      }
+      else
+      {
+        Cache.setProperty("FIGURE_FIXEDIDWIDTH",
+                String.valueOf(fixedIdWidth));
+      }
     }
   }