();
+ if (selected.isEmpty())
{
- int index = 0;
- int gaps = 0;
- do
- {
- int[] region = (int[]) hiddenColumns.elementAt(index);
- if(hiddenRegion==0)
- {
- return region[0];
- }
-
- gaps += region[1] +1 - region[0];
- result = region[1] +1;
- index++;
- }
- while(index < hiddenRegion+1);
-
- result -= gaps;
+ 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;
+ }
- return result;
+ @Override
+ public int hashCode()
+ {
+ // TODO Auto-generated method stub
+ return selected.hashCode();
}
- /**
- * THis method returns the rightmost limit of a
- * region of an alignment with hidden columns.
- * In otherwords, the next hidden column.
- * @param index int
- */
- public int getHiddenBoundaryRight(int alPos)
+ @Override
+ public boolean equals(Object obj)
{
- if (hiddenColumns != null)
+ if (obj instanceof IntList)
{
- int index = 0;
- do
- {
- int[] region = (int[]) hiddenColumns.elementAt(index);
- if(alPos < region[0])
- return region[0];
-
- index++;
- }
- while(index < hiddenColumns.size());
+ return ((IntList) obj).selected.equals(selected);
}
-
- return alPos;
-
+ return false;
}
- /**
- * THis method returns the rightmost limit of a
- * region of an alignment with hidden columns.
- * In otherwords, the next hidden column.
- * @param index int
- */
- public int getHiddenBoundaryLeft(int alPos)
+ }
+
+ IntList selection = new IntList();
+
+ /**
+ * Add a column to the selection
+ *
+ * @param col
+ * index of column
+ */
+ public void addElement(int col)
+ {
+ selection.add(col);
+ }
+
+ /**
+ * clears column selection
+ */
+ public void clear()
+ {
+ selection.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)
+ {
+ selection.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++)
{
- if (hiddenColumns != null)
+ colInt = new Integer(i);
+ if (selection.contains(colInt))
{
- int index = hiddenColumns.size()-1;
- do
- {
- int[] region = (int[]) hiddenColumns.elementAt(index);
- if(alPos > region[1])
- return region[1];
+ selection.remove(colInt);
+ }
+ }
+ }
+
+ /**
+ * Returns a read-only view of the (possibly empty) list of selected columns
+ *
+ * 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.
+ *
+ * The list is not thread-safe: iterating over it could result in
+ * ConcurrentModificationException if it is modified by another thread.
+ */
+ public List getSelected()
+ {
+ return selection.getList();
+ }
+
+ /**
+ * @return list of int arrays containing start and end column position for
+ * runs of selected columns ordered from right to left.
+ */
+ public List getSelectedRanges()
+ {
+ return selection.getRanges();
+ }
+
+ /**
+ *
+ * @param col
+ * index to search for in column selection
+ *
+ * @return true if col is selected
+ */
+ public boolean contains(int col)
+ {
+ return (col > -1) ? selection.isSelected(col) : false;
+ }
+
+ /**
+ * Answers true if no columns are selected, else false
+ */
+ public boolean isEmpty()
+ {
+ return selection == null || selection.isEmpty();
+ }
+
+ /**
+ * rightmost selected column
+ *
+ * @return rightmost column in alignment that is selected
+ */
+ public int getMax()
+ {
+ if (selection.isEmpty())
+ {
+ return -1;
+ }
+ return selection.getMaxColumn();
+ }
+
+ /**
+ * Leftmost column in selection
+ *
+ * @return column index of leftmost column in selection
+ */
+ public int getMin()
+ {
+ if (selection.isEmpty())
+ {
+ return 1000000000;
+ }
+ return selection.getMinColumn();
+ }
- index--;
- }
- while(index >-1);
+ public void hideSelectedColumns(AlignmentI al)
+ {
+ synchronized (selection)
+ {
+ for (int[] selregions : selection.getRanges())
+ {
+ al.getHiddenColumns().hideColumns(selregions[0], selregions[1]);
}
+ selection.clear();
+ }
- return alPos;
+ }
+
+ /**
+ * Hides the specified column and any adjacent selected columns
+ *
+ * @param res
+ * int
+ */
+ public void hideSelectedColumns(int col, HiddenColumns hidden)
+ {
+ /*
+ * deselect column (whether selected or not!)
+ */
+ removeElement(col);
+
+ /*
+ * find adjacent selected columns
+ */
+ int min = col - 1, max = col + 1;
+ while (contains(min))
+ {
+ removeElement(min);
+ min--;
}
- public void hideSelectedColumns()
+ while (contains(max))
{
- while (size() > 0)
- {
- int column = ( (Integer) getSelected().firstElement()).intValue();
- hideColumns(column);
- }
+ removeElement(max);
+ max++;
+ }
+ /*
+ * min, max are now the closest unselected columns
+ */
+ min++;
+ max--;
+ if (min > max)
+ {
+ min = max;
}
- public void hideColumns(int start, int end)
+ hidden.hideColumns(min, max);
+ }
+
+
+
+
+
+ /**
+ * Copy constructor
+ *
+ * @param copy
+ */
+ public ColumnSelection(ColumnSelection copy)
+ {
+ if (copy != null)
{
- if(hiddenColumns==null)
- hiddenColumns = new Vector();
+ selection = new IntList(copy.selection);
+ }
+ }
+
+ /**
+ * ColumnSelection
+ */
+ public ColumnSelection()
+ {
+ }
- boolean added = false;
- boolean overlap = false;
- for (int i = 0; i < hiddenColumns.size(); i++)
+
+
+
+
+ /**
+ * Invert the column selection from first to end-1. leaves hiddenColumns
+ * untouched (and unselected)
+ *
+ * @param first
+ * @param end
+ */
+ public void invertColumnSelection(int first, int width, AlignmentI al)
+ {
+ boolean hasHidden = al.getHiddenColumns().hasHidden();
+ for (int i = first; i < width; i++)
+ {
+ if (contains(i))
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
- if ( start<=region[1] && end>=region[0])
+ removeElement(i);
+ }
+ else
+ {
+ if (!hasHidden || al.getHiddenColumns().isVisible(i))
{
- hiddenColumns.removeElementAt(i);
- overlap = true;
- break;
+ addElement(i);
}
- else if (end < region[0] && start < region[0])
+ }
+ }
+ }
+
+ /**
+ * set the selected columns to the given column selection, excluding any
+ * columns that are hidden.
+ *
+ * @param colsel
+ */
+ public void setElementsFrom(ColumnSelection colsel,
+ HiddenColumns hiddenColumns)
+ {
+ selection = new IntList();
+ if (colsel.selection != null && colsel.selection.size() > 0)
+ {
+ if (hiddenColumns.hasHidden())
+ {
+ // only select visible columns in this columns selection
+ for (Integer col : colsel.getSelected())
{
- hiddenColumns.insertElementAt(new int[]
- {start, end}, i);
- added = true;
- break;
+ if (hiddenColumns != null
+ && hiddenColumns.isVisible(col.intValue()))
+ {
+ selection.add(col);
+ }
}
}
-
- if(overlap)
+ else
{
- hideColumns(start, end);
+ // add everything regardless
+ for (Integer col : colsel.getSelected())
+ {
+ addElement(col);
+ }
}
- else if (!added)
- hiddenColumns.addElement(new int[] {start, end});
-
}
+ }
- /**
- * This method will find a range of selected columns
- * around the column specified
- * @param res int
- */
- public void hideColumns(int col)
- {
- // First find out range of columns to hide
- int min = col, max = col+1;
- while( contains(min) )
- { removeElement(min); min --; }
- while( contains(max) )
- { removeElement(max); max ++; }
+ /**
+ *
+ * @return true if there are columns marked
+ */
+ public boolean hasSelectedColumns()
+ {
+ return (selection != null && selection.size() > 0);
+ }
- min++; max--;
- hideColumns(min, max);
- }
- public void revealAllHiddenColumns()
+ public boolean filterAnnotations(Annotation[] annotations,
+ AnnotationFilterParameter filterParams)
+ {
+ // JBPNote - this method needs to be refactored to become independent of
+ // viewmodel package
+ this.clear();
+ int count = 0;
+ do
{
- if(hiddenColumns!=null)
+ if (annotations[count] != null)
{
- for (int i = 0; i < hiddenColumns.size(); i++)
+
+ boolean itemMatched = false;
+
+ if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+ && annotations[count].value >= filterParams
+ .getThresholdValue())
+ {
+ itemMatched = true;
+ }
+ if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
+ && annotations[count].value <= filterParams
+ .getThresholdValue())
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterAlphaHelix()
+ && annotations[count].secondaryStructure == 'H')
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterBetaSheet()
+ && annotations[count].secondaryStructure == 'E')
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterTurn()
+ && annotations[count].secondaryStructure == 'S')
+ {
+ itemMatched = true;
+ }
+
+ String regexSearchString = filterParams.getRegexString();
+ if (regexSearchString != null
+ && !filterParams.getRegexSearchFields().isEmpty())
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
- for (int j = region[0]; j < region[1]+1; j++)
+ List fields = filterParams
+ .getRegexSearchFields();
+ try
{
- addElement(j);
+ if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
+ && annotations[count].displayCharacter
+ .matches(regexSearchString))
+ {
+ itemMatched = true;
+ }
+ } catch (java.util.regex.PatternSyntaxException pse)
+ {
+ if (annotations[count].displayCharacter
+ .equals(regexSearchString))
+ {
+ itemMatched = true;
+ }
}
+ if (fields.contains(SearchableAnnotationField.DESCRIPTION)
+ && annotations[count].description != null
+ && annotations[count].description
+ .matches(regexSearchString))
+ {
+ itemMatched = true;
+ }
+ }
+
+ if (itemMatched)
+ {
+ this.addElement(count);
}
}
+ count++;
+ } while (count < annotations.length);
+ return false;
+ }
+
+ /**
+ * Returns a hashCode built from selected columns ranges
+ */
+ @Override
+ public int hashCode()
+ {
+ return selection.hashCode();
+ }
+
+ /**
+ * Answers true if comparing to a ColumnSelection with the same selected
+ * columns and hidden columns, else false
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof ColumnSelection))
+ {
+ return false;
+ }
+ ColumnSelection that = (ColumnSelection) obj;
- hiddenColumns = null;
+ /*
+ * check columns selected are either both null, or match
+ */
+ if (this.selection == null)
+ {
+ if (that.selection != null)
+ {
+ return false;
+ }
+ }
+ if (!this.selection.equals(that.selection))
+ {
+ return false;
}
- public void revealHiddenColumns(int res)
+ return true;
+ }
+
+ /**
+ * Updates the column selection depending on the parameters, and returns true
+ * if any change was made to the selection
+ *
+ * @param markedColumns
+ * a set identifying marked columns (base 0)
+ * @param startCol
+ * the first column of the range to operate over (base 0)
+ * @param endCol
+ * the last column of the range to operate over (base 0)
+ * @param invert
+ * if true, deselect marked columns and select unmarked
+ * @param extendCurrent
+ * if true, extend rather than replacing the current column selection
+ * @param toggle
+ * if true, toggle the selection state of marked columns
+ *
+ * @return
+ */
+ public boolean markColumns(BitSet markedColumns, int startCol,
+ int endCol, boolean invert, boolean extendCurrent, boolean toggle)
+ {
+ boolean changed = false;
+ if (!extendCurrent && !toggle)
{
- for(int i=0; i= startCol && i <= endCol)
{
- int [] region = (int[])hiddenColumns.elementAt(i);
- if( res == region[0])
+ if (ibs < 0 || i < ibs)
{
- for (int j = region[0]; j < region[1]+1; j++)
+ changed = true;
+ if (toggle && contains(i))
{
- addElement(j);
+ removeElement(i++);
}
-
- hiddenColumns.removeElement(region);
- break;
+ else
+ {
+ addElement(i++);
+ }
+ }
+ else
+ {
+ i = markedColumns.nextClearBit(ibs);
+ ibs = markedColumns.nextSetBit(i);
}
}
- if(hiddenColumns.size()==0)
- hiddenColumns = null;
}
-
- public boolean isVisible(int column)
+ else
{
- for(int i=0; i= startCol && i <= endCol)
{
- int [] region = (int[])hiddenColumns.elementAt(i);
- if( column >= region[0] && column <= region[1])
+ changed = true;
+ if (toggle && contains(i))
+ {
+ removeElement(i);
+ }
+ else
{
- return false;
+ addElement(i);
}
+ i = markedColumns.nextSetBit(i + 1);
}
- return true;
+ }
+ return changed;
+ }
+
+ /**
+ * Adjusts column selections, and the given selection group, to match the
+ * range of a stretch (e.g. mouse drag) operation
+ *
+ * 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);
+ }
+ }
+ }
}