merge
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
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();
     }
 
   }