From 5bfa620be59254040bb09046fecc018770c6dbb0 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 3 Oct 2017 11:43:36 +0100 Subject: [PATCH] JAL-2674 working refactor of drawPanel iteration --- src/jalview/appletgui/SeqCanvas.java | 39 ++++------------ src/jalview/datamodel/HiddenColumns.java | 16 ++++--- src/jalview/gui/SeqCanvas.java | 72 ++++-------------------------- 3 files changed, 28 insertions(+), 99 deletions(-) diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 67b21bc..2a66fd8 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -22,6 +22,7 @@ package jalview.appletgui; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenColumns.VisibleBlocksVisBoundsIterator; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -560,30 +561,23 @@ public class SeqCanvas extends Panel implements ViewportListenerI else { int screenY = 0; - final int screenYMax = endRes - startRes; int blockStart = startRes; - int blockEnd = endRes; // equals blockStart + screenYMax - screenY; + int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - Iterator regions = hidden.iterator(); + VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden + .getVisibleBlocksIterator(startRes, endRes, true); + while (regions.hasNext()) { int[] region = regions.next(); - int hideStart = region[0]; - int hideEnd = region[1]; - - if (hideStart <= blockStart) - { - blockStart += (hideEnd - hideStart) + 1; - blockEnd += (hideEnd - hideStart) + 1; - continue; - } + blockEnd = region[1]; + blockStart = region[0]; /* * draw up to just before the next hidden region, or the end of * the visible region, whichever comes first */ - blockEnd = Math.min(blockEnd, hideStart - 1); g1.translate(screenY * avcharWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); @@ -592,7 +586,8 @@ 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 == hideStart - 1) + if (av.getShowHiddenMarkers() + && (regions.hasNext() || regions.endsAtHidden())) { g1.setColor(Color.blue); g1.drawLine((blockEnd - blockStart + 1) * avcharWidth - 1, @@ -602,22 +597,6 @@ public class SeqCanvas extends Panel implements ViewportListenerI g1.translate(-screenY * avcharWidth, 0); screenY += blockEnd - blockStart + 1; - blockStart = hideEnd + 1; - blockEnd = blockStart + screenYMax - screenY; - - if (screenY > screenYMax) - { - // already rendered last block - return; - } - } - - if (screenY <= screenYMax) - { - // remaining visible region to render - g1.translate(screenY * avcharWidth, 0); - draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); - g1.translate(-screenY * avcharWidth, 0); } } } diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 2088aba..f8a7f0c 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1932,7 +1932,7 @@ public class HiddenColumns private int currentPosition = 0; - private boolean endsAtHidden = true; + private boolean endsAtHidden = false; VisibleBlocksVisBoundsIterator(int start, int end, boolean usecopy) { @@ -1950,6 +1950,7 @@ public class HiddenColumns int hiddenSoFar = 0; int visSoFar = 0; int maxVisible = end - start; + endsAtHidden = false; // iterate until a region begins within (start,end] int i = 0; @@ -1978,23 +1979,28 @@ public class HiddenColumns visSoFar += blockEnd - blockStart + 1; blockStart = region[1] + 1; - blockEnd = end + hiddenSoFar; + hiddenSoFar += region[1] - region[0] + 1; + blockEnd = end + hiddenSoFar; i++; } if (visSoFar < maxVisible) { blockEnd = blockStart + maxVisible - visSoFar; - int[] contig = new int[] { blockStart, - blockEnd }; + int[] contig = new int[] { blockStart, blockEnd }; vcontigs.add(contig); - endsAtHidden = false; + if (i < hiddenColumns.size() + && hiddenColumns.get(i)[0] - 1 == blockEnd) + { + endsAtHidden = true; + } } } else { + // there are no hidden columns, return a single visible contig int[] contig = new int[] { start, end }; vcontigs.add(contig); endsAtHidden = false; diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 2c8a5df..82e4481 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -852,35 +852,23 @@ public class SeqCanvas extends JComponent implements ViewportListenerI else { int screenY = 0; - final int screenYMax = endRes - startRes; int blockStart = startRes; - int blockEnd = endRes; // equals blockStart + screenYMax - screenY; + int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden - .getVisibleBlocksIterator(startRes, endRes, true);// hidden.iterator(); + .getVisibleBlocksIterator(startRes, endRes, true); + while (regions.hasNext()) { int[] region = regions.next(); blockEnd = region[1]; blockStart = region[0]; -/* int hideStart = region[0]; - int hideEnd = region[1]; - if (hideStart <= blockStart) - { - blockStart += (hideEnd - hideStart) + 1; // convert startRes to an - // absolute value - blockEnd += (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(hideStart - 1, -// blockEnd); g1.translate(screenY * charWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset); @@ -890,8 +878,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * triangle on top) if we reached it */ if (av.getShowHiddenMarkers() - && (regions.hasNext() || regions.endsAtHidden()))// blockEnd == - // hideStart - 1) + && (regions.hasNext() || regions.endsAtHidden())) { g1.setColor(Color.blue); @@ -902,25 +889,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g1.translate(-screenY * charWidth, 0); screenY += blockEnd - blockStart + 1; - /* blockStart = hideEnd + 1; - blockEnd = blockStart + screenYMax - screenY; - - if (screenY > screenYMax) - { - // already rendered last block - return; - }*/ } - - /* if (screenY <= screenYMax) - { - // remaining visible region to render - blockEnd = blockStart + screenYMax - screenY; - g1.translate(screenY * charWidth, 0); - draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset); - - g1.translate(-screenY * charWidth, 0); - }*/ } } @@ -1135,20 +1104,13 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int blockEnd = endRes; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - Iterator regions = hidden.iterator(); + VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden + .getVisibleBlocksIterator(startRes, endRes, true); while (regions.hasNext()) { int[] region = regions.next(); - int hideStart = region[0]; - int hideEnd = region[1]; - - if (hideStart <= blockStart) - { - blockStart += (hideEnd - hideStart) + 1; - continue; - } - - blockEnd = hideStart - 1; + blockEnd = region[1]; + blockStart = region[0]; g.translate(screenY * charWidth, 0); drawPartialGroupOutline(g, group, @@ -1156,24 +1118,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g.translate(-screenY * charWidth, 0); screenY += blockEnd - blockStart + 1; - blockStart = hideEnd + 1; - - if (screenY > (endRes - startRes)) - { - // already rendered last block - break; - } - } - - if (screenY <= (endRes - startRes)) - { - // remaining visible region to render - blockEnd = blockStart + (endRes - startRes) - screenY; - g.translate(screenY * charWidth, 0); - drawPartialGroupOutline(g, group, - blockStart, blockEnd, startSeq, endSeq, offset); - - g.translate(-screenY * charWidth, 0); } } } -- 1.7.10.2