-
- index++;
- } while (index < hiddenColumns.size());
- }
-
- return alPos;
- } finally
- {
- LOCK.readLock().unlock();
- }
-
- }
-
- /**
- * This method returns the leftmost limit of a region of an alignment with
- * hidden columns. In otherwords, the previous hidden column.
- *
- * @param index
- * int
- */
- public int getHiddenBoundaryLeft(int alPos)
- {
- try
- {
- LOCK.readLock().lock();
-
- if (hiddenColumns != null)
- {
- int index = hiddenColumns.size() - 1;
- do
- {
- int[] region = hiddenColumns.elementAt(index);
- if (alPos > region[1])
- {
- return region[1];
- }
-
- index--;
- } while (index > -1);
- }
-
- return alPos;
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- /**
- * This method returns the index of the hidden region to the left of a column
- * position. If the column is in a hidden region it returns the index of the
- * region to the left. If there is no hidden region to the left it returns -1.
- *
- * @param pos
- * int
- */
- private int getHiddenIndexLeft(int pos)
- {
- try
- {
-
- LOCK.readLock().lock();
- if (hiddenColumns != null)
- {
- int index = hiddenColumns.size() - 1;
- do
- {
- int[] region = hiddenColumns.elementAt(index);
- if (pos > region[1])
- {
- return index;
- }
-
- index--;
- } while (index > -1);
- }
-
- return -1;
- } finally
- {
- LOCK.readLock().unlock();
- }
-
- }
-
- /**
- * Adds the specified column range to the hidden columns
- *
- * @param start
- * @param end
- */
- public void hideColumns(int start, int end)
- {
- hideColumns(start, end, false);
- }
-
- /**
- * Adds the specified column range to the hidden columns
- *
- * @param start
- * @param end
- */
- private void hideColumns(int start, int end, boolean alreadyLocked)
- {
- try
- {
-
- if (!alreadyLocked)
- {
- LOCK.writeLock().lock();
- }
-
- if (hiddenColumns == null)
- {
- hiddenColumns = new Vector<>();
- }
-
- /*
- * traverse existing hidden ranges and insert / amend / append as
- * appropriate
- */
- for (int i = 0; i < hiddenColumns.size(); i++)
- {
- int[] region = hiddenColumns.elementAt(i);
-
- if (end < region[0] - 1)
- {
- /*
- * insert discontiguous preceding range
- */
- hiddenColumns.insertElementAt(new int[] { start, end }, i);
- return;
- }
-
- if (end <= region[1])
- {
- /*
- * new range overlaps existing, or is contiguous preceding it - adjust
- * start column
- */
- region[0] = Math.min(region[0], start);
- return;
- }
-
- if (start <= region[1] + 1)
- {
- /*
- * new range overlaps existing, or is contiguous following it - adjust
- * start and end columns
- */
- 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;
- }
- }
-
- /*
- * remaining case is that the new range follows everything else
- */
- hiddenColumns.addElement(new int[] { start, end });
- } finally
- {
- if (!alreadyLocked)
- {
- LOCK.writeLock().unlock();
- }
- }
- }
-
- public boolean isVisible(int column)
- {
- try
- {
- LOCK.readLock().lock();
-
- if (hiddenColumns != null)
- {
- for (int[] region : hiddenColumns)
- {
- if (column >= region[0] && column <= region[1])
- {
- return false;
- }
- }
- }
-
- return true;
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- /**
- * ColumnSelection
- */
- public HiddenColumns()
- {
- }
-
- /**
- * Copy constructor
- *
- * @param copy
- */
- public HiddenColumns(HiddenColumns copy)
- {
- try
- {
-
- LOCK.readLock().lock();
- if (copy != null)
- {
- if (copy.hiddenColumns != null)
- {
- hiddenColumns = copy.copyHiddenRegions();
- }
- }
- }
- finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- private Vector<int[]> copyHiddenRegions()
- {
- Vector<int[]> copy = new Vector<>(hiddenColumns.size());
- for (int i = 0, j = hiddenColumns.size(); i < j; i++)
- {
- int[] rh;
- int[] cp;
- rh = hiddenColumns.elementAt(i);
- if (rh != null)
- {
- cp = new int[rh.length];
- System.arraycopy(rh, 0, cp, 0, rh.length);
- copy.addElement(cp);
- }
- }
- return copy;
- }
-
- private ArrayList<int[]> copyHiddenRegionsToArrayList()
- {
- ArrayList<int[]> copy = new ArrayList<>(hiddenColumns.size());
- for (int i = 0, j = hiddenColumns.size(); i < j; i++)
- {
- int[] rh;
- int[] cp;
- rh = hiddenColumns.elementAt(i);
- if (rh != null)
- {
- cp = new int[rh.length];
- System.arraycopy(rh, 0, cp, 0, rh.length);
- copy.add(cp);
- }
- }
- return copy;
- }
-
- /**
- * Returns a copy of the vector of hidden regions, as a vector. Before using
- * this method please consider if you really need access to the hidden regions
- * - a new (or existing!) method on HiddenColumns might be more appropriate.
- *
- * @return hidden regions as vector of [start,end] pairs
- */
- public Vector<int[]> getHiddenColumnsCopy()
- {
- try
- {
- LOCK.readLock().lock();
- return copyHiddenRegions();
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- /**
- * Returns a copy of the vector of hidden regions, as an ArrayList. Before
- * using this method please consider if you really need access to the hidden
- * regions - a new (or existing!) method on HiddenColumns might be more
- * appropriate.
- *
- * @return hidden regions as an ArrayList of [start,end] pairs
- */
- public ArrayList<int[]> getHiddenColumnsCopyAsList()
- {
- try
- {
- LOCK.readLock().lock();
- return copyHiddenRegionsToArrayList();
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- /**
- * 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,
- ColumnSelection sel)
- {
- try
- {
- LOCK.writeLock().lock();
- List<int[]> deletedHiddenColumns = null;
-
- if (hiddenColumns != null)
- {
- deletedHiddenColumns = new ArrayList<>();
- int hSize = hiddenColumns.size();
- for (int i = 0; i < hSize; i++)
- {
- int[] region = hiddenColumns.elementAt(i);
- if (region[0] > start && start + change > region[1])
- {
- deletedHiddenColumns.add(region);
-
- hiddenColumns.removeElementAt(i);
- i--;
- hSize--;
- continue;
- }
-
- if (region[0] > start)
- {
- region[0] -= change;
- region[1] -= change;
- }
-
- if (region[0] < 0)