/*
* list of selected columns (ordered by selection order, not column order)
*/
- private List<Integer> order = new ArrayList<Integer>();
+ private List<Integer> order;
+
+ /*
+ * an unmodifiable view of the selected columns list
+ */
+ private List<Integer> _uorder;
/**
* bitfield for column selection - allows quick lookup
*/
- private BitSet selected = new BitSet();
+ private BitSet selected;
+
+ /**
+ * Constructor
+ */
+ IntList()
+ {
+ order = new ArrayList<Integer>();
+ _uorder = Collections.unmodifiableList(order);
+ selected = new BitSet();
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param other
+ */
+ IntList(IntList other)
+ {
+ this();
+ if (other != null)
+ {
+ int j = other.size();
+ for (int i = 0; i < j; i++)
+ {
+ add(other.elementAt(i));
+ }
+ }
+ }
/**
* adds a new column i to the selection - only if i is not already selected
*
* @param i
*/
- public void add(int i)
+ void add(int i)
{
if (!selected.get(i))
{
}
}
- public void clear()
+ void clear()
{
order.clear();
selected.clear();
}
- public void remove(int col)
+ void remove(int col)
{
Integer colInt = new Integer(col);
}
}
- public boolean contains(Integer colInt)
+ boolean contains(Integer colInt)
{
return selected.get(colInt);
}
- public boolean isEmpty()
+ boolean isEmpty()
{
return order.isEmpty();
}
- public List<Integer> getList()
+ /**
+ * Returns a read-only view of the selected columns list
+ *
+ * @return
+ */
+ List<Integer> getList()
{
- return order;
+ return _uorder;
}
- public int size()
+ int size()
{
return order.size();
}
* @param i
* @return
*/
- public int elementAt(int i)
+ int elementAt(int i)
{
return order.get(i);
}
* @param change
* - delta for shift
*/
- public void compensateForEdits(int start, int change)
+ void compensateForEdits(int start, int change)
{
BitSet mask = new BitSet();
for (int i = 0; i < order.size(); i++)
selected.or(mask);
}
- public boolean isSelected(int column)
+ boolean isSelected(int column)
{
return selected.get(column);
}
- public int getMaxColumn()
+ int getMaxColumn()
{
return selected.length() - 1;
}
- public int getMinColumn()
+ int getMinColumn()
{
return selected.get(0) ? 0 : selected.nextSetBit(0);
}
/**
* @return a series of selection intervals along the range
*/
- public List<int[]> getRanges()
+ List<int[]> getRanges()
{
List<int[]> rlist = new ArrayList<int[]>();
if (selected.isEmpty())
}
/**
- * 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. This returns a copy of the actual list, and changes to the
- * copy will not affect the selection.
+ * Returns a read-only view of the (possibly empty) list of selected columns
+ * <p>
+ * The list contains no duplicates but is not necessarily ordered. It also may
+ * include columns hidden from the current view. To modify (for example sort)
+ * the list, you should first make a copy.
+ * <p>
+ * The list is not thread-safe: iterating over it could result in
+ * ConcurrentModificationException if it is modified by another thread.
*/
public List<Integer> getSelected()
{
- return new ArrayList<Integer>(selection.getList());
+ return selection.getList();
}
/**
*/
region[0] = Math.min(region[0], start);
region[1] = Math.max(region[1], end);
+
+ /*
+ * also update or remove any subsequent ranges
+ * that are overlapped
+ */
+ while (i < hiddenColumns.size() - 1)
+ {
+ int[] nextRegion = hiddenColumns.get(i + 1);
+ if (nextRegion[0] > end + 1)
+ {
+ /*
+ * gap to next hidden range - no more to update
+ */
+ break;
+ }
+ region[1] = Math.max(nextRegion[1], end);
+ hiddenColumns.remove(i + 1);
+ }
return;
}
}
{
if (copy != null)
{
- if (copy.selection != null)
- {
- selection = new IntList();
- for (int i = 0, j = copy.selection.size(); i < j; i++)
- {
- selection.add(copy.selection.elementAt(i));
- }
- }
+ selection = new IntList(copy.selection);
if (copy.hiddenColumns != null)
{
hiddenColumns = new Vector<int[]>(copy.hiddenColumns.size());
*/
public int[] locateVisibleBoundsOfSequence(SequenceI seq)
{
- int fpos=seq.getStart(),lpos= seq.getEnd();
+ int fpos = seq.getStart(), lpos = seq.getEnd();
int start = 0;
-
+
if (hiddenColumns == null || hiddenColumns.size() == 0)
{
int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1;
return changed;
}
+ /**
+ * Adjusts column selections, and the given selection group, to match the
+ * range of a stretch (e.g. mouse drag) operation
+ * <p>
+ * Method refactored from ScalePanel.mouseDragged
+ *
+ * @param res
+ * current column position, adjusted for hidden columns
+ * @param sg
+ * current selection group
+ * @param min
+ * start position of the stretch group
+ * @param max
+ * end position of the stretch group
+ */
+ public void stretchGroup(int res, SequenceGroup sg, int min, int max)
+ {
+ if (!contains(res))
+ {
+ addElement(res);
+ }
+
+ if (res > sg.getStartRes())
+ {
+ // expand selection group to the right
+ sg.setEndRes(res);
+ }
+ if (res < sg.getStartRes())
+ {
+ // expand selection group to the left
+ sg.setStartRes(res);
+ }
+
+ /*
+ * expand or shrink column selection to match the
+ * range of the drag operation
+ */
+ for (int col = min; col <= max; col++)
+ {
+ if (col < sg.getStartRes() || col > sg.getEndRes())
+ {
+ // shrinking drag - remove from selection
+ removeElement(col);
+ }
+ else
+ {
+ // expanding drag - add to selection
+ addElement(col);
+ }
+ }
+ }
}