X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FViewportRanges.java;h=4bdaa815caec0d0cf561bb353452f178c10aaa45;hb=refs%2Fheads%2Fimp%2FJAL-2774;hp=24ff57f46861e3ffed3004250946f89b97892260;hpb=7157280e15326fa721d8c19e785f4e0ec2b05e5a;p=jalview.git diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 24ff57f..4bdaa81 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -24,11 +24,10 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; /** - * Slightly less embryonic class which: Supplies and updates viewport properties - * relating to position such as: start and end residues and sequences; ideally - * will serve hidden columns/rows too. Intention also to support calculations - * for positioning, scrolling etc. such as finding the middle of the viewport, - * checking for scrolls off screen + * Supplies and updates viewport properties relating to position such as: start + * and end residues and sequences; ideally will serve hidden columns/rows too. + * Intention also to support calculations for positioning, scrolling etc. such + * as finding the middle of the viewport, checking for scrolls off screen */ public class ViewportRanges extends ViewportProperties { @@ -40,6 +39,8 @@ public class ViewportRanges extends ViewportProperties public static final String ENDSEQ = "endseq"; + public static final String STARTRESANDSEQ = "startresandseq"; + private boolean wrappedMode = false; // start residue of viewport @@ -130,6 +131,31 @@ public class ViewportRanges extends ViewportProperties */ public void setStartEndRes(int start, int end) { + int[] oldvalues = updateStartEndRes(start, end); + int oldstartres = oldvalues[0]; + int oldendres = oldvalues[1]; + + changeSupport.firePropertyChange(STARTRES, oldstartres, startRes); + if (oldstartres == startRes) + { + // event won't be fired if start positions are same + // fire an event for the end positions in case they changed + changeSupport.firePropertyChange(ENDRES, oldendres, endRes); + } + } + + /** + * Update start and end residue values, adjusting for width constraints if + * necessary + * + * @param start + * start residue + * @param end + * end residue + * @return array containing old start and end residue values + */ + private int[] updateStartEndRes(int start, int end) + { int oldstartres = this.startRes; /* @@ -162,14 +188,7 @@ public class ViewportRanges extends ViewportProperties { endRes = end; } - - changeSupport.firePropertyChange(STARTRES, oldstartres, startRes); - if (oldstartres == startRes) - { - // event won't be fired if start positions are same - // fire an event for the end positions in case they changed - changeSupport.firePropertyChange(ENDRES, oldendres, endRes); - } + return new int[] { oldstartres, oldendres }; } /** @@ -203,6 +222,31 @@ public class ViewportRanges extends ViewportProperties */ public void setStartEndSeq(int start, int end) { + int[] oldvalues = updateStartEndSeq(start, end); + int oldstartseq = oldvalues[0]; + int oldendseq = oldvalues[1]; + + changeSupport.firePropertyChange(STARTSEQ, oldstartseq, startSeq); + if (oldstartseq == startSeq) + { + // event won't be fired if start positions are the same + // fire in case the end positions changed + changeSupport.firePropertyChange(ENDSEQ, oldendseq, endSeq); + } + } + + /** + * Update start and end sequence values, adjusting for height constraints if + * necessary + * + * @param start + * start sequence + * @param end + * end sequence + * @return array containing old start and end sequence values + */ + private int[] updateStartEndSeq(int start, int end) + { int oldstartseq = this.startSeq; int visibleHeight = getVisibleAlignmentHeight(); if (start > visibleHeight - 1) @@ -231,14 +275,7 @@ public class ViewportRanges extends ViewportProperties { endSeq = end; } - - changeSupport.firePropertyChange(STARTSEQ, oldstartseq, startSeq); - if (oldstartseq == startSeq) - { - // event won't be fired if start positions are the same - // fire in case the end positions changed - changeSupport.firePropertyChange(ENDSEQ, oldendseq, endSeq); - } + return new int[] { oldstartseq, oldendseq }; } /** @@ -255,6 +292,34 @@ public class ViewportRanges extends ViewportProperties } /** + * Set start residue and start sequence together (fires single event). The + * event supplies a pair of old values and a pair of new values: [old start + * residue, old start sequence] and [new start residue, new start sequence] + * + * @param res + * the start residue + * @param seq + * the start sequence + */ + public void setStartResAndSeq(int res, int seq) + { + int width = getViewportWidth(); + int[] oldresvalues = updateStartEndRes(res, res + width - 1); + + int startseq = seq; + int height = getViewportHeight(); + if (startseq + height - 1 > getVisibleAlignmentHeight() - 1) + { + startseq = getVisibleAlignmentHeight() - height; + } + int[] oldseqvalues = updateStartEndSeq(startseq, startseq + height - 1); + + int[] old = new int[] { oldresvalues[0], oldseqvalues[0] }; + int[] newresseq = new int[] { startRes, startSeq }; + changeSupport.firePropertyChange(STARTRESANDSEQ, old, newresseq); + } + + /** * Get start residue of viewport */ public int getStartRes()