From: BobHanson Date: Wed, 10 Jun 2020 21:03:42 +0000 (-0500) Subject: Bamboo text #35 - simpler logic; avoids impossible repaint, validation? X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=edeca22444e251f45ce730542b4dc2187bb95b63;p=jalview.git Bamboo text #35 - simpler logic; avoids impossible repaint, validation? --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index d84047c..d99bd1d 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -600,6 +600,8 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public void updateLayout() { + if (getTopLevelAncestor() == null) + return; ViewportRanges ranges = av.getRanges(); fontChanged(); setAnnotationVisible(av.isShowAnnotation()); @@ -643,7 +645,8 @@ public class AlignmentPanel extends GAlignmentPanel implements idSpaceFillerPanel1.setVisible(!wrap); - repaint(); + +// BH not added to anything yet! repaint(); } /** @@ -655,12 +658,10 @@ public class AlignmentPanel extends GAlignmentPanel implements * visible row to scroll to * */ - public void setScrollValues(int xpos, int ypos) + public void setScrollValues(int x, int y) { - System.out.println("AlignmentPanel.setScrollValues " + xpos + "_" + ypos); - int x = xpos; - int y = ypos; + System.out.println("AlignmentPanel.setScrollValues " + x + "_" + y); if (av == null || av.getAlignment() == null) { @@ -675,50 +676,22 @@ public class AlignmentPanel extends GAlignmentPanel implements { int width = av.getAlignment().getVisibleWidth(); int height = av.getAlignment().getHeight(); + + hextent = Math.min(getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(), width); + vextent = Math.min(getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(), height); - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); - vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); - + if (hextent < 0) System.out.println("AlignmentPanel.setScrollValues found hext=" + hextent + " vext=" + vextent + " width=" + width + " height=" + height ); + + x = Math.max(0, Math.min(x, width - hextent)); + y = Math.max(0, Math.min(y, height - vextent)); - if (hextent > width) - { - hextent = width; - } - - if (vextent > height) - { - vextent = height; - } - - - - if ((hextent + x) > width) - { - x = width - hextent; - } - - if ((vextent + y) > height) - { - y = height - vextent; - } - System.out.println("AlignmentPanel.setScrollValues resetting these to " + x + "_" + y + " based on hext=" + hextent + " vext=" + vextent + " width=" + width + " height=" + height ); - - if (y < 0) - { - y = 0; - } - - if (x < 0) - { - x = 0; - } updateRanges(x, y); updateScrollBars(x, y, width, height); diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 8c137b8..b96ac28 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -112,7 +112,7 @@ public class ViewportRanges extends ViewportProperties * Set first residue visible in the viewport, and retain the current width. * Fires a property change event. * - * @param res + * @param res * residue position */ public void setStartRes(int res) @@ -262,38 +262,15 @@ public class ViewportRanges extends ViewportProperties private int[] updateStartEndSeq(int start, int end) { - if (end == 3 && this.endSeq == 14 || end == 13 && this.endSeq == 3) { - new NullPointerException().printStackTrace(System.out); - System.out.println("ViewportRange updateStartEndSeq " + start + " " + end + " " + Thread.currentThread()); - } +// if (end == 3 && this.endSeq == 14 || end == 13 && this.endSeq == 3) { +// new NullPointerException().printStackTrace(System.out); +// System.out.println("ViewportRange updateStartEndSeq " + start + " " + end + " " + Thread.currentThread()); +// } int oldstartseq = this.startSeq; - int visibleHeight = getVisibleAlignmentHeight(); - if (start > visibleHeight - 1) - { - startSeq = Math.max(visibleHeight - 1, 0); - } - else if (start < 0) - { - startSeq = 0; - } - else - { - startSeq = start; - } - int oldendseq = this.endSeq; - if (end >= visibleHeight) - { - endSeq = Math.max(visibleHeight - 1, 0); - } - else if (end < 0) - { - endSeq = 0; - } - else - { - endSeq = end; - } + int max = getVisibleAlignmentHeight() - 1; + startSeq = Math.max(0, Math.min(start, max)); + endSeq = Math.max(0, Math.min(end, max)); return new int[] { oldstartseq, oldendseq }; } @@ -408,21 +385,15 @@ public class ViewportRanges extends ViewportProperties */ public void setViewportStartAndWidth(int start, int w) { - int vpstart = start; - if (vpstart < 0) - { - vpstart = 0; - } - - /* - * if not wrapped, don't leave white space at the right margin - */ + int vpstart = Math.max(0, start); + if (!wrappedMode) { - if ((w <= getVisibleAlignmentWidth()) - && (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)) + // if not wrapped, don't leave white space at the right margin + int maxStart = getVisibleAlignmentWidth() - w; + if (maxStart >= 0) { - vpstart = getVisibleAlignmentWidth() - w; + vpstart = Math.min(vpstart, maxStart); } } @@ -441,22 +412,15 @@ public class ViewportRanges extends ViewportProperties */ public void setViewportStartAndHeight(int start, int h) { - int vpstart = start; - - int visHeight = getVisibleAlignmentHeight(); - if (vpstart < 0) + int vpstart = Math.max(0, start); + int maxStart = getVisibleAlignmentHeight() - h; + if (maxStart > 0) { - vpstart = 0; + // can't start higher than vertical extent will allow + // (viewport height is less than the full alignment + // and we are running off the bottom) + vpstart = Math.min(vpstart, maxStart); } - else if (h <= visHeight && vpstart + h > visHeight) - // viewport height is less than the full alignment and we are running off - // the bottom - { - vpstart = visHeight - h; - } - // System.out.println("ViewportRanges setviewportStartAndHeight " + vpstart - // + " " + start + " " + h + " " + getVisibleAlignmentHeight()); - setStartEndSeq(vpstart, vpstart + h - 1); } diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index 3877429..0e14a6b 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -51,7 +51,7 @@ public class SeqCanvasTest * Test the method that computes wrapped width in residues, height of wrapped * widths in pixels, and the number of widths visible */ - @Test(groups = "Functional", priority = 0) + @Test(groups = "Functional") public void testCalculateWrappedGeometry_noAnnotations() { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( @@ -222,7 +222,7 @@ public class SeqCanvasTest * Test the method that computes wrapped width in residues, height of wrapped * widths in pixels, and the number of widths visible */ - @Test(groups = "Functional", priority = 1) + @Test(groups = "Functional") public void testCalculateWrappedGeometry_withAnnotations() { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( @@ -324,7 +324,7 @@ public class SeqCanvasTest * endSeq should be unchanged, but the vertical repeat height should include * all sequences. */ - @Test(groups = "Functional", priority = 2) + @Test(groups = "Functional") public void testCalculateWrappedGeometry_fromScrolled() { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( @@ -335,25 +335,28 @@ public class SeqCanvasTest assertEquals(al.getHeight(), 15); ViewportRanges ranges = av.getRanges(); - System.out.println(av.getRanges() + " just before setting end to 3"); ranges.setStartEndSeq(0, 3); - System.out.println(av.getRanges() + " just after setting end to 3"); + System.out.println(ranges); av.setShowAnnotation(false); av.setScaleAboveWrapped(true); + System.out.println(ranges); SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; av.setWrapAlignment(true); + System.out.println(ranges); av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); + System.out.println(ranges); // Windows h=19, w=11. assertEquals(charHeight, !Platform.isWin() ? 17 : 19); assertEquals(charWidth, !Platform.isWin() ? 12 : 11); + System.out.println(ranges); int canvasWidth = 400; int canvasHeight = 300; testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - System.out.println(ranges + " just before assert"); + System.out.println(ranges); assertEquals(ranges.getEndSeq(), 3); // unchanged int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx");