/*
* 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;
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);
}
/**
- * 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)
{
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());
+ }
}