JAL-2674 Changes to pasting
[jalview.git] / src / jalview / datamodel / HiddenColumns.java
index 88af9fa..a704b3c 100644 (file)
@@ -73,6 +73,49 @@ public class HiddenColumns
   }
 
   /**
+   * Copy constructor within bounds and with offset. Copies hidden column
+   * regions fully contained between start and end, and offsets positions by
+   * subtracting offset.
+   * 
+   * @param copy
+   *          HiddenColumns instance to copy from
+   * @param start
+   *          lower bound to copy from
+   * @param end
+   *          upper bound to copy to
+   * @param offset
+   *          offset to subtract from each region boundary position
+   * 
+   */
+  public HiddenColumns(HiddenColumns copy, int start, int end, int offset)
+  {
+    try
+    {
+      LOCK.writeLock().lock();
+      if (copy != null)
+      {
+        hiddenColumns = new ArrayList<>();
+        Iterator<int[]> it = copy.getBoundedIterator(start, end, true);
+        while (it.hasNext())
+        {
+          int[] region = it.next();
+          // still need to check boundaries because iterator returns
+          // all overlapping regions and we need contained regions
+          if (region[0] >= start && region[1] <= end)
+          {
+            hiddenColumns.add(
+                    new int[]
+            { region[0] - offset, region[1] - offset });
+          }
+        }
+      }
+    } finally
+    {
+      LOCK.writeLock().unlock();
+    }
+  }
+
+  /**
    * This method is used to return all the HiddenColumn regions and is intended
    * to remain private. External callers which need a copy of the regions can
    * call getHiddenColumnsCopyAsList.