-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)\r
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
- * \r
- * This file is part of Jalview.\r
- * \r
- * Jalview is free software: you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License \r
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
- * \r
- * Jalview is distributed in the hope that it will be useful, but \r
- * WITHOUT ANY WARRANTY; without even the implied warranty \r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
- * PURPOSE. See the GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package jalview.datamodel;\r
-\r
-import java.util.*;\r
-\r
-import jalview.util.*;\r
-\r
-/**\r
- * NOTE: Columns are zero based.\r
- */\r
-public class ColumnSelection\r
-{\r
- Vector selected = new Vector();\r
-\r
- // Vector of int [] {startCol, endCol}\r
- Vector hiddenColumns;\r
-\r
- /**\r
- * Add a column to the selection\r
- * \r
- * @param col\r
- * index of column\r
- */\r
- public void addElement(int col)\r
- {\r
- Integer column = new Integer(col);\r
- if (!selected.contains(column))\r
- {\r
- selected.addElement(column);\r
- }\r
- }\r
-\r
- /**\r
- * clears column selection\r
- */\r
- public void clear()\r
- {\r
- selected.removeAllElements();\r
- }\r
-\r
- /**\r
- * removes col from selection\r
- * \r
- * @param col\r
- * index of column to be removed\r
- */\r
- public void removeElement(int col)\r
- {\r
- Integer colInt = new Integer(col);\r
-\r
- if (selected.contains(colInt))\r
- {\r
- selected.removeElement(colInt);\r
- }\r
- }\r
-\r
- /**\r
- * removes a range of columns from the selection\r
- * \r
- * @param start\r
- * int - first column in range to be removed\r
- * @param end\r
- * int - last col\r
- */\r
- public void removeElements(int start, int end)\r
- {\r
- Integer colInt;\r
- for (int i = start; i < end; i++)\r
- {\r
- colInt = new Integer(i);\r
- if (selected.contains(colInt))\r
- {\r
- selected.removeElement(colInt);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * \r
- * @return Vector containing selected columns as Integers\r
- */\r
- public Vector getSelected()\r
- {\r
- return selected;\r
- }\r
-\r
- /**\r
- * \r
- * @param col\r
- * index to search for in column selection\r
- * \r
- * @return true if Integer(col) is in selection.\r
- */\r
- public boolean contains(int col)\r
- {\r
- return selected.contains(new Integer(col));\r
- }\r
-\r
- /**\r
- * Column number at position i in selection\r
- * \r
- * @param i\r
- * index into selected columns\r
- * \r
- * @return column number in alignment\r
- */\r
- public int columnAt(int i)\r
- {\r
- return ((Integer) selected.elementAt(i)).intValue();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- * \r
- * @return DOCUMENT ME!\r
- */\r
- public int size()\r
- {\r
- return selected.size();\r
- }\r
-\r
- /**\r
- * rightmost selected column\r
- * \r
- * @return rightmost column in alignment that is selected\r
- */\r
- public int getMax()\r
- {\r
- int max = -1;\r
-\r
- for (int i = 0; i < selected.size(); i++)\r
- {\r
- if (columnAt(i) > max)\r
- {\r
- max = columnAt(i);\r
- }\r
- }\r
-\r
- return max;\r
- }\r
-\r
- /**\r
- * Leftmost column in selection\r
- * \r
- * @return column index of leftmost column in selection\r
- */\r
- public int getMin()\r
- {\r
- int min = 1000000000;\r
-\r
- for (int i = 0; i < selected.size(); i++)\r
- {\r
- if (columnAt(i) < min)\r
- {\r
- min = columnAt(i);\r
- }\r
- }\r
-\r
- return min;\r
- }\r
-\r
- /**\r
- * propagate shift in alignment columns to column selection\r
- * \r
- * @param start\r
- * beginning of edit\r
- * @param left\r
- * shift in edit (+ve for removal, or -ve for inserts)\r
- */\r
- public Vector compensateForEdit(int start, int change)\r
- {\r
- Vector deletedHiddenColumns = null;\r
- for (int i = 0; i < size(); i++)\r
- {\r
- int temp = columnAt(i);\r
-\r
- if (temp >= start)\r
- {\r
- selected.setElementAt(new Integer(temp - change), i);\r
- }\r
- }\r
-\r
- if (hiddenColumns != null)\r
- {\r
- deletedHiddenColumns = new Vector();\r
- int hSize = hiddenColumns.size();\r
- for (int i = 0; i < hSize; i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (region[0] > start && start + change > region[1])\r
- {\r
- deletedHiddenColumns.addElement(hiddenColumns.elementAt(i));\r
-\r
- hiddenColumns.removeElementAt(i);\r
- i--;\r
- hSize--;\r
- continue;\r
- }\r
-\r
- if (region[0] > start)\r
- {\r
- region[0] -= change;\r
- region[1] -= change;\r
- }\r
-\r
- if (region[0] < 0)\r
- {\r
- region[0] = 0;\r
- }\r
-\r
- }\r
-\r
- this.revealHiddenColumns(0);\r
- }\r
-\r
- return deletedHiddenColumns;\r
- }\r
-\r
- /**\r
- * propagate shift in alignment columns to column selection special version of\r
- * compensateForEdit - allowing for edits within hidden regions\r
- * \r
- * @param start\r
- * beginning of edit\r
- * @param left\r
- * shift in edit (+ve for removal, or -ve for inserts)\r
- */\r
- private void compensateForDelEdits(int start, int change)\r
- {\r
- for (int i = 0; i < size(); i++)\r
- {\r
- int temp = columnAt(i);\r
-\r
- if (temp >= start)\r
- {\r
- selected.setElementAt(new Integer(temp - change), i);\r
- }\r
- }\r
-\r
- if (hiddenColumns != null)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (region[0] >= start)\r
- {\r
- region[0] -= change;\r
- }\r
- if (region[1] >= start)\r
- {\r
- region[1] -= change;\r
- }\r
- if (region[1] < region[0])\r
- {\r
- hiddenColumns.removeElementAt(i--);\r
- }\r
-\r
- if (region[0] < 0)\r
- {\r
- region[0] = 0;\r
- }\r
- if (region[1] < 0)\r
- {\r
- region[1] = 0;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Adjust hidden column boundaries based on a series of column additions or\r
- * deletions in visible regions.\r
- * \r
- * @param shiftrecord\r
- * @return\r
- */\r
- public ShiftList compensateForEdits(ShiftList shiftrecord)\r
- {\r
- if (shiftrecord != null)\r
- {\r
- Vector shifts = shiftrecord.shifts;\r
- if (shifts != null && shifts.size() > 0)\r
- {\r
- int shifted = 0;\r
- for (int i = 0, j = shifts.size(); i < j; i++)\r
- {\r
- int[] sh = (int[]) shifts.elementAt(i);\r
- // compensateForEdit(shifted+sh[0], sh[1]);\r
- compensateForDelEdits(shifted + sh[0], sh[1]);\r
- shifted -= sh[1];\r
- }\r
- }\r
- return shiftrecord.getInverse();\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * removes intersection of position,length ranges in deletions from the\r
- * start,end regions marked in intervals.\r
- * \r
- * @param deletions\r
- * @param intervals\r
- * @return\r
- */\r
- private boolean pruneIntervalVector(Vector deletions, Vector intervals)\r
- {\r
- boolean pruned = false;\r
- int i = 0, j = intervals.size() - 1, s = 0, t = deletions.size() - 1;\r
- int hr[] = (int[]) intervals.elementAt(i);\r
- int sr[] = (int[]) deletions.elementAt(s);\r
- while (i <= j && s <= t)\r
- {\r
- boolean trailinghn = hr[1] >= sr[0];\r
- if (!trailinghn)\r
- {\r
- if (i < j)\r
- {\r
- hr = (int[]) intervals.elementAt(++i);\r
- }\r
- else\r
- {\r
- i++;\r
- }\r
- continue;\r
- }\r
- int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert\r
- if (endshift < hr[0] || endshift < sr[0])\r
- { // leadinghc disjoint or not a deletion\r
- if (s < t)\r
- {\r
- sr = (int[]) deletions.elementAt(++s);\r
- }\r
- else\r
- {\r
- s++;\r
- }\r
- continue;\r
- }\r
- boolean leadinghn = hr[0] >= sr[0];\r
- boolean leadinghc = hr[0] < endshift;\r
- boolean trailinghc = hr[1] < endshift;\r
- if (leadinghn)\r
- {\r
- if (trailinghc)\r
- { // deleted hidden region.\r
- intervals.removeElementAt(i);\r
- pruned = true;\r
- j--;\r
- if (i <= j)\r
- {\r
- hr = (int[]) intervals.elementAt(i);\r
- }\r
- continue;\r
- }\r
- if (leadinghc)\r
- {\r
- hr[0] = endshift; // clip c terminal region\r
- leadinghn = !leadinghn;\r
- pruned = true;\r
- }\r
- }\r
- if (!leadinghn)\r
- {\r
- if (trailinghc)\r
- {\r
- if (trailinghn)\r
- {\r
- hr[1] = sr[0] - 1;\r
- pruned = true;\r
- }\r
- }\r
- else\r
- {\r
- // sr contained in hr\r
- if (s < t)\r
- {\r
- sr = (int[]) deletions.elementAt(++s);\r
- }\r
- else\r
- {\r
- s++;\r
- }\r
- continue;\r
- }\r
- }\r
- }\r
- return pruned; // true if any interval was removed or modified by\r
- // operations.\r
- }\r
-\r
- private boolean pruneColumnList(Vector deletion, Vector list)\r
- {\r
- int s = 0, t = deletion.size();\r
- int[] sr = (int[]) list.elementAt(s++);\r
- boolean pruned = false;\r
- int i = 0, j = list.size();\r
- while (i < j && s <= t)\r
- {\r
- int c = ((Integer) list.elementAt(i++)).intValue();\r
- if (sr[0] <= c)\r
- {\r
- if (sr[1] + sr[0] >= c)\r
- { // sr[1] -ve means inseriton.\r
- list.removeElementAt(--i);\r
- j--;\r
- }\r
- else\r
- {\r
- if (s < t)\r
- {\r
- sr = (int[]) deletion.elementAt(s);\r
- }\r
- s++;\r
- }\r
- }\r
- }\r
- return pruned;\r
- }\r
-\r
- /**\r
- * remove any hiddenColumns or selected columns and shift remaining based on a\r
- * series of position, range deletions.\r
- * \r
- * @param deletions\r
- */\r
- public void pruneDeletions(ShiftList deletions)\r
- {\r
- if (deletions != null)\r
- {\r
- Vector shifts = deletions.shifts;\r
- if (shifts != null && shifts.size() > 0)\r
- {\r
- // delete any intervals intersecting.\r
- if (hiddenColumns != null)\r
- {\r
- pruneIntervalVector(shifts, hiddenColumns);\r
- if (hiddenColumns != null && hiddenColumns.size() == 0)\r
- {\r
- hiddenColumns = null;\r
- }\r
- }\r
- if (selected != null && selected.size() > 0)\r
- {\r
- pruneColumnList(shifts, selected);\r
- if (selected != null && selected.size() == 0)\r
- {\r
- selected = null;\r
- }\r
- }\r
- // and shift the rest.\r
- this.compensateForEdits(deletions);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * This Method is used to return all the HiddenColumn regions less than the\r
- * given index.\r
- * \r
- * @param end\r
- * int\r
- * @return Vector\r
- */\r
- public Vector getHiddenColumns()\r
- {\r
- return hiddenColumns;\r
- }\r
-\r
- /**\r
- * Return absolute column index for a visible column index\r
- * \r
- * @param column\r
- * int column index in alignment view\r
- * @return alignment column index for column\r
- */\r
- public int adjustForHiddenColumns(int column)\r
- {\r
- int result = column;\r
- if (hiddenColumns != null)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (result >= region[0])\r
- {\r
- result += region[1] - region[0] + 1;\r
- }\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- /**\r
- * Use this method to find out where a column will appear in the visible alignment when\r
- * hidden columns exist. If the column is not visible, then the left-most visible column will always be returned.\r
- * \r
- * @param hiddenColumn\r
- * int\r
- * @return int\r
- */\r
- public int findColumnPosition(int hiddenColumn)\r
- {\r
- int result = hiddenColumn;\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- int[] region;\r
- do\r
- {\r
- region = (int[]) hiddenColumns.elementAt(index++);\r
- if (hiddenColumn > region[1])\r
- {\r
- result -= region[1] + 1 - region[0];\r
- }\r
- } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size()));\r
- if (hiddenColumn>region[0] && hiddenColumn<region[1])\r
- {\r
- return region[0]+hiddenColumn-result;\r
- }\r
- }\r
- return result; // return the shifted position after removing hidden columns.\r
- }\r
-\r
- /**\r
- * Use this method to determine where the next hiddenRegion starts\r
- */\r
- public int findHiddenRegionPosition(int hiddenRegion)\r
- {\r
- int result = 0;\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- int gaps = 0;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if (hiddenRegion == 0)\r
- {\r
- return region[0];\r
- }\r
-\r
- gaps += region[1] + 1 - region[0];\r
- result = region[1] + 1;\r
- index++;\r
- } while (index < hiddenRegion + 1);\r
-\r
- result -= gaps;\r
- }\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- * THis method returns the rightmost limit of a region of an alignment with\r
- * hidden columns. In otherwords, the next hidden column.\r
- * \r
- * @param index\r
- * int\r
- */\r
- public int getHiddenBoundaryRight(int alPos)\r
- {\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if (alPos < region[0])\r
- {\r
- return region[0];\r
- }\r
-\r
- index++;\r
- } while (index < hiddenColumns.size());\r
- }\r
-\r
- return alPos;\r
-\r
- }\r
-\r
- /**\r
- * This method returns the leftmost limit of a region of an alignment with\r
- * hidden columns. In otherwords, the previous hidden column.\r
- * \r
- * @param index\r
- * int\r
- */\r
- public int getHiddenBoundaryLeft(int alPos)\r
- {\r
- if (hiddenColumns != null)\r
- {\r
- int index = hiddenColumns.size() - 1;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if (alPos > region[1])\r
- {\r
- return region[1];\r
- }\r
-\r
- index--;\r
- } while (index > -1);\r
- }\r
-\r
- return alPos;\r
-\r
- }\r
-\r
- public void hideSelectedColumns()\r
- {\r
- while (size() > 0)\r
- {\r
- int column = ((Integer) getSelected().firstElement()).intValue();\r
- hideColumns(column);\r
- }\r
-\r
- }\r
-\r
- public void hideColumns(int start, int end)\r
- {\r
- if (hiddenColumns == null)\r
- {\r
- hiddenColumns = new Vector();\r
- }\r
-\r
- boolean added = false;\r
- boolean overlap = false;\r
-\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (start <= region[1] && end >= region[0])\r
- {\r
- hiddenColumns.removeElementAt(i);\r
- overlap = true;\r
- break;\r
- }\r
- else if (end < region[0] && start < region[0])\r
- {\r
- hiddenColumns.insertElementAt(new int[]\r
- { start, end }, i);\r
- added = true;\r
- break;\r
- }\r
- }\r
-\r
- if (overlap)\r
- {\r
- hideColumns(start, end);\r
- }\r
- else if (!added)\r
- {\r
- hiddenColumns.addElement(new int[]\r
- { start, end });\r
- }\r
-\r
- }\r
-\r
- /**\r
- * This method will find a range of selected columns around the column\r
- * specified\r
- * \r
- * @param res\r
- * int\r
- */\r
- public void hideColumns(int col)\r
- {\r
- // First find out range of columns to hide\r
- int min = col, max = col + 1;\r
- while (contains(min))\r
- {\r
- removeElement(min);\r
- min--;\r
- }\r
-\r
- while (contains(max))\r
- {\r
- removeElement(max);\r
- max++;\r
- }\r
-\r
- min++;\r
- max--;\r
- if (min > max)\r
- {\r
- min = max;\r
- }\r
-\r
- hideColumns(min, max);\r
- }\r
-\r
- public void revealAllHiddenColumns()\r
- {\r
- if (hiddenColumns != null)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- for (int j = region[0]; j < region[1] + 1; j++)\r
- {\r
- addElement(j);\r
- }\r
- }\r
- }\r
-\r
- hiddenColumns = null;\r
- }\r
-\r
- public void revealHiddenColumns(int res)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (res == region[0])\r
- {\r
- for (int j = region[0]; j < region[1] + 1; j++)\r
- {\r
- addElement(j);\r
- }\r
-\r
- hiddenColumns.removeElement(region);\r
- break;\r
- }\r
- }\r
- if (hiddenColumns.size() == 0)\r
- {\r
- hiddenColumns = null;\r
- }\r
- }\r
-\r
- public boolean isVisible(int column)\r
- {\r
- if (hiddenColumns != null)\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (column >= region[0] && column <= region[1])\r
- {\r
- return false;\r
- }\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Copy constructor\r
- * \r
- * @param copy\r
- */\r
- public ColumnSelection(ColumnSelection copy)\r
- {\r
- if (copy != null)\r
- {\r
- if (copy.selected != null)\r
- {\r
- selected = new Vector();\r
- for (int i = 0, j = copy.selected.size(); i < j; i++)\r
- {\r
- selected.addElement(copy.selected.elementAt(i));\r
- }\r
- }\r
- if (copy.hiddenColumns != null)\r
- {\r
- hiddenColumns = new Vector(copy.hiddenColumns.size());\r
- for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)\r
- {\r
- int[] rh, cp;\r
- rh = (int[]) copy.hiddenColumns.elementAt(i);\r
- if (rh != null)\r
- {\r
- cp = new int[rh.length];\r
- System.arraycopy(rh, 0, cp, 0, rh.length);\r
- hiddenColumns.addElement(cp);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * ColumnSelection\r
- */\r
- public ColumnSelection()\r
- {\r
- }\r
-\r
- public String[] getVisibleSequenceStrings(int start, int end,\r
- SequenceI[] seqs)\r
- {\r
- int i, iSize = seqs.length;\r
- String selection[] = new String[iSize];\r
- if (hiddenColumns != null && hiddenColumns.size() > 0)\r
- {\r
- for (i = 0; i < iSize; i++)\r
- {\r
- StringBuffer visibleSeq = new StringBuffer();\r
- Vector regions = getHiddenColumns();\r
-\r
- int blockStart = start, blockEnd = end;\r
- int[] region;\r
- int hideStart, hideEnd;\r
-\r
- for (int j = 0; j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
-\r
- if (hideStart < start)\r
- {\r
- continue;\r
- }\r
-\r
- blockStart = Math.min(blockStart, hideEnd + 1);\r
- blockEnd = Math.min(blockEnd, hideStart);\r
-\r
- if (blockStart > blockEnd)\r
- {\r
- break;\r
- }\r
-\r
- visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));\r
-\r
- blockStart = hideEnd + 1;\r
- blockEnd = end;\r
- }\r
-\r
- if (end > blockStart)\r
- {\r
- visibleSeq.append(seqs[i].getSequence(blockStart, end));\r
- }\r
-\r
- selection[i] = visibleSeq.toString();\r
- }\r
- }\r
- else\r
- {\r
- for (i = 0; i < iSize; i++)\r
- {\r
- selection[i] = seqs[i].getSequenceAsString(start, end);\r
- }\r
- }\r
-\r
- return selection;\r
- }\r
-\r
- /**\r
- * return all visible segments between the given start and end boundaries\r
- * \r
- * @param start\r
- * (first column inclusive from 0)\r
- * @param end\r
- * (last column - not inclusive)\r
- * @return int[] {i_start, i_end, ..} where intervals lie in\r
- * start<=i_start<=i_end<end\r
- */\r
- public int[] getVisibleContigs(int start, int end)\r
- {\r
- if (hiddenColumns != null && hiddenColumns.size() > 0)\r
- {\r
- Vector visiblecontigs = new Vector();\r
- Vector regions = getHiddenColumns();\r
-\r
- int vstart = start;\r
- int[] region;\r
- int hideStart, hideEnd;\r
-\r
- for (int j = 0; vstart < end && j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
-\r
- if (hideEnd < vstart)\r
- {\r
- continue;\r
- }\r
- if (hideStart > vstart)\r
- {\r
- visiblecontigs.addElement(new int[]\r
- { vstart, hideStart - 1 });\r
- }\r
- vstart = hideEnd + 1;\r
- }\r
-\r
- if (vstart < end)\r
- {\r
- visiblecontigs.addElement(new int[]\r
- { vstart, end - 1 });\r
- }\r
- int[] vcontigs = new int[visiblecontigs.size() * 2];\r
- for (int i = 0, j = visiblecontigs.size(); i < j; i++)\r
- {\r
- int[] vc = (int[]) visiblecontigs.elementAt(i);\r
- visiblecontigs.setElementAt(null, i);\r
- vcontigs[i * 2] = vc[0];\r
- vcontigs[i * 2 + 1] = vc[1];\r
- }\r
- visiblecontigs.removeAllElements();\r
- return vcontigs;\r
- }\r
- else\r
- {\r
- return new int[]\r
- { start, end - 1 };\r
- }\r
- }\r
-\r
- /**\r
- * delete any columns in alignmentAnnotation that are hidden (including\r
- * sequence associated annotation).\r
- * \r
- * @param alignmentAnnotation\r
- */\r
- public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)\r
- {\r
- makeVisibleAnnotation(-1, -1, alignmentAnnotation);\r
- }\r
-\r
- /**\r
- * delete any columns in alignmentAnnotation that are hidden (including\r
- * sequence associated annotation).\r
- * \r
- * @param start\r
- * remove any annotation to the right of this column\r
- * @param end\r
- * remove any annotation to the left of this column\r
- * @param alignmentAnnotation\r
- * the annotation to operate on\r
- */\r
- public void makeVisibleAnnotation(int start, int end,\r
- AlignmentAnnotation alignmentAnnotation)\r
- {\r
- if (alignmentAnnotation.annotations == null)\r
- {\r
- return;\r
- }\r
- if (start == end && end == -1)\r
- {\r
- start = 0;\r
- end = alignmentAnnotation.annotations.length;\r
- }\r
- if (hiddenColumns != null && hiddenColumns.size() > 0)\r
- {\r
- // then mangle the alignmentAnnotation annotation array\r
- Vector annels = new Vector();\r
- Annotation[] els = null;\r
- Vector regions = getHiddenColumns();\r
- int blockStart = start, blockEnd = end;\r
- int[] region;\r
- int hideStart, hideEnd, w = 0;\r
-\r
- for (int j = 0; j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
-\r
- if (hideStart < start)\r
- {\r
- continue;\r
- }\r
-\r
- blockStart = Math.min(blockStart, hideEnd + 1);\r
- blockEnd = Math.min(blockEnd, hideStart);\r
-\r
- if (blockStart > blockEnd)\r
- {\r
- break;\r
- }\r
-\r
- annels.addElement(els = new Annotation[blockEnd - blockStart]);\r
- System.arraycopy(alignmentAnnotation.annotations, blockStart, els,\r
- 0, els.length);\r
- w += els.length;\r
- blockStart = hideEnd + 1;\r
- blockEnd = end;\r
- }\r
-\r
- if (end > blockStart)\r
- {\r
- annels.addElement(els = new Annotation[end - blockStart + 1]);\r
- if ((els.length + blockStart) <= alignmentAnnotation.annotations.length)\r
- {\r
- // copy just the visible segment of the annotation row\r
- System.arraycopy(alignmentAnnotation.annotations, blockStart,\r
- els, 0, els.length);\r
- }\r
- else\r
- {\r
- // copy to the end of the annotation row\r
- System.arraycopy(alignmentAnnotation.annotations, blockStart,\r
- els, 0,\r
- (alignmentAnnotation.annotations.length - blockStart));\r
- }\r
- w += els.length;\r
- }\r
- if (w == 0)\r
- return;\r
- Enumeration e = annels.elements();\r
- alignmentAnnotation.annotations = new Annotation[w];\r
- w = 0;\r
- while (e.hasMoreElements())\r
- {\r
- Annotation[] chnk = (Annotation[]) e.nextElement();\r
- System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,\r
- chnk.length);\r
- w += chnk.length;\r
- }\r
- }\r
- else\r
- {\r
- alignmentAnnotation.restrict(start, end);\r
- }\r
- }\r
-\r
- /**\r
- * Invert the column selection from first to end-1. leaves hiddenColumns\r
- * untouched (and unselected)\r
- * \r
- * @param first\r
- * @param end\r
- */\r
- public void invertColumnSelection(int first, int width)\r
- {\r
- boolean hasHidden = hiddenColumns != null && hiddenColumns.size() > 0;\r
- for (int i = first; i < width; i++)\r
- {\r
- if (contains(i))\r
- {\r
- removeElement(i);\r
- }\r
- else\r
- {\r
- if (!hasHidden || isVisible(i))\r
- {\r
- addElement(i);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * add in any unselected columns from the given column selection, excluding\r
- * any that are hidden.\r
- * \r
- * @param colsel\r
- */\r
- public void addElementsFrom(ColumnSelection colsel)\r
- {\r
- if (colsel != null && colsel.size() > 0)\r
- {\r
- Enumeration e = colsel.getSelected().elements();\r
- while (e.hasMoreElements())\r
- {\r
- Object eo = e.nextElement();\r
- if (hiddenColumns != null && isVisible(((Integer) eo).intValue()))\r
- {\r
- if (!selected.contains(eo))\r
- {\r
- selected.addElement(eo);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * set the selected columns the given column selection, excluding any columns\r
- * that are hidden.\r
- * \r
- * @param colsel\r
- */\r
- public void setElementsFrom(ColumnSelection colsel)\r
- {\r
- selected = new Vector();\r
- if (colsel.selected != null && colsel.selected.size() > 0)\r
- {\r
- if (hiddenColumns != null && hiddenColumns.size() > 0)\r
- {\r
- // only select visible columns in this columns selection\r
- selected = new Vector();\r
- addElementsFrom(colsel);\r
- }\r
- else\r
- {\r
- // add everything regardless\r
- Enumeration en = colsel.selected.elements();\r
- while (en.hasMoreElements())\r
- {\r
- selected.addElement(en.nextElement());\r
- }\r
- }\r
- }\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.datamodel;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.PatternSyntaxException;
+
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
+
+/**
+ * Data class holding the selected columns and hidden column ranges for a view.
+ * Ranges are base 1.
+ */
+public class ColumnSelection
+{
+ /**
+ * A class to hold an efficient representation of selected columns
+ */
+ private class IntList
+ {
+ /*
+ * list of selected columns (ordered by selection order, not column order)
+ */
+ 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;
+
+ /**
+ * Constructor
+ */
+ IntList()
+ {
+ order = new ArrayList<>();
+ _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
+ */
+ void add(int i)
+ {
+ if (!selected.get(i))
+ {
+ order.add(Integer.valueOf(i));
+ selected.set(i);
+ }
+ }
+
+ void clear()
+ {
+ order.clear();
+ selected.clear();
+ }
+
+ void remove(int col)
+ {
+
+ Integer colInt = Integer.valueOf(col);
+
+ if (selected.get(col))
+ {
+ // if this ever changes to List.remove(), ensure Integer not int
+ // argument
+ // as List.remove(int i) removes the i'th item which is wrong
+ order.remove(colInt);
+ selected.clear(col);
+ }
+ }
+
+ boolean contains(Integer colInt)
+ {
+ return selected.get(colInt);
+ }
+
+ boolean isEmpty()
+ {
+ return order.isEmpty();
+ }
+
+ /**
+ * Returns a read-only view of the selected columns list
+ *
+ * @return
+ */
+ List<Integer> getList()
+ {
+ return _uorder;
+ }
+
+ int size()
+ {
+ return order.size();
+ }
+
+ /**
+ * gets the column that was selected first, second or i'th
+ *
+ * @param i
+ * @return
+ */
+ int elementAt(int i)
+ {
+ return order.get(i);
+ }
+
+ protected boolean pruneColumnList(final List<int[]> shifts)
+ {
+ int s = 0, t = shifts.size();
+ int[] sr = shifts.get(s++);
+ boolean pruned = false;
+ int i = 0, j = order.size();
+ while (i < j && s <= t)
+ {
+ int c = order.get(i++).intValue();
+ if (sr[0] <= c)
+ {
+ if (sr[1] + sr[0] >= c)
+ { // sr[1] -ve means inseriton.
+ order.remove(--i);
+ selected.clear(c);
+ j--;
+ }
+ else
+ {
+ if (s < t)
+ {
+ sr = shifts.get(s);
+ }
+ s++;
+ }
+ }
+ }
+ return pruned;
+ }
+
+ /**
+ * shift every selected column at or above start by change
+ *
+ * @param start
+ * - leftmost column to be shifted
+ * @param change
+ * - delta for shift
+ */
+ void compensateForEdits(int start, int change)
+ {
+ BitSet mask = new BitSet();
+ for (int i = 0; i < order.size(); i++)
+ {
+ int temp = order.get(i);
+
+ if (temp >= start)
+ {
+ // clear shifted bits and update List of selected columns
+ selected.clear(temp);
+ mask.set(temp - change);
+ order.set(i, Integer.valueOf(temp - change));
+ }
+ }
+ // lastly update the bitfield all at once
+ selected.or(mask);
+ }
+
+ boolean isSelected(int column)
+ {
+ return selected.get(column);
+ }
+
+ int getMaxColumn()
+ {
+ return selected.length() - 1;
+ }
+
+ int getMinColumn()
+ {
+ return selected.get(0) ? 0 : selected.nextSetBit(0);
+ }
+
+ /**
+ * @return a series of selection intervals along the range
+ */
+ List<int[]> getRanges()
+ {
+ List<int[]> rlist = new ArrayList<>();
+ 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;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ // TODO Auto-generated method stub
+ return selected.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof IntList)
+ {
+ return ((IntList) obj).selected.equals(selected);
+ }
+ return false;
+ }
+ }
+
+ private 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++)
+ {
+ colInt = Integer.valueOf(i);
+ if (selection.contains(colInt))
+ {
+ selection.remove(colInt);
+ }
+ }
+ }
+
+ /**
+ * 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 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<int[]> 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;
+ }
+
+ /**
+ *
+ */
+ public boolean intersects(int from, int to)
+ {
+ // TODO: do this in a more efficient bitwise way
+ for (int f = from; f <= to; f++)
+ {
+ if (selection.isSelected(f))
+ {
+ return true;
+ }
+ }
+ return 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();
+ }
+
+ public void hideSelectedColumns(AlignmentI al)
+ {
+ synchronized (selection)
+ {
+ for (int[] selregions : selection.getRanges())
+ {
+ al.getHiddenColumns().hideColumns(selregions[0], selregions[1]);
+ }
+ selection.clear();
+ }
+
+ }
+
+ /**
+ * 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--;
+ }
+
+ while (contains(max))
+ {
+ removeElement(max);
+ max++;
+ }
+
+ /*
+ * min, max are now the closest unselected columns
+ */
+ min++;
+ max--;
+ if (min > max)
+ {
+ min = max;
+ }
+
+ hidden.hideColumns(min, max);
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copy
+ */
+ public ColumnSelection(ColumnSelection copy)
+ {
+ if (copy != null)
+ {
+ selection = new IntList(copy.selection);
+ }
+ }
+
+ /**
+ * ColumnSelection
+ */
+ public ColumnSelection()
+ {
+ }
+
+ /**
+ * 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().hasHiddenColumns();
+ for (int i = first; i < width; i++)
+ {
+ if (contains(i))
+ {
+ removeElement(i);
+ }
+ else
+ {
+ if (!hasHidden || al.getHiddenColumns().isVisible(i))
+ {
+ addElement(i);
+ }
+ }
+ }
+ }
+
+ /**
+ * 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.hasHiddenColumns())
+ {
+ // only select visible columns in this columns selection
+ for (Integer col : colsel.getSelected())
+ {
+ if (hiddenColumns != null
+ && hiddenColumns.isVisible(col.intValue()))
+ {
+ selection.add(col);
+ }
+ }
+ }
+ else
+ {
+ // add everything regardless
+ for (Integer col : colsel.getSelected())
+ {
+ addElement(col);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @return true if there are columns marked
+ */
+ public boolean hasSelectedColumns()
+ {
+ return (selection != null && selection.size() > 0);
+ }
+
+ /**
+ * Selects columns where the given annotation matches the provided filter
+ * condition(s). Any existing column selections are first cleared. Answers the
+ * number of columns added.
+ *
+ * @param annotations
+ * @param filterParams
+ * @return
+ */
+ public int filterAnnotations(AlignmentAnnotation ann_row,
+ AnnotationFilterParameter filterParams)
+ {
+ Annotation[] annotations = ann_row.annotations;
+ // JBPNote - this method needs to be refactored to become independent of
+ // viewmodel package
+ this.clear();
+
+ if (ann_row.graph == AlignmentAnnotation.CUSTOMRENDERER && (filterParams
+ .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+ || filterParams
+ .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD))
+ {
+ float tVal = filterParams.getThresholdValue();
+ if (ann_row.sequenceRef != null)
+ {
+ // TODO - get ContactList from AlignmentView for non-seq-ref associatd
+ for (int column = 0; column < annotations.length; column++)
+ {
+ if (ann_row.annotations[column] == null)
+ {
+ continue;
+ }
+
+ int cpos = ann_row.sequenceRef.findPosition(column) - 1;
+ ContactListI clist = ann_row.sequenceRef
+ .getContactListFor(ann_row, cpos);
+ for (int row = column + 8,
+ rowEnd = clist.getContactHeight(); row < rowEnd; row++)
+ {
+ if (filterParams
+ .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+ ? (clist.getContactAt(row) > tVal)
+ : (clist.getContactAt(row) < tVal))
+ {
+ addElement(column);
+ break;
+ // int column_forrowpos = ann_row.sequenceRef.findIndex(row + 1);
+ // addElement(column_forrowpos);
+ }
+ }
+ }
+ }
+ return selection.size();
+ }
+
+ int addedCount = 0;
+ int column = 0;
+ do
+ {
+ Annotation ann = annotations[column];
+ if (ann != null)
+ {
+ float value = ann.value;
+ boolean matched = false;
+
+ /*
+ * filter may have multiple conditions -
+ * these are or'd until a match is found
+ */
+ if (filterParams
+ .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+ && value > filterParams.getThresholdValue())
+ {
+ matched = true;
+ }
+
+ if (!matched && filterParams
+ .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
+ && value < filterParams.getThresholdValue())
+ {
+ matched = true;
+ }
+
+ if (!matched && filterParams.isFilterAlphaHelix()
+ && ann.secondaryStructure == 'H')
+ {
+ matched = true;
+ }
+
+ if (!matched && filterParams.isFilterBetaSheet()
+ && ann.secondaryStructure == 'E')
+ {
+ matched = true;
+ }
+
+ if (!matched && filterParams.isFilterTurn()
+ && ann.secondaryStructure == 'S')
+ {
+ matched = true;
+ }
+
+ String regexSearchString = filterParams.getRegexString();
+ if (!matched && regexSearchString != null)
+ {
+ List<SearchableAnnotationField> fields = filterParams
+ .getRegexSearchFields();
+ for (SearchableAnnotationField field : fields)
+ {
+ String compareTo = field == SearchableAnnotationField.DISPLAY_STRING
+ ? ann.displayCharacter // match 'Label'
+ : ann.description; // and/or 'Description'
+ if (compareTo != null)
+ {
+ try
+ {
+ if (compareTo.matches(regexSearchString))
+ {
+ matched = true;
+ }
+ } catch (PatternSyntaxException pse)
+ {
+ if (compareTo.equals(regexSearchString))
+ {
+ matched = true;
+ }
+ }
+ if (matched)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ if (matched)
+ {
+ this.addElement(column);
+ addedCount++;
+ }
+ }
+ column++;
+ } while (column < annotations.length);
+
+ return addedCount;
+ }
+
+ /**
+ * 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;
+
+ /*
+ * 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;
+ }
+
+ 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)
+ {
+ changed = !this.isEmpty();
+ clear();
+ }
+ if (invert)
+ {
+ // invert only in the currently selected sequence region
+ int i = markedColumns.nextClearBit(startCol);
+ int ibs = markedColumns.nextSetBit(startCol);
+ while (i >= startCol && i <= endCol)
+ {
+ if (ibs < 0 || i < ibs)
+ {
+ changed = true;
+ if (toggle && contains(i))
+ {
+ removeElement(i++);
+ }
+ else
+ {
+ addElement(i++);
+ }
+ }
+ else
+ {
+ i = markedColumns.nextClearBit(ibs);
+ ibs = markedColumns.nextSetBit(i);
+ }
+ }
+ }
+ else
+ {
+ int i = markedColumns.nextSetBit(startCol);
+ while (i >= startCol && i <= endCol)
+ {
+ changed = true;
+ if (toggle && contains(i))
+ {
+ removeElement(i);
+ }
+ else
+ {
+ addElement(i);
+ }
+ i = markedColumns.nextSetBit(i + 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);
+ }
+ }
+ }
+}