From 7a287c5cc3b2725a604fe4f83abd57c0a9acc53d Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 29 Sep 2017 10:26:15 +0100 Subject: [PATCH] JAL-2674 reverted attempt at visible regions iterator --- src/jalview/appletgui/SeqCanvas.java | 22 +++-- src/jalview/datamodel/HiddenColumns.java | 126 ------------------------- src/jalview/gui/SeqCanvas.java | 35 ++++--- test/jalview/datamodel/HiddenColumnsTest.java | 61 ------------ 4 files changed, 38 insertions(+), 206 deletions(-) diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 8d429c7..5d55473 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -565,20 +565,25 @@ public class SeqCanvas extends Panel implements ViewportListenerI int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - Iterator regions = hidden.getBoundedVisRegionIterator(startRes, - endRes); + Iterator regions = hidden.iterator(); while (regions.hasNext()) { int[] region = regions.next(); + int hideStart = region[0]; + int hideEnd = region[1]; - blockStart = region[0]; + if (hideStart <= blockStart) + { + blockStart += (hideEnd - hideStart) + 1; + continue; + } /* * draw up to just before the next hidden region, or the end of * the visible region, whichever comes first */ - blockEnd = Math.min(region[1], blockStart + screenYMax - screenY); - + blockEnd = Math.min(hideStart - 1, + blockStart + screenYMax - screenY); g1.translate(screenY * avcharWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); @@ -587,7 +592,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI * draw the downline of the hidden column marker (ScalePanel draws the * triangle on top) if we reached it */ - if (av.getShowHiddenMarkers() && blockEnd == region[1]) + if (av.getShowHiddenMarkers() && blockEnd == hideStart - 1) { g1.setColor(Color.blue); g1.drawLine((blockEnd - blockStart + 1) * avcharWidth - 1, @@ -597,6 +602,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI g1.translate(-screenY * avcharWidth, 0); screenY += blockEnd - blockStart + 1; + blockStart = hideEnd + 1; if (screenY > screenYMax) { @@ -604,17 +610,17 @@ public class SeqCanvas extends Panel implements ViewportListenerI return; } } + if (screenY <= screenYMax) { // remaining visible region to render - blockEnd = blockStart + (endRes - startRes) - screenY; + blockEnd = blockStart + screenYMax - screenY; g1.translate(screenY * avcharWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); g1.translate(-screenY * avcharWidth, 0); } } - } // int startRes, int endRes, int startSeq, int endSeq, int x, int y, diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 82e25b9..b915423 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1525,11 +1525,6 @@ public class HiddenColumns return new BoundedStartRegionIterator(start, end, useCopy); } - public Iterator getBoundedVisRegionIterator(int start, int end) - { - return new BoundedVisRegionIterator(start, end, true); - } - /** * An iterator which iterates over hidden column regions in a range. * @@ -1733,125 +1728,4 @@ public class HiddenColumns return result; } } - - class BoundedVisRegionIterator implements Iterator - { - private int start; // start position to iterate from - - private int end; // end position to iterate to - - // current region in visColumns - private int[] currentRegion; - - // current index in visColumns - private int currentPosition = 0; - - private List vcontigs = null; - - /** - * Construct an iterator over visibleColumn regions bounded at - * [lowerBound,upperBound] - * - * @param lowerBound - * lower bound to iterate from - * @param upperBound - * upper bound to iterate to - * @param useCopyCols - * whether to make a local copy for iteration (set to true if - * calling from outwith the HiddenColumns class) - */ - BoundedVisRegionIterator(int lowerBound, int upperBound, - boolean useCopy) - { - try - { - start = lowerBound; - end = upperBound; - - if (useCopy) - { - // assume that if useCopy is false the calling code has locked - // hiddenColumns - LOCK.readLock().lock(); - } - - int visStart = start; - - if (hiddenColumns != null) - { - vcontigs = new ArrayList<>(hiddenColumns.size() + 1); - - // navigate to start, keeping count of hidden columns - int i = 0; - int[] region = null; - while ((i < hiddenColumns.size()) - && (hiddenColumns.get(i)[0] <= start)) - { - i++; - } - // if there was a hidden region before (i>=1), and it ended after - // start - // and before end, adjust visStart to be just after that region - if (i > 0) - { - region = hiddenColumns.get(i - 1); - if ((region[1] > start) && (region[1] < end)) - { - visStart = region[1] + 1; - } - else if (region[1] >= end) - { - // previous hidden region covers whole range [start,end] - // early exit - vcontigs is empty - return; - } - } - - // iterate from start to end, adding start positions of each - // hidden region. Positions are visible columns count, not absolute - while (i < hiddenColumns.size() - && (hiddenColumns.get(i)[0] < end)) - { - region = hiddenColumns.get(i); - int[] prevVisibleRegion = new int[] { visStart, region[0] - 1 }; - vcontigs.add(prevVisibleRegion); - visStart = region[1] + 1; - i++; - } - // add on a final visible region if needed - if (visStart <= end) - { - int[] lastRegion = new int[] { visStart, end }; - vcontigs.add(lastRegion); - } - } - else - { - vcontigs = new ArrayList<>(); - int[] lastRegion = new int[] { start, end }; - vcontigs.add(lastRegion); - } - } finally - { - if (useCopy) - { - LOCK.readLock().unlock(); - } - } - } - - @Override - public boolean hasNext() - { - return (currentPosition < vcontigs.size()); - } - - @Override - public int[] next() - { - currentRegion = vcontigs.get(currentPosition); - currentPosition++; - return currentRegion; - } - } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 122e29a..b7d74de 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -856,20 +856,25 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - Iterator regions = hidden.getBoundedVisRegionIterator(startRes, - endRes); + Iterator regions = hidden.iterator(); while (regions.hasNext()) { int[] region = regions.next(); + int hideStart = region[0]; + int hideEnd = region[1]; - blockStart = region[0]; + if (hideStart <= blockStart) + { + blockStart += (hideEnd - hideStart) + 1; + continue; + } /* * draw up to just before the next hidden region, or the end of * the visible region, whichever comes first */ - blockEnd = Math.min(region[1], blockStart + screenYMax - screenY); - + blockEnd = Math.min(hideStart - 1, + blockStart + screenYMax - screenY); g1.translate(screenY * charWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset); @@ -878,7 +883,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * draw the downline of the hidden column marker (ScalePanel draws the * triangle on top) if we reached it */ - if (av.getShowHiddenMarkers() && blockEnd == region[1]) + if (av.getShowHiddenMarkers() && blockEnd == hideStart - 1) { g1.setColor(Color.blue); @@ -889,6 +894,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g1.translate(-screenY * charWidth, 0); screenY += blockEnd - blockStart + 1; + blockStart = hideEnd + 1; if (screenY > screenYMax) { @@ -903,7 +909,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI blockEnd = blockStart + screenYMax - screenY; g1.translate(screenY * charWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset); - + g1.translate(-screenY * charWidth, 0); } } @@ -1120,14 +1126,20 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - Iterator regions = hidden.getBoundedVisRegionIterator(startRes, - endRes); + Iterator regions = hidden.iterator(); while (regions.hasNext()) { int[] region = regions.next(); + int hideStart = region[0]; + int hideEnd = region[1]; + + if (hideStart <= blockStart) + { + blockStart += (hideEnd - hideStart) + 1; + continue; + } - blockStart = region[0]; - blockEnd = region[1]; + blockEnd = hideStart - 1; g.translate(screenY * charWidth, 0); drawPartialGroupOutline(g, group, @@ -1135,6 +1147,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g.translate(-screenY * charWidth, 0); screenY += blockEnd - blockStart + 1; + blockStart = hideEnd + 1; if (screenY > (endRes - startRes)) { diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 92e0f90..1ad6d85 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -1434,65 +1434,4 @@ public class HiddenColumnsTest assertEquals(6, next); assertFalse(it.hasNext()); } - - @Test(groups = "Functional") - public void testVisRegionsIterator() - { - HiddenColumns h = new HiddenColumns(); - Iterator it = h.getBoundedVisRegionIterator(0, 15); - - // no hidden columns = single visible contig - assertTrue(it.hasNext()); - assertEquals("[0, 15]", Arrays.toString(it.next())); - - // hidden column region at start - h.hideColumns(0, 5); - it = h.getBoundedVisRegionIterator(0, 15); - assertTrue(it.hasNext()); - assertEquals("[6, 15]", Arrays.toString(it.next())); - - // hidden column region at end - h = new HiddenColumns(); - h.hideColumns(8, 15); - it = h.getBoundedVisRegionIterator(0, 15); - assertTrue(it.hasNext()); - assertEquals("[0, 7]", Arrays.toString(it.next())); - - // hidden column region across whole region - h = new HiddenColumns(); - h.hideColumns(0, 20); - it = h.getBoundedVisRegionIterator(0, 15); - assertFalse(it.hasNext()); - - // hidden column region in middle - h = new HiddenColumns(); - h.hideColumns(1, 14); - it = h.getBoundedVisRegionIterator(0, 15); - assertTrue(it.hasNext()); - assertEquals("[0, 0]", Arrays.toString(it.next())); - assertTrue(it.hasNext()); - assertEquals("[15, 15]", Arrays.toString(it.next())); - - // hidden column region just off either end - h = new HiddenColumns(); - h.hideColumns(3, 14); - it = h.getBoundedVisRegionIterator(4, 13); - assertFalse(it.hasNext()); - - // multiple regions - h = new HiddenColumns(); - h.hideColumns(3, 5); - h.hideColumns(7, 11); - h.hideColumns(14, 19); - h.hideColumns(24, 25); - h.hideColumns(35, 39); - it = h.getBoundedVisRegionIterator(8, 26); - assertTrue(it.hasNext()); - assertEquals("[12, 13]", Arrays.toString(it.next())); - assertTrue(it.hasNext()); - assertEquals("[20, 23]", Arrays.toString(it.next())); - assertTrue(it.hasNext()); - assertEquals("[26, 26]", Arrays.toString(it.next())); - assertFalse(it.hasNext()); - } } -- 1.7.10.2