From: gmungoc Date: Mon, 10 Sep 2018 13:13:47 +0000 (+0100) Subject: JAL-3099 use Alignment.getVisibleWidth() where wanted X-Git-Tag: Release_2_11_0~17^2~78^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fbug%2FJAL-3099alignmentVisibleWidth;p=jalview.git JAL-3099 use Alignment.getVisibleWidth() where wanted --- diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 83d8ade..e9081b0 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -669,14 +669,9 @@ public class AlignmentPanel extends Panel } else { - int width = av.getAlignment().getWidth(); + int width = av.getAlignment().getVisibleWidth(); int height = av.getAlignment().getHeight(); - if (av.hasHiddenColumns()) - { - width = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(width); - } if (x < 0) { x = 0; diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index 296f898..ef80616 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -280,15 +280,9 @@ public class IdCanvas extends Panel implements ViewportListenerI protected void drawIdsWrapped(int starty, final boolean doHiddenCheck, boolean hiddenRows) { - int maxwidth = av.getAlignment().getWidth(); + int maxwidth = av.getAlignment().getVisibleWidth(); int alheight = av.getAlignment().getHeight(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth) - 1; - } - int annotationHeight = 0; AnnotationLabels labels = null; diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 35d73de..96eb6b9 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -136,13 +136,6 @@ public class SeqCanvas extends Panel implements ViewportListenerI .visibleToAbsoluteColumn(endx); } - int maxwidth = av.getAlignment().getWidth(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth) - 1; - } - // WEST SCALE for (int i = 0; i < av.getAlignment().getHeight(); i++) { @@ -450,13 +443,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI int endx; int ypos = hgap; - int maxwidth = av.getAlignment().getWidth(); - - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth); - } + int maxwidth = av.getAlignment().getVisibleWidth(); while ((ypos <= canvasHeight) && (startRes < maxwidth)) { @@ -565,7 +552,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI int blockEnd; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - VisibleContigsIterator regions = (VisibleContigsIterator) hidden + VisibleContigsIterator regions = hidden .getVisContigsIterator(startRes, endRes + 1, true); while (regions.hasNext()) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 2c5684a..d8f1629 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -667,16 +667,9 @@ public class AlignmentPanel extends GAlignmentPanel implements } else { - int width = av.getAlignment().getWidth(); + int width = av.getAlignment().getVisibleWidth(); int height = av.getAlignment().getHeight(); - if (av.hasHiddenColumns()) - { - // reset the width to exclude hidden columns - width = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(width); - } - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); @@ -1002,7 +995,7 @@ public class AlignmentPanel extends GAlignmentPanel implements int totalSeq = (pageHeight - scaleHeight) / charHeight - 1; - int alignmentWidth = av.getAlignment().getWidth(); + int alignmentWidth = av.getAlignment().getVisibleWidth(); int pagesWide = (alignmentWidth / totalRes) + 1; final int startRes = (pi % pagesWide) * totalRes; @@ -1168,12 +1161,7 @@ public class AlignmentPanel extends GAlignmentPanel implements 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); @@ -1360,12 +1348,7 @@ public class AlignmentPanel extends GAlignmentPanel implements public AlignmentDimension getAlignmentDimension() { - int maxwidth = av.getAlignment().getWidth(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth); - } + int maxwidth = av.getAlignment().getVisibleWidth(); int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight()) + getScalePanel().getHeight(); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index cd7b0b7..9ff0652 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -374,15 +374,9 @@ public class IdCanvas extends JPanel implements ViewportListenerI */ protected void drawIdsWrapped(int starty, boolean hasHiddenRows) { - int maxwidth = av.getAlignment().getWidth(); + int maxwidth = av.getAlignment().getVisibleWidth(); int alheight = av.getAlignment().getHeight(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth) - 1; - } - int annotationHeight = 0; if (av.isShowAnnotation()) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 8f315bd..ce7b63b 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -954,13 +954,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int startx = startRes; int endx; int ypos = hgap; // vertical offset - int maxwidth = av.getAlignment().getWidth(); - - if (av.hasHiddenColumns()) - { - maxwidth = av.getAlignment().getHiddenColumns() - .absoluteToVisibleColumn(maxwidth); - } + int maxwidth = av.getAlignment().getVisibleWidth(); // chop the wrapped alignment extent up into panel-sized blocks and treat // each block as if it were a block from an unwrapped alignment diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 691e492..6f817bb 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -97,7 +97,7 @@ public class ViewportRanges extends ViewportProperties */ public int getVisibleAlignmentWidth() { - return al.getWidth() - al.getHiddenColumns().getSize(); + return al.getVisibleWidth(); } /** diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 1d1ebd6..5e400c0 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -1484,4 +1484,34 @@ public class AlignmentTest assertEquals(".JKLMNO", seq2.getSequenceAsString()); assertEquals(".PQR...", seq3.getSequenceAsString()); } + + @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()); + } }