+ 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();
+
+ /*
+ * list of hidden column [start, end] ranges; the list is maintained in
+ * ascending start column order
+ */
+ Vector<int[]> hiddenColumns;
+
+ /**
+ * Add a column to the selection
+ *
+ * @param col
+ * index of column
+ */
+ public void addElement(int col)
+ {
+ selected.add(col);
+ }
+
+ /**
+ * clears column selection
+ */
+ public void clear()
+ {
+ selected.clear();
+ }
+
+ /**
+ * Removes value 'col' from the selection (not the col'th item)
+ *
+ * @param col
+ * index of column to be removed
+ */
+ public void removeElement(int col)
+ {
+ selected.remove(col);
+ }
+
+ /**
+ * removes a range of columns from the selection
+ *
+ * @param start
+ * int - first column in range to be removed
+ * @param end
+ * int - last col
+ */
+ public void removeElements(int start, int end)
+ {
+ Integer colInt;
+ for (int i = start; i < end; i++)
+ {
+ colInt = new Integer(i);
+ if (selected.contains(colInt))
+ {
+ selected.remove(colInt);
+ }
+ }
+ }
+
+ /**
+ * Returns a list of selected columns. The list contains no duplicates but is
+ * not necessarily ordered. It also may include columns hidden from the
+ * current view
+ */
+ public List<Integer> getSelected()
+ {
+ return selected.getList();
+ }
+
+ /**
+ * @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
+ *
+ * @return true if col is selected
+ */
+ public boolean contains(int col)
+ {
+ return (col > -1) ? selected.isSelected(col) : false;
+ }
+
+ /**
+ * Answers true if no columns are selected, else false
+ */
+ public boolean isEmpty()
+ {
+ return selected == null || selected.isEmpty();
+ }
+
+ /**
+ * rightmost selected column
+ *
+ * @return rightmost column in alignment that is selected
+ */
+ public int getMax()
+ {
+ if (selected.isEmpty())
+ {
+ return -1;
+ }
+ return selected.getMaxColumn();
+ }
+
+ /**
+ * Leftmost column in selection
+ *
+ * @return column index of leftmost column in selection
+ */
+ public int getMin()
+ {
+ if (selected.isEmpty())
+ {
+ return 1000000000;
+ }
+ return selected.getMinColumn();
+ }
+
+ /**
+ * propagate shift in alignment columns to column selection
+ *
+ * @param start
+ * beginning of edit
+ * @param left
+ * shift in edit (+ve for removal, or -ve for inserts)
+ */
+ public List<int[]> compensateForEdit(int start, int change)
+ {
+ List<int[]> deletedHiddenColumns = null;
+ selected.compensateForEdits(start, change);
+
+ if (hiddenColumns != null)
+ {
+ deletedHiddenColumns = new ArrayList<int[]>();
+ int hSize = hiddenColumns.size();
+ for (int i = 0; i < hSize; i++)
+ {
+ int[] region = hiddenColumns.elementAt(i);
+ if (region[0] > start && start + change > region[1])