JAL-3364 align split frame sequence panels with wrapped view scale left
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 3c86653..716c237 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();
   }
 
@@ -1205,21 +1209,42 @@ public class AlignmentPanel extends GAlignmentPanel implements
                 { type.getLabel() }), pSessionId);
       }
     }
+
+    /*
+    * cache preferences in case we need to fudge them for export of
+    * split frame with 'protein scaled to codons' and 'auto id width'
+    */
+
+    final String autoIdWidth = Cache.getProperty("FIGURE_AUTOIDWIDTH");
+    final Integer fixedIdWidth = Cache
+            .getIntegerProperty("FIGURE_FIXEDIDWIDTH");
+
     try
     {
       /*
        * 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)
        */
-      AlignmentPanel comp = null;
+      AlignmentPanel complement = null;
       AlignmentDimension dim1 = getAlignmentDimension();
       AlignmentDimension dim2 = new AlignmentDimension(0, 0);
+
       if (forSplitFrame)
       {
-        comp = ((AlignViewport) av.getCodingComplement())
+        complement = ((AlignViewport) av.getCodingComplement())
                 .getAlignPanel();
-        dim2 = comp.getAlignmentDimension();
+        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)));
+        }
       }
       final int graphicsHeight = dim1.height + dim2.height
               + borderBottomOffset;
@@ -1258,12 +1283,12 @@ public class AlignmentPanel extends GAlignmentPanel implements
         // graphics.drawString("Hello world", 0, 0);
         if (av.getCodingComplement().getWrapAlignment())
         {
-          comp.printWrappedAlignment(dim2.width,
+          complement.printWrappedAlignment(dim2.width,
                   dim2.height + borderBottomOffset, 0, graphics, false);
         }
         else
         {
-          comp.printUnwrapped(dim2.width, dim2.height, 0, graphics,
+          complement.printUnwrapped(dim2.width, dim2.height, 0, graphics,
                   graphics);
         }
       }
@@ -1279,6 +1304,28 @@ public class AlignmentPanel extends GAlignmentPanel implements
     } catch (Exception ex)
     {
       ex.printStackTrace();
+    } finally
+    {
+      /*
+       * restore preference settings in case they were fudged
+       */
+      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));
+      }
     }
   }