From: gmungoc Date: Mon, 4 Mar 2019 12:30:09 +0000 (+0000) Subject: Merge branch 'bug/JAL-3099alignmentVisibleWidth' into merge/JAL-3099 X-Git-Tag: Release_2_11_0~17^2~78 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=985fd5ff517f3eb5221a7aefec88138341514779;p=jalview.git Merge branch 'bug/JAL-3099alignmentVisibleWidth' into merge/JAL-3099 Conflicts: src/jalview/gui/AlignmentPanel.java src/jalview/gui/IdCanvas.java test/jalview/datamodel/AlignmentTest.java --- 985fd5ff517f3eb5221a7aefec88138341514779 diff --cc src/jalview/gui/AlignmentPanel.java index 82e2113,d8f1629..51e703d --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@@ -954,20 -991,29 +947,20 @@@ public class AlignmentPanel extends GAl /* * How many sequences and residues can we fit on a printable page? */ - int totalRes = (pageWidth - idWidth) / av.getCharWidth(); + final int totalRes = (pageWidth - idWidth) / av.getCharWidth(); - int totalSeq = (pageHeight - scaleHeight) / charHeight - 1; + final int totalSeq = (pageHeight - scaleHeight) / charHeight - 1; - final int alignmentWidth = av.getAlignment().getWidth(); - final int pagesWide = (alignmentWidth / totalRes) + 1; - int alignmentWidth = av.getAlignment().getVisibleWidth(); ++ final int alignmentWidth = av.getAlignment().getVisibleWidth(); + int pagesWide = (alignmentWidth / totalRes) + 1; - final int startRes = (pi % pagesWide) * totalRes; - int endRes = (startRes + totalRes) - 1; + final int startRes = (pageIndex % pagesWide) * totalRes; + final int endRes = Math.min(startRes + totalRes - 1, + alignmentWidth - 1); - if (endRes > (alignmentWidth - 1)) - { - endRes = alignmentWidth - 1; - } - - final int startSeq = (pi / pagesWide) * totalSeq; - int endSeq = startSeq + totalSeq; - - int alignmentHeight = av.getAlignment().getHeight(); - if (endSeq > alignmentHeight) - { - endSeq = alignmentHeight; - } + final int startSeq = (pageIndex / pagesWide) * totalSeq; + final int alignmentHeight = av.getAlignment().getHeight(); + final int endSeq = Math.min(startSeq + totalSeq, alignmentHeight); int pagesHigh = ((alignmentHeight / totalSeq) + 1) * pageHeight; @@@ -1076,15 -1161,10 +1069,10 @@@ int idWidth = getVisibleIdWidth(false); - int maxwidth = av.getAlignment().getWidth(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth) - 1; - } + int maxwidth = av.getAlignment().getVisibleWidth(); int resWidth = getSeqPanel().seqCanvas - .getWrappedCanvasWidth(pwidth - idWidth); + .getWrappedCanvasWidth(pageWidth - idWidth); int totalHeight = cHeight * (maxwidth / resWidth + 1); diff --cc src/jalview/gui/IdCanvas.java index cf88c90,9ff0652..951db78 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@@ -367,29 -367,19 +367,23 @@@ public class IdCanvas extends JPanel im } /** - * Draws sequence ids in wrapped mode + * Draws sequence ids, and annotation labels if annotations are shown, in + * wrapped mode * - * @param starty - * @param hasHiddenRows + * @param g + * @param alignViewport + * @param startSeq */ - protected void drawIdsWrapped(int starty, boolean hasHiddenRows) + void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, + int startSeq, int pageHeight) { - int maxwidth = av.getAlignment().getVisibleWidth(); - int alheight = av.getAlignment().getHeight(); + int alignmentWidth = alignViewport.getAlignment().getWidth(); + final int alheight = alignViewport.getAlignment().getHeight(); - if (alignViewport.hasHiddenColumns()) - { - alignmentWidth = alignViewport.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(alignmentWidth) - 1; - } - int annotationHeight = 0; - if (av.isShowAnnotation()) + AnnotationLabels labels = null; + if (alignViewport.isShowAnnotation()) { if (ap == null) { diff --cc test/jalview/datamodel/AlignmentTest.java index 8aed114,5e400c0..dd19eb6 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@@ -1485,51 -1485,33 +1485,81 @@@ public class AlignmentTes assertEquals(".PQR...", seq3.getSequenceAsString()); } + /** + * Test for setHiddenColumns, to check it returns true if the hidden columns + * have changed, else false + */ + @Test(groups = { "Functional" }) + public void testSetHiddenColumns() + { + AlignmentI al = new Alignment(new SequenceI[] {}); + assertFalse(al.getHiddenColumns().hasHiddenColumns()); + + HiddenColumns hc = new HiddenColumns(); + assertFalse(al.setHiddenColumns(hc)); // no change + assertSame(hc, al.getHiddenColumns()); + + hc.hideColumns(2, 4); + assertTrue(al.getHiddenColumns().hasHiddenColumns()); + + /* + * set a different object but with the same columns hidden + */ + HiddenColumns hc2 = new HiddenColumns(); + hc2.hideColumns(2, 4); + assertFalse(al.setHiddenColumns(hc2)); // no change + assertSame(hc2, al.getHiddenColumns()); + + assertTrue(al.setHiddenColumns(null)); + assertNull(al.getHiddenColumns()); + assertTrue(al.setHiddenColumns(hc)); + assertSame(hc, al.getHiddenColumns()); + + al.getHiddenColumns().hideColumns(10, 12); + hc2.hideColumns(10, 12); + assertFalse(al.setHiddenColumns(hc2)); // no change + + /* + * hide columns 15-16 then 17-18 in hc + * hide columns 15-18 in hc2 + * these are not now 'equal' objects even though they + * represent the same set of columns + */ + assertSame(hc2, al.getHiddenColumns()); + hc.hideColumns(15, 16); + hc.hideColumns(17, 18); + hc2.hideColumns(15, 18); + assertFalse(hc.equals(hc2)); + assertTrue(al.setHiddenColumns(hc)); // 'changed' + } ++ + @Test(groups = { "Functional" }) + public void testGetWidth() + { + SequenceI seq1 = new Sequence("seq1", "ABCDEF--"); + SequenceI seq2 = new Sequence("seq2", "-JKLMNO--"); + SequenceI seq3 = new Sequence("seq2", "-PQR"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 }); + + assertEquals(9, a.getWidth()); + + // width includes hidden columns + a.getHiddenColumns().hideColumns(2, 5); + assertEquals(9, a.getWidth()); + } + + @Test(groups = { "Functional" }) + public void testGetVisibleWidth() + { + SequenceI seq1 = new Sequence("seq1", "ABCDEF--"); + SequenceI seq2 = new Sequence("seq2", "-JKLMNO--"); + SequenceI seq3 = new Sequence("seq2", "-PQR"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 }); + + assertEquals(9, a.getVisibleWidth()); + + // width excludes hidden columns + a.getHiddenColumns().hideColumns(2, 5); + assertEquals(5, a.getVisibleWidth()); + } }