JAL-2647 more iterators
[jalview.git] / src / jalview / gui / SeqCanvas.java
index 1df6ae3..122e29a 100755 (executable)
@@ -855,24 +855,20 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
       int blockStart = startRes;
       int blockEnd = endRes;
 
-      for (int[] region : av.getAlignment().getHiddenColumns()
-              .getHiddenColumnsCopy())
+      HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+      Iterator<int[]> regions = hidden.getBoundedVisRegionIterator(startRes,
+              endRes);
+      while (regions.hasNext())
       {
-        int hideStart = region[0];
-        int hideEnd = region[1];
+        int[] region = regions.next();
 
-        if (hideStart <= blockStart)
-        {
-          blockStart += (hideEnd - hideStart) + 1;
-          continue;
-        }
+        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(hideStart - 1, blockStart + screenYMax
-                - screenY);
+        blockEnd = Math.min(region[1], blockStart + screenYMax - screenY);
 
         g1.translate(screenY * charWidth, 0);
 
@@ -882,7 +878,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 == hideStart - 1)
+        if (av.getShowHiddenMarkers() && blockEnd == region[1])
         {
           g1.setColor(Color.blue);
 
@@ -893,7 +889,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
         g1.translate(-screenY * charWidth, 0);
         screenY += blockEnd - blockStart + 1;
-        blockStart = hideEnd + 1;
 
         if (screenY > screenYMax)
         {
@@ -908,7 +903,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);
       }
     }
@@ -1124,19 +1119,15 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
       int blockStart = startRes;
       int blockEnd = endRes;
 
-      for (int[] region : av.getAlignment().getHiddenColumns()
-              .getHiddenColumnsCopy())
+      HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+      Iterator<int[]> regions = hidden.getBoundedVisRegionIterator(startRes,
+              endRes);
+      while (regions.hasNext())
       {
-        int hideStart = region[0];
-        int hideEnd = region[1];
-
-        if (hideStart <= blockStart)
-        {
-          blockStart += (hideEnd - hideStart) + 1;
-          continue;
-        }
+        int[] region = regions.next();
 
-        blockEnd = hideStart - 1;
+        blockStart = region[0];
+        blockEnd = region[1];
 
         g.translate(screenY * charWidth, 0);
         drawPartialGroupOutline(g, group,
@@ -1144,7 +1135,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
 
         g.translate(-screenY * charWidth, 0);
         screenY += blockEnd - blockStart + 1;
-        blockStart = hideEnd + 1;
 
         if (screenY > (endRes - startRes))
         {