From: kiramt Date: Tue, 26 Sep 2017 12:46:26 +0000 (+0100) Subject: JAL-2674 Changes to pasting X-Git-Tag: Release_2_10_4~55^2~1^2~107 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=761905b8d753ec00c5bee0abb8de1840ff580165;p=jalview.git JAL-2674 Changes to pasting --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index ed04a0a..f28a906 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1900,7 +1900,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, static StringBuffer copiedSequences; - static Vector copiedHiddenColumns; + static HiddenColumns copiedHiddenColumns; protected void copy_actionPerformed() { @@ -1924,14 +1924,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null) { - copiedHiddenColumns = new Vector<>(viewport.getAlignment() - .getHiddenColumns().getHiddenColumnsCopy()); int hiddenOffset = viewport.getSelectionGroup().getStartRes(); - for (int[] region : copiedHiddenColumns) - { - region[0] = region[0] - hiddenOffset; - region[1] = region[1] - hiddenOffset; - } + int hiddenCutoff = viewport.getSelectionGroup().getEndRes(); + + // create new HiddenColumns object with copy of hidden regions + // between startRes and endRes, offset by startRes + copiedHiddenColumns = new HiddenColumns( + viewport.getAlignment().getHiddenColumns(), hiddenOffset, + hiddenCutoff, hiddenOffset); } else { @@ -2038,14 +2038,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } AlignFrame af = new AlignFrame(new Alignment(newSeqs), viewport.applet, newtitle, false); - if (copiedHiddenColumns != null) - { - for (int i = 0; i < copiedHiddenColumns.size(); i++) - { - int[] region = copiedHiddenColumns.elementAt(i); - af.viewport.hideColumns(region[0], region[1]); - } - } + af.viewport.setHiddenColumns(copiedHiddenColumns); jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth, frameHeight); diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index 2fb737a..c76e2cf 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -23,6 +23,7 @@ package jalview.appletgui; import jalview.analysis.AlignmentUtils; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; @@ -50,7 +51,6 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.Arrays; import java.util.Collections; -import java.util.Vector; public class AnnotationLabels extends Panel implements ActionListener, MouseListener, MouseMotionListener @@ -842,8 +842,8 @@ public class AnnotationLabels extends Panel + "\t" + sq.getSequenceAsString() + "\n"); if (av.hasHiddenColumns()) { - jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector<>( - av.getAlignment().getHiddenColumns().getHiddenColumnsCopy()); + jalview.appletgui.AlignFrame.copiedHiddenColumns = new HiddenColumns( + av.getAlignment().getHiddenColumns()); } } diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 88af9fa..a704b3c 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -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 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. diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 13b715e..d843c7f 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1864,23 +1864,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - ArrayList hiddenColumns = null; + HiddenColumns hiddenColumns = null; if (viewport.hasHiddenColumns()) { - hiddenColumns = new ArrayList<>(); int hiddenOffset = viewport.getSelectionGroup().getStartRes(); int hiddenCutoff = viewport.getSelectionGroup().getEndRes(); - ArrayList hiddenRegions = viewport.getAlignment() - .getHiddenColumns().getHiddenColumnsCopy(); - for (int[] region : hiddenRegions) - { - if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff) - { - hiddenColumns - .add(new int[] - { region[0] - hiddenOffset, region[1] - hiddenOffset }); - } - } + + // create new HiddenColumns object with copy of hidden regions + // between startRes and endRes, offset by startRes + hiddenColumns = new HiddenColumns( + viewport.getAlignment().getHiddenColumns(), hiddenOffset, + hiddenCutoff, hiddenOffset); } Desktop.jalviewClipboard = new Object[] { seqs, @@ -2209,11 +2203,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.jalviewClipboard != null && Desktop.jalviewClipboard[2] != null) { - List hc = (List) Desktop.jalviewClipboard[2]; - for (int[] region : hc) - { - af.viewport.hideColumns(region[0], region[1]); - } + HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2]; + af.viewport.setHiddenColumns(hc); } // >>>This is a fix for the moment, until a better solution is