X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FSeqCanvasTest.java;h=52986807d7953e344fd2e11ae604b753d71fe469;hb=20a4d7ddb86ee996f2b6617a0470922b83354c35;hp=a27bc3fafbb90511ce895570b058cc4a6e13d9a3;hpb=271fbb166b9396fdfc3cd164c0bca35649f2c2ff;p=jalview.git diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index a27bc3f..5298680 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.gui; import static org.testng.Assert.assertEquals; @@ -13,8 +33,6 @@ import junit.extensions.PA; import org.testng.annotations.Test; -import sun.swing.SwingUtilities2; - public class SeqCanvasTest { /** @@ -30,17 +48,17 @@ public class SeqCanvasTest 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.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); - SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; - /* * first with scales above, left, right */ @@ -48,7 +66,7 @@ public class SeqCanvasTest av.setScaleAboveWrapped(true); av.setScaleLeftWrapped(true); av.setScaleRightWrapped(true); - FontMetrics fm = SwingUtilities2.getFontMetrics(testee, av.getFont()); + FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; assertEquals(labelWidth, 39); // 3 x 9 + charWidth @@ -218,7 +236,7 @@ public class SeqCanvasTest av.setScaleAboveWrapped(true); av.setScaleLeftWrapped(true); av.setScaleRightWrapped(true); - FontMetrics fm = SwingUtilities2.getFontMetrics(testee, av.getFont()); + FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; assertEquals(labelWidth, 39); // 3 x 9 + charWidth int annotationHeight = testee.getAnnotationHeight(); @@ -280,4 +298,42 @@ public class SeqCanvasTest 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())); + } }