X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=98a7fe28b15d9d497984541fe31c96912cfacdcf;hb=2e18e422cead591bd9a1df295f1897b3e346a480;hp=c467f4ad103d7634b9f997d78ba3e1d9f28ab229;hpb=b4be31307e3a1e6d3dbb43bd14dfd012be6a3dfd;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index c467f4a..98a7fe2 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1831,4 +1831,55 @@ public class ColumnSelection 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); + } + } + } }