JAL-3087 include full alignment height in repeating wrapped height
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 24 Aug 2018 14:32:44 +0000 (15:32 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 28 Aug 2018 15:23:16 +0000 (16:23 +0100)
src/jalview/gui/SeqCanvas.java
test/jalview/gui/SeqCanvasTest.java

index 8f315bd..1753a64 100755 (executable)
@@ -658,7 +658,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
     calculateWrappedGeometry(canvasWidth, canvasHeight);
 
     /*
     calculateWrappedGeometry(canvasWidth, canvasHeight);
 
     /*
-     * draw one width at a time (including any scales or annotation shown),
+     * draw one width at a time (excluding any scales or annotation shown),
      * until we have run out of either alignment or vertical space available
      */
     int ypos = wrappedSpaceAboveAlignment;
      * until we have run out of either alignment or vertical space available
      */
     int ypos = wrappedSpaceAboveAlignment;
@@ -709,7 +709,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
      */
     wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
     // add sequences
      */
     wrappedRepeatHeightPx = wrappedSpaceAboveAlignment;
     // add sequences
-    wrappedRepeatHeightPx += av.getRanges().getViewportHeight()
+    wrappedRepeatHeightPx += av.getAlignment().getHeight()
             * charHeight;
     // add annotations panel height if shown
     wrappedRepeatHeightPx += getAnnotationHeight();
             * charHeight;
     // add annotations panel height if shown
     wrappedRepeatHeightPx += getAnnotationHeight();
index ee1270e..bcb1cfd 100644 (file)
@@ -48,17 +48,17 @@ public class SeqCanvasTest
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
     assertEquals(al.getHeight(), 15);
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
     assertEquals(al.getHeight(), 15);
+    av.getRanges().setStartEndSeq(0, 14);
+
+    SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
 
     av.setWrapAlignment(true);
 
     av.setWrapAlignment(true);
-    av.getRanges().setStartEndSeq(0, 14);
     av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
     assertEquals(charHeight, 17);
     assertEquals(charWidth, 12);
 
     av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
     assertEquals(charHeight, 17);
     assertEquals(charWidth, 12);
 
-    SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
-
     /*
      * first with scales above, left, right
      */
     /*
      * first with scales above, left, right
      */
@@ -298,4 +298,42 @@ public class SeqCanvasTest
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3);
   }
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
     assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3);
   }
+
+  /**
+   * Test simulates loading an unwrapped alignment, shrinking it vertically so
+   * not all sequences are visible, then changing to wrapped mode. The ranges
+   * endSeq should be unchanged, but the vertical repeat height should include
+   * all sequences.
+   */
+  @Test(groups = "Functional")
+  public void testCalculateWrappedGeometry_fromScrolled()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewport av = af.getViewport();
+    AlignmentI al = av.getAlignment();
+    assertEquals(al.getWidth(), 157);
+    assertEquals(al.getHeight(), 15);
+    av.getRanges().setStartEndSeq(0, 3);
+    av.setShowAnnotation(false);
+    av.setScaleAboveWrapped(true);
+
+    SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
+
+    av.setWrapAlignment(true);
+    av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
+    int charHeight = av.getCharHeight();
+    int charWidth = av.getCharWidth();
+    assertEquals(charHeight, 17);
+    assertEquals(charWidth, 12);
+
+    int canvasWidth = 400;
+    int canvasHeight = 300;
+    testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
+
+    assertEquals(av.getRanges().getEndSeq(), 3); // unchanged
+    int repeatingHeight = (int) PA.getValue(testee,
+            "wrappedRepeatHeightPx");
+    assertEquals(repeatingHeight, charHeight * (2 + al.getHeight()));
+  }
 }
 }