From: kiramt Date: Fri, 12 May 2017 18:32:32 +0000 (+0100) Subject: JAL-2491 Tidies to Overview panel calls in light of new code X-Git-Tag: Release_2_10_2~3^2~64^2~8 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1dff9688cc5ebc8f0a409806c911756a4d80ce52;p=jalview.git JAL-2491 Tidies to Overview panel calls in light of new code --- diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index c3458f9..308a550 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -745,6 +745,9 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, @Override public void adjustmentValueChanged(AdjustmentEvent evt) { + // Note that this event is NOT fired by the AWT scrollbar when setValues is + // called. Instead manually call adjustHorizontal and adjustVertical + // directly. if (evt == null || evt.getSource() == apvscroll) { annotationPanel.setScrollOffset(apvscroll.getValue(), false); @@ -896,8 +899,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, * Scroll to position but centring the target residue. Also set a state flag * to prevent adjustmentValueChanged performing this recursively. */ - // setFollowingComplementScroll(true); - // this should be scrollToPosition(sr,verticalOffset, scrollToPosition(sr, seqOffset, true, true); } diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 0f37544..c1b5f9c 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -151,7 +151,6 @@ public class OverviewPanel extends Panel implements Runnable, od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() .getHiddenSequences(), av.getColumnSelection(), av .getRanges()); - // ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); ap.paintAlignment(false); } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 1b047a3..095a573 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -108,6 +108,7 @@ public class OverviewPanel extends JPanel implements Runnable, || (getHeight() != (od.getHeight()))) { updateOverviewImage(); + setBoxPosition(); } } }); @@ -124,7 +125,6 @@ public class OverviewPanel extends JPanel implements Runnable, .getColumnSelection(), av.getRanges()); // TODO set via ViewportRanges in overview dimensions once JAL-2388 is // merged - // ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } }); @@ -141,13 +141,12 @@ public class OverviewPanel extends JPanel implements Runnable, .getColumnSelection(), av.getRanges()); // TODO set via ViewportRanges in overview dimensions once JAL-2388 is // merged - - // ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } }); updateOverviewImage(); + setBoxPosition(); } /** @@ -243,7 +242,7 @@ public class OverviewPanel extends JPanel implements Runnable, lastMiniMe = miniMe; } - setBoxPosition(); + // setBoxPosition(); } /* diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index e4c24e1..1abc93b 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -60,12 +60,6 @@ public class OverviewDimensions // height of box private int boxHeight = -1; - // scroll position in viewport corresponding to boxX - private int scrollCol = -1; - - // scroll position in viewport corresponding to boxY - private int scrollRow = -1; - /** * Create an OverviewDimensions object * @@ -171,14 +165,14 @@ public class OverviewDimensions // went past the end of the alignment, adjust backwards // if last position was before the end of the alignment, need to update - if ((scrollCol + vpwidth - 1) < visAlignWidth) + if ((ranges.getStartRes() + vpwidth - 1) < visAlignWidth) { visXAsRes = hiddenCols.findColumnPosition(hiddenCols .subtractVisibleColumns(vpwidth - 1, alwidth - 1)); } else { - visXAsRes = scrollCol; + visXAsRes = ranges.getStartRes(); } } @@ -205,22 +199,19 @@ public class OverviewDimensions if (visYAsRes + vpheight - 1 > visAlignHeight) { // went past the end of the alignment, adjust backwards - if ((scrollRow + vpheight - 1) < visAlignHeight) + if ((ranges.getEndRes() + vpheight - 1) < visAlignHeight) { visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs .subtractVisibleRows(vpheight - 1, alheight - 1)); } else { - visYAsRes = scrollRow; + visYAsRes = ranges.getEndRes(); } } - // update scroll values - // scrollCol = visXAsRes; - // scrollRow = visYAsRes; + // update viewport ranges.setStartRes(visXAsRes); - ranges.setStartSeq(visYAsRes); } @@ -272,20 +263,12 @@ public class OverviewDimensions */ public void drawBox(Graphics g) { + System.out.println("Drawbox: " + boxX + " " + boxY + " " + boxWidth + + " " + boxHeight); g.drawRect(boxX, boxY, boxWidth, boxHeight); g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); } - /*public int getScrollCol() - { - return scrollCol; - } - - public int getScrollRow() - { - return scrollRow; - }*/ - // TODO should be removed, when unit test has mock Graphics object available // to check boxX/boxY public int getBoxX() diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 267b50e..ac310cc 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -145,27 +145,38 @@ public class ViewportRanges extends ViewportProperties */ public void setEndRes(int res) { + int startres = res; int width = getViewportWidth(); - setStartEndRes(res - width + 1, res); + if (startres + width - 1 > al.getWidth() - 1) + { + startres = al.getWidth() - width; + } + setStartEndRes(startres - width + 1, startres); } /** - * Set the first sequence visible in the viewport. Fires a property change - * event. + * Set the first sequence visible in the viewport, maintaining the height. If + * the viewport would extend past the last sequence, sets the viewport so it + * sits at the bottom of the alignment. Fires a property change event. * * @param seq * sequence position */ public void setStartSeq(int seq) { + int startseq = seq; int height = getViewportHeight(); - setStartEndSeq(seq, seq + height - 1); + if (startseq + height - 1 > al.getHeight() - 1) + { + startseq = al.getHeight() - height; + } + setStartEndSeq(startseq, startseq + height - 1); } /** - * Set start and end sequences at the same time. This method only fires one - * event for the two changes, and should be used in preference to separate - * calls to setStartSeq and setEndSeq. + * Set start and end sequences at the same time. The viewport height may + * change. This method only fires one event for the two changes, and should be + * used in preference to separate calls to setStartSeq and setEndSeq. * * @param start * the start sequence diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index 42b9289..7aa665f 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -76,10 +76,8 @@ public class OverviewDimensionsTest hiddenCols.revealAllHiddenColumns(); vpranges = new ViewportRanges(al); - vpranges.setStartRes(0); - vpranges.setEndRes(62); - vpranges.setStartSeq(0); - vpranges.setEndSeq(17); + vpranges.setViewportStartAndHeight(0, 18); + vpranges.setViewportStartAndWidth(0, 63); viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1; viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1; @@ -202,26 +200,26 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartSeq(), 0); // negative boxX value reset to 0 mouseClick(od, -5, 10); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), + assertEquals(vpranges.getStartSeq(), Math.round((float) 10 * alheight / od.getSequencesHeight())); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartRes(), 0); // negative boxY value reset to 0 mouseClick(od, 6, -2); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) 6 * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // overly large boxX value reset to width-boxWidth mouseClick(od, 100, 6); @@ -229,9 +227,10 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 6); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); @@ -241,13 +240,14 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5 // and round rounds to 508; however we get 507 working with row values // hence the subtraction of 1 - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1); @@ -256,9 +256,10 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); @@ -272,19 +273,20 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), oldboxx + 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); assertEquals(od.getBoxY(), oldboxy + 2); - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); // click at top corner mouseClick(od, 0, 0); assertEquals(od.getBoxX(), 0); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartRes(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); } @@ -301,8 +303,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide cols at start and check updated box position is correct // changes boxX but not boxwidth @@ -326,13 +328,13 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), 0); + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), 0); // click to right of hidden columns, box moves to click point testBoxIsAtClickPoint(40, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), Math.round((float) 40 * alwidth / od.getWidth()) - (lastHiddenCol + 1)); @@ -346,10 +348,11 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth()) - (lastHiddenCol + 1)); - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); } @@ -366,8 +369,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide columns 63-73, no change to box position or dimensions int firstHidden = 63; @@ -378,8 +381,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // move box so that it overlaps with hidden cols on one side // box width changes, boxX and scrollCol as for unhidden case @@ -393,9 +396,9 @@ public class OverviewDimensionsTest Math.round(boxWidth + (float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round(xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // move box so that it completely covers hidden cols // box width changes, boxX and scrollCol as for hidden case @@ -408,9 +411,9 @@ public class OverviewDimensionsTest Math.round(boxWidth + (float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // move box so boxX is in hidden cols, box overhangs at right // boxX and scrollCol at left of hidden area, box width extends across @@ -426,16 +429,16 @@ public class OverviewDimensionsTest + Math.round((float) (lastHidden - firstHidden + 1) * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), firstHidden - 1); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), firstHidden - 1); + assertEquals(vpranges.getStartSeq(), 0); // move box so boxX is to right of hidden cols, but does not go beyond full // width of alignment // box width, boxX and scrollCol all as for non-hidden case xpos = 75; testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), Math.round(xpos * alwidth / od.getWidth()) - (lastHidden - firstHidden + 1)); @@ -447,10 +450,12 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals( + vpranges.getStartRes(), Math.round(((float) od.getBoxX() * alwidth / od.getWidth()) - (lastHidden - firstHidden + 1))); - assertEquals(od.getScrollRow(), + assertEquals( + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); @@ -468,8 +473,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide columns 140-164, no change to box position or dimensions int firstHidden = 140; @@ -479,15 +484,15 @@ public class OverviewDimensionsTest assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // click to left of hidden cols, without overlapping // boxX, scrollCol and width as normal int xpos = 5; testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartSeq(), 0); + assertEquals(vpranges.getStartRes(), Math.round((float) xpos * alwidth / od.getWidth())); // click to left of hidden cols, with overlap @@ -500,9 +505,9 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // click in hidden cols // boxX and scrollCol adjusted for hidden cols, width normal @@ -513,9 +518,9 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); // click off end of alignment // boxX and scrollCol adjusted for hidden cols, width normal @@ -526,9 +531,9 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartSeq(), 0); } /** @@ -796,8 +801,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows at start and check updated box position is correct // changes boxY but not boxheight @@ -844,8 +849,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows in middle and check updated box position is correct // no changes @@ -902,8 +907,8 @@ public class OverviewDimensionsTest assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), 0); - assertEquals(od.getScrollRow(), 0); + assertEquals(vpranges.getStartRes(), 0); + assertEquals(vpranges.getStartSeq(), 0); // hide rows at end and check updated box position is correct // no changes @@ -958,8 +963,7 @@ public class OverviewDimensionsTest */ private void moveViewportH(int startRes) { - vpranges.setStartRes(startRes); - vpranges.setEndRes(startRes + viewWidth - 1); + vpranges.setViewportStartAndWidth(startRes, viewWidth); od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } @@ -968,8 +972,7 @@ public class OverviewDimensionsTest */ private void moveViewportV(int startSeq) { - vpranges.setStartSeq(startSeq); - vpranges.setEndSeq(startSeq + viewHeight - 1); + vpranges.setViewportStartAndHeight(startSeq, viewHeight); od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } @@ -978,10 +981,8 @@ public class OverviewDimensionsTest */ private void moveViewport(int startRes, int startSeq) { - vpranges.setStartRes(startRes); - vpranges.setEndRes(startRes + viewWidth - 1); - vpranges.setStartSeq(startSeq); - vpranges.setEndSeq(startSeq + viewHeight - 1); + vpranges.setViewportStartAndWidth(startRes, viewWidth); + vpranges.setViewportStartAndHeight(startSeq, viewHeight); od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); } @@ -996,9 +997,6 @@ public class OverviewDimensionsTest // updates require an OverviewPanel to exist which it doesn't here // so call setBoxPosition() as it would be called by the AlignmentPanel // normally - - vpranges.setStartRes(od.getScrollCol()); - vpranges.setStartSeq(od.getScrollRow()); od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges); }