From: kiramt Date: Fri, 13 Oct 2017 10:58:38 +0000 (+0100) Subject: JAL-2774 Created single event for update to both start residue and seq X-Git-Tag: Release_2_10_4~67^2~21 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=53507580ea0d347514d4f5e092a4d3d815609b9e;p=jalview.git JAL-2774 Created single event for update to both start residue and seq --- diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 6fe71de..88408bb 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -777,5 +777,10 @@ public class AnnotationPanel extends Panel { fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(((int[]) evt.getNewValue())[0] + - ((int[]) evt.getOldValue())[0]); + } } } diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index 5eddc4f..dc906f4 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -448,5 +448,10 @@ public class IdCanvas extends Panel implements ViewportListenerI { fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (propertyName.equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(((int[]) evt.getNewValue())[1] + - ((int[]) evt.getOldValue())[1]); + } } } diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 514c3f9..ad53ea4 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -468,7 +468,8 @@ public class ScalePanel extends Panel // Here we only want to fastpaint on a scroll, with resize using a normal // paint, so scroll events are identified as changes to the horizontal or // vertical start value. - if (evt.getPropertyName().equals(ViewportRanges.STARTRES)) + if (evt.getPropertyName().equals(ViewportRanges.STARTRES) + || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) { // scroll event, repaint panel repaint(); diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index f59967d..ef47f75 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -892,12 +892,21 @@ public class SeqCanvas extends Panel implements ViewportListenerI if (!av.getWrapAlignment()) { int scrollX = 0; - if (eventName.equals(ViewportRanges.STARTRES)) + if (eventName.equals(ViewportRanges.STARTRES) + || eventName.equals(ViewportRanges.STARTRESANDSEQ)) { // Make sure we're not trying to draw a panel // larger than the visible window + if (eventName.equals(ViewportRanges.STARTRES)) + { + scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + } + else + { + scrollX = ((int[]) evt.getNewValue())[0] + - ((int[]) evt.getOldValue())[0]; + } ViewportRanges vpRanges = av.getRanges(); - scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); int range = vpRanges.getEndRes() - vpRanges.getStartRes(); if (scrollX > range) { @@ -924,6 +933,11 @@ public class SeqCanvas extends Panel implements ViewportListenerI // scroll fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (eventName.equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(scrollX, ((int[]) evt.getNewValue())[1] + - ((int[]) evt.getOldValue())[1]); + } } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index be8f5f6..c9d65fa 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -1185,5 +1185,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(((int[]) evt.getNewValue())[0] + - ((int[]) evt.getOldValue())[0]); + } } } diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index a7dff86..235dea0 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -564,5 +564,10 @@ public class IdCanvas extends JPanel implements ViewportListenerI { fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (propertyName.equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(((int[]) evt.getNewValue())[1] + - ((int[]) evt.getOldValue())[1]); + } } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 1db4051..6b2f9c9 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -549,7 +549,8 @@ public class ScalePanel extends JPanel // Here we only want to fastpaint on a scroll, with resize using a normal // paint, so scroll events are identified as changes to the horizontal or // vertical start value. - if (evt.getPropertyName().equals(ViewportRanges.STARTRES)) + if (evt.getPropertyName().equals(ViewportRanges.STARTRES) + || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) { // scroll event, repaint panel repaint(); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 4e896a0..403cbcf 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1489,6 +1489,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI return matchFound; } + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -1509,12 +1510,22 @@ public class SeqCanvas extends JComponent implements ViewportListenerI else { int scrollX = 0; - if (eventName.equals(ViewportRanges.STARTRES)) + if (eventName.equals(ViewportRanges.STARTRES) + || eventName.equals(ViewportRanges.STARTRESANDSEQ)) { // Make sure we're not trying to draw a panel // larger than the visible window + if (eventName.equals(ViewportRanges.STARTRES)) + { + scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + } + else + { + scrollX = ((int[]) evt.getNewValue())[0] + - ((int[]) evt.getOldValue())[0]; + } ViewportRanges vpRanges = av.getRanges(); - scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + int range = vpRanges.getEndRes() - vpRanges.getStartRes(); if (scrollX > range) { @@ -1541,6 +1552,11 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // scroll fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); } + else if (eventName.equals(ViewportRanges.STARTRESANDSEQ)) + { + fastPaint(scrollX, ((int[]) evt.getNewValue())[1] + - ((int[]) evt.getOldValue())[1]); + } } } diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index c525bc6..c158ce7 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -132,9 +132,7 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions } } - // update viewport - ranges.setStartRes(xAsRes); - ranges.setStartSeq(yAsSeq); + ranges.setStartResAndSeq(xAsRes, yAsSeq); } @Override diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 0bda56e..9dde16e 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -176,8 +176,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions } // update viewport - ranges.setStartRes(visXAsRes); - ranges.setStartSeq(visYAsSeq); + ranges.setStartResAndSeq(visXAsRes, visYAsSeq); } /** diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 42d490e..b1d2c02 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,32 @@ public class ViewportRanges extends ViewportProperties } /** + * Set start residue and start sequence together (fires single event) + * + * @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() diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 851b1b7..98b1217 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -85,7 +85,6 @@ public class ViewportRangesTest { vr.setEndSeq(al.getHeight()); assertEquals(vr.getEndSeq(), al.getHeight() - 1); - // vr.setEndRes(al.getHeight() - 1); vr.setEndSeq(al.getHeight() - 1); assertEquals(vr.getEndSeq(), al.getHeight() - 1); } @@ -169,6 +168,24 @@ public class ViewportRangesTest { } @Test(groups = { "Functional" }) + public void testSetStartResAndSeq() + { + ViewportRanges vr = new ViewportRanges(al); + vr.setViewportHeight(10); + vr.setStartResAndSeq(3, 6); + assertEquals(vr.getStartRes(), 3); + assertEquals(vr.getStartSeq(), 6); + assertEquals(vr.getEndRes(), 3 + vr.getViewportWidth() - 1); + assertEquals(vr.getEndSeq(), 6 + vr.getViewportHeight() - 1); + + vr.setStartResAndSeq(10, 25); + assertEquals(vr.getStartRes(), 10); + assertEquals(vr.getStartSeq(), 19); + assertEquals(vr.getEndRes(), 10 + vr.getViewportWidth() - 1); + assertEquals(vr.getEndSeq(), 19 + vr.getViewportHeight() - 1); + } + + @Test(groups = { "Functional" }) public void testSetViewportHeight() { ViewportRanges vr = new ViewportRanges(al); @@ -418,7 +435,7 @@ public class ViewportRangesTest { // one event fired when startRes is called with new value vr.setStartRes(4); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); l.reset(); // no event fired for same value @@ -427,7 +444,7 @@ public class ViewportRangesTest { l.reset(); vr.setStartSeq(4); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.setStartSeq(4); @@ -435,7 +452,7 @@ public class ViewportRangesTest { l.reset(); vr.setEndSeq(10); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.setEndSeq(10); @@ -443,7 +460,7 @@ public class ViewportRangesTest { l.reset(); vr.setStartEndRes(2, 15); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); l.reset(); vr.setStartEndRes(2, 15); @@ -452,16 +469,18 @@ public class ViewportRangesTest { // check new value fired by event is corrected startres vr.setStartEndRes(-1, 5); - assertTrue(l.verify(1, Arrays.asList("startres"), Arrays.asList(0))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES), + Arrays.asList(0))); l.reset(); // check new value fired by event is corrected endres vr.setStartEndRes(0, -1); - assertTrue(l.verify(1, Arrays.asList("endres"), Arrays.asList(0))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDRES), + Arrays.asList(0))); l.reset(); vr.setStartEndSeq(2, 15); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.setStartEndSeq(2, 15); @@ -474,12 +493,14 @@ public class ViewportRangesTest { // check new value fired by event is corrected startseq vr.setStartEndSeq(-1, 5); - assertTrue(l.verify(1, Arrays.asList("startseq"), Arrays.asList(0))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ), + Arrays.asList(0))); l.reset(); // check new value fired by event is corrected endseq vr.setStartEndSeq(0, -1); - assertTrue(l.verify(1, Arrays.asList("endseq"), Arrays.asList(0))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ), + Arrays.asList(0))); l.reset(); // reset for later tests @@ -488,51 +509,52 @@ public class ViewportRangesTest { // test viewport height and width setting triggers event vr.setViewportHeight(10); - assertTrue(l.verify(1, Arrays.asList("endseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ))); l.reset(); vr.setViewportWidth(18); - assertTrue(l.verify(1, Arrays.asList("endres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDRES))); l.reset(); // already has seq start set to 2, so triggers endseq vr.setViewportStartAndHeight(2, 16); - assertTrue(l.verify(1, Arrays.asList("endseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ))); l.reset(); vr.setViewportStartAndWidth(1, 14); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); l.reset(); // test page up/down triggers event vr.pageUp(); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.pageDown(); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); // test scrolling triggers event vr.scrollUp(true); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.scrollUp(false); - assertTrue(l.verify(1, Arrays.asList("startseq"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ))); l.reset(); vr.scrollRight(true); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); l.reset(); vr.scrollRight(false); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); l.reset(); vr.scrollToVisible(10, 10); assertTrue(l.verify(4, - Arrays.asList("startseq", "startseq", "startseq", "startseq"))); + Arrays.asList(ViewportRanges.STARTSEQ, ViewportRanges.STARTSEQ, + ViewportRanges.STARTSEQ, ViewportRanges.STARTSEQ))); l.reset(); /* @@ -544,7 +566,15 @@ public class ViewportRangesTest { l.reset(); vr.scrollToWrappedVisible(25); - assertTrue(l.verify(1, Arrays.asList("startres"))); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES))); + l.reset(); + + // test setStartResAndSeq triggers one event + vr.setStartResAndSeq(5, 7); + assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRESANDSEQ), + Arrays.asList(5, 7))); + + l.reset(); } @Test(groups = { "Functional" }) @@ -784,7 +814,15 @@ class MockPropChangeListener implements ViewportListenerI { firecount++; events.add(evt.getPropertyName()); - newvalues.add((Integer) evt.getNewValue()); + if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) + { + newvalues.add(((int[]) evt.getNewValue())[0]); + newvalues.add(((int[]) evt.getNewValue())[1]); + } + else + { + newvalues.add((Integer) evt.getNewValue()); + } } public boolean verify(int count, List eventslist,