merge
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 11 Apr 2016 10:49:08 +0000 (11:49 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 11 Apr 2016 10:49:08 +0000 (11:49 +0100)
src/jalview/appletgui/ScalePanel.java
src/jalview/appletgui/SeqCanvas.java
src/jalview/datamodel/ColumnSelection.java
src/jalview/gui/ScalePanel.java
src/jalview/gui/SeqCanvas.java
test/jalview/datamodel/ColumnSelectionTest.java

index 9106385..71ecb13 100755 (executable)
@@ -428,6 +428,7 @@ public class ScalePanel extends Panel implements MouseMotionListener,
     gg.setColor(Color.black);
 
     int scalestartx = (startx / 10) * 10;
+    int widthx = 1 + endx - startx;
 
     FontMetrics fm = gg.getFontMetrics(av.getFont());
     int y = avcharHeight - fm.getDescent();
@@ -479,7 +480,7 @@ public class ScalePanel extends Panel implements MouseMotionListener,
           res = av.getColumnSelection().findHiddenRegionPosition(i)
                   - startx;
 
-          if (res < 0 || res > endx - scalestartx)
+          if (res < 0 || res > widthx)
           {
             continue;
           }
index ce70597..024fdc7 100755 (executable)
@@ -276,6 +276,7 @@ public class SeqCanvas extends Panel
    * at 0). NOTE 1: The av limits are set in setFont in this class and in the
    * adjustment listener in SeqPanel when the scrollbars move.
    */
+  @Override
   public void update(Graphics g)
   {
     paint(g);
@@ -573,10 +574,17 @@ public class SeqCanvas extends Panel
           g1.translate(-screenY * avcharWidth, 0);
           screenY += blockEnd - blockStart + 1;
           blockStart = hideEnd + 1;
+
+          if (screenY > (endRes - startRes))
+          {
+            // already rendered last block
+            return;
+          }
         }
       }
       if (screenY <= (endRes - startRes))
       {
+        // remaining visible region to render
         blockEnd = blockStart + (endRes - startRes) - screenY;
         g1.translate(screenY * avcharWidth, 0);
         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
index c63b6cd..c23b772 100644 (file)
@@ -184,6 +184,26 @@ public class ColumnSelection
     {
       return selected.get(0) ? 0 : selected.nextSetBit(0);
     }
+
+    /**
+     * @return a series of selection intervals along the range
+     */
+    public List<int[]> getRanges()
+    {
+      List<int[]> rlist = new ArrayList<int[]>();
+      if (selected.isEmpty())
+      {
+        return rlist;
+      }
+      int next = selected.nextSetBit(0), clear = -1;
+      while (next != -1)
+      {
+        clear = selected.nextClearBit(next);
+        rlist.add(new int[] { next, clear - 1 });
+        next = selected.nextSetBit(clear);
+      }
+      return rlist;
+    }
   }
 
   IntList selected = new IntList();
@@ -255,6 +275,15 @@ public class ColumnSelection
   }
 
   /**
+   * @return list of int arrays containing start and end column position for
+   *         runs of selected columns ordered from right to left.
+   */
+  public List<int[]> getSelectedRanges()
+  {
+    return selected.getRanges();
+  }
+
+  /**
    * 
    * @param col
    *          index to search for in column selection
@@ -623,6 +652,10 @@ public class ColumnSelection
 
   /**
    * Use this method to determine where the next hiddenRegion starts
+   * 
+   * @param hiddenRegion
+   *          index of hidden region (counts from 0)
+   * @return column number in visible view
    */
   public int findHiddenRegionPosition(int hiddenRegion)
   {
@@ -642,7 +675,7 @@ public class ColumnSelection
         gaps += region[1] + 1 - region[0];
         result = region[1] + 1;
         index++;
-      } while (index < hiddenRegion + 1);
+      } while (index <= hiddenRegion);
 
       result -= gaps;
     }
@@ -708,10 +741,12 @@ public class ColumnSelection
 
   public void hideSelectedColumns()
   {
-    while (!selected.isEmpty())
-    {
-      int column = selected.elementAt(0);
-      hideColumns(column);
+    synchronized (selected) {
+      for (int[] selregions:selected.getRanges())
+      {
+        hideColumns(selregions[0], selregions[1]);
+      }
+      selected.clear();
     }
 
   }
index 7e17f46..41de58f 100755 (executable)
@@ -493,6 +493,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     gg.setColor(Color.black);
 
     int scalestartx = (startx / 10) * 10;
+    int widthx = 1 + endx - startx;
 
     FontMetrics fm = gg.getFontMetrics(av.getFont());
     int y = avCharHeight - fm.getDescent();
@@ -540,11 +541,10 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
         for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
                 .size(); i++)
         {
-
           res = av.getColumnSelection().findHiddenRegionPosition(i)
                   - startx;
 
-          if (res < 0 || res > endx - scalestartx)
+          if (res < 0 || res > widthx)
           {
             continue;
           }
index 5706fe7..0f24b4b 100755 (executable)
@@ -335,6 +335,7 @@ public class SeqCanvas extends JComponent
    */
 
   // Set this to false to force a full panel paint
+  @Override
   public void paintComponent(Graphics g)
   {
     updateViewport();
@@ -682,10 +683,17 @@ public class SeqCanvas extends JComponent
         g1.translate(-screenY * charWidth, 0);
         screenY += blockEnd - blockStart + 1;
         blockStart = hideEnd + 1;
+
+        if (screenY > (endRes - startRes))
+        {
+          // already rendered last block
+          return;
+        }
       }
 
       if (screenY <= (endRes - startRes))
       {
+        // remaining visible region to render
         blockEnd = blockStart + (endRes - startRes) - screenY;
         g1.translate(screenY * charWidth, 0);
         draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
index 0f08ceb..0245b15 100644 (file)
@@ -244,6 +244,32 @@ public class ColumnSelectionTest
   }
 
   /**
+   * Test the method that gets runs of selected columns ordered by column. If
+   * this fails, HideSelectedColumns may also fail
+   */
+  @Test(groups = { "Functional" })
+  public void testgetSelectedRanges()
+  {
+    ColumnSelection cs = new ColumnSelection();
+    int[] sel = { 2, 3, 4, 7, 8, 9, 20, 21, 22 };
+    for (int col : sel)
+    {
+      cs.addElement(col);
+    }
+    List<int[]> range;
+    range = cs.getSelectedRanges();
+    assertEquals(3, range.size());
+    assertEquals("[2, 4]", Arrays.toString(range.get(0)));
+    assertEquals("[7, 9]", Arrays.toString(range.get(1)));
+    assertEquals("[20, 22]", Arrays.toString(range.get(2)));
+    cs.addElement(0);
+    cs.addElement(1);
+    range = cs.getSelectedRanges();
+    assertEquals(3, range.size());
+    assertEquals("[0, 4]", Arrays.toString(range.get(0)));
+  }
+
+  /**
    * Test the method that reveals a range of hidden columns given the start
    * column of the range
    */