From: BobHanson Date: Tue, 24 Mar 2020 17:03:30 +0000 (-0500) Subject: Bamboo test #13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=53601a266c5c00791cb0173b3146f982247cd338;p=jalview.git Bamboo test #13 --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index c43e0b6..a553e65 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -67,6 +67,8 @@ import java.io.FileWriter; import java.io.PrintWriter; import java.util.List; +import javax.swing.JScrollBar; + /** * The main panel of an AlignFrame, containing holders for the IdPanel, * SeqPanel, AnnotationLabels (a JPanel), and AnnotationPanel. @@ -155,11 +157,13 @@ public class AlignmentPanel extends GAlignmentPanel implements hscroll.addAdjustmentListener(this); vscroll.addAdjustmentListener(this); + addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent evt) { + System.out.println("AlignmentPanel resized " + evt); // reset the viewport ranges when the alignment panel is resized // in particular, this initialises the end residue value when Jalview // is initialised @@ -178,10 +182,10 @@ public class AlignmentPanel extends GAlignmentPanel implements / av.getCharHeight(); ranges.setViewportWidth(widthInRes); - ranges.setViewportHeight(heightInSeq); ViewportRanges.sTest += "AP.resize chht=" + av.getCharHeight() + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " " + heightInSeq + "\n"; + ranges.setViewportHeight(heightInSeq); } } @@ -209,6 +213,46 @@ public class AlignmentPanel extends GAlignmentPanel implements } @Override + public void setBounds(int x, int y, int width, int height) + { + System.out.println("?AlignmentPanel.setBounds " + this.getX() + " " + + this.getY() + " " + this.getWidth() + " " + getHeight() + " " + + x + " " + y + " " + width + " " + height); + // BH 2020.03.23 when the Desktop changes its progress bar it re-lays out + // all + // its + // children, for unclear reasons. Maybe because they could be tiled? + if (x == this.getX() && y == this.getY() && width == this.getWidth() + && height == this.getHeight()) + { + return; + } + System.out.println("!AlignmentPanel.setBounds " + this.getX() + " " + + this.getY() + " " + this.getWidth() + " " + getHeight() + " " + + x + " " + y + " " + width + " " + height); + super.setBounds(x, y, width, height); + } + + // @Override + // public void reshape(int x, int y, int width, int height) + // { + // // BH 2020.03.23 when the Desktop changes its progress bar it relays out + // all its + // // children, for unclear reasons. Maybe because they could be tiled? + // if (x == this.getX() && y == this.getY() && width == this.getWidth() + // && height == this.getHeight()) + // { + // return; + // } + // + // System.out.println("AlignmentPanel.reshape " + this.getX() + " " + // + this.getY() + " " + this.getWidth() + " " + getHeight() + " " + // + x + // + " " + y + " " + width + " " + height); + // super.reshape(x, y, width, height); + // } + + @Override public AlignViewportI getAlignViewport() { return av; @@ -646,64 +690,87 @@ public class AlignmentPanel extends GAlignmentPanel implements * visible column to scroll to * @param y * visible row to scroll to + * + * @return true if scrollbars will fire property changes * */ - public void setScrollValues(int xpos, int ypos) + public boolean setScrollValues(int xpos, int ypos) { int x = xpos; int y = ypos; if (av == null || av.getAlignment() == null) { - return; + return false; } if (av.getWrapAlignment()) { - setScrollingForWrappedPanel(x); + return setScrollingForWrappedPanel(x); } - else + int width = av.getAlignment().getVisibleWidth(); + int height = av.getAlignment().getHeight(); + + hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); + vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); + + if (hextent > width) { - int width = av.getAlignment().getVisibleWidth(); - int height = av.getAlignment().getHeight(); + hextent = width; + } - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); - vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); + if (vextent > height) + { + vextent = height; + } - if (hextent > width) - { - hextent = width; - } + if ((hextent + x) > width) + { + x = width - hextent; + } - if (vextent > height) - { - vextent = height; - } + if ((vextent + y) > height) + { + y = height - vextent; + } - if ((hextent + x) > width) - { - x = width - hextent; - } + if (y < 0) + { + y = 0; + } - if ((vextent + y) > height) - { - y = height - vextent; - } + if (x < 0) + { + x = 0; + } - if (y < 0) - { - y = 0; - } + // update the scroll values and return true if they changed - if (x < 0) - { - x = 0; - } + return (setIfChanged(hscroll, x, hextent, 0, width) + + setIfChanged(vscroll, y, vextent, 0, height) != 0); - // update the scroll values - hscroll.setValues(x, hextent, 0, width); - vscroll.setValues(y, vextent, 0, height); + } + + /** + * Update a horizontal or vertical scrollbar and indicate if it is actually changed + * (and so will be firing an AdjustmentChangedEvent) + * @param sb + * @param val + * @param extent + * @param min + * @praam max + * @return 1 if JScrollBar is changed; 0 if not + */ + private int setIfChanged(JScrollBar sb, int val, int extent, int min, + int max) + { + if (sb.getValue() == val && sb.getModel().getExtent() == extent + && sb.getMinimum() == min && sb.getMaximum() == max) + { + return 0; } + sb.setValues(val, extent, min, max); + return 1; } /** @@ -756,8 +823,8 @@ public class AlignmentPanel extends GAlignmentPanel implements return; } - ViewportRanges.sTest += "AP.valChanged chht=" + av.getCharHeight() - + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " " + ViewportRanges.sTest += "AP.adjvalChanged chht=" + av.getCharHeight() + + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " newHt=" + height + "\n"; ranges.setViewportStartAndHeight(y, height); @@ -856,6 +923,20 @@ public class AlignmentPanel extends GAlignmentPanel implements } } + @Override + public void invalidate() + { + System.out.println("AlignmentPanel invalidate"); + super.invalidate(); + } + + @Override + public void validate() + { + System.out.println("AlignmentPanel validate"); + super.validate(); + } + /** * DOCUMENT ME! * @@ -866,6 +947,8 @@ public class AlignmentPanel extends GAlignmentPanel implements public void paintComponent(Graphics g) { + System.out.println("AlignmentPanel paintComponent"); + invalidate(); // needed so that the id width adjuster works correctly Dimension d = getIdPanel().getIdCanvas().getPreferredSize(); @@ -879,7 +962,10 @@ public class AlignmentPanel extends GAlignmentPanel implements * though I still think this call should be elsewhere. */ ViewportRanges ranges = av.getRanges(); - setScrollValues(ranges.getStartRes(), ranges.getStartSeq()); + if (!setScrollValues(ranges.getStartRes(), ranges.getStartSeq())) + { + // super.paintComponent(g); + } super.paintComponent(g); } @@ -890,7 +976,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * @param topLeftColumn * the column position at top left (0..) */ - private void setScrollingForWrappedPanel(int topLeftColumn) + private boolean setScrollingForWrappedPanel(int topLeftColumn) { ViewportRanges ranges = av.getRanges(); int scrollPosition = ranges.getWrappedScrollPosition(topLeftColumn); @@ -901,7 +987,8 @@ public class AlignmentPanel extends GAlignmentPanel implements * so we add extent (1) to the maxScroll value */ vscroll.setUnitIncrement(1); - vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1); + return (setIfChanged(vscroll, scrollPosition, 1, 0, + maxScroll + 1) != 0); } /** diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index e13a63e..cc4cc48 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -361,7 +361,7 @@ public class Desktop extends GDesktop */ public static Desktop getInstance() { - return Jalview.isHeadlessMode() ? null + return Jalview.isHeadlessMode() || Jalview.isSynchronous() ? null : (Desktop) ApplicationSingletonProvider .getInstance(Desktop.class); } @@ -903,7 +903,7 @@ public class Desktop extends GDesktop // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN // IF JALVIEW IS RUNNING HEADLESS // /////////////////////////////////////////////// - if (Jalview.isHeadlessMode()) + if (Jalview.isHeadlessMode() || Jalview.isSynchronous()) { return; } diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index b6bfcd6..3d6bc3d 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -82,8 +82,14 @@ public class ViewportRanges extends ViewportProperties private void setEndSeqTest(int val) { + if (endSeq == val) + { + return; + } + String st = Thread.currentThread().toString(); - sTest += "ViewPortRanges.setEndseqTest " + val + " " + sTest += "ViewPortRanges.setEndseqTest was " + endSeq + " now " + val + + " " + st + "\n"; if (val == 13) { diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index 4e22348..e73b805 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -32,6 +32,9 @@ import jalview.viewmodel.ViewportRanges; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Toolkit; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -47,6 +50,7 @@ public class SeqCanvasTest { Thread.currentThread().setName("SeqCanvasTest Setup " + ++nTest); + Cache.loadProperties("test/jalview/io/testProps.jvprops"); Cache.initLogger(); Jalview.setSynchronous(true); } @@ -380,18 +384,37 @@ public class SeqCanvasTest @Test(groups = "Functional") public void testCalculateWrappedGeometry_fromScrolled() { - flushEvents(); + // debugOut("12]", new Runnable() + // { + // + // @Override + // public void run() + // { + // + // String s = Arrays + // .toString(new NullPointerException().getStackTrace()) + // .replace(',', '\n') + "\n\n"; + // + // System.err.println(s); + // + // } + // + // }); + // ViewportRanges.sTest = ""; Thread.currentThread().setName("SeqCanvasTest fromScrolled " + ++nTest); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); + // note that this frame is unpacked, with w = h = 0; AlignViewport av = af.getViewport(); AlignmentI al = av.getAlignment(); assertEquals(al.getWidth(), 157); assertEquals(al.getHeight(), 15); + String s = ""; + s += "flushing events"; flushEvents(); + s += "events flushed"; av.getRanges().setStartEndSeq(0, 3); - String s = ""; s += " SC1 " + av.getRanges() + " " + ViewportRanges.sTest; av.setShowAnnotation(false); av.setScaleAboveWrapped(true); @@ -409,10 +432,56 @@ public class SeqCanvasTest testee.calculateWrappedGeometry(canvasWidth, canvasHeight); int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx"); - assertEquals(av.getRanges().getEndSeq(), 0, "endSeq should be 3 " + s); // unchanged + assertEquals(av.getRanges().getEndSeq(), 3, "endSeq should be 3 " + s); // unchanged assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())); } + /** + * Let me know when the output indicates the specified message. + * + * @param msg + * @param r + */ + private void debugOut(String msg, Runnable r) + { + int len = msg.length(); + int c0 = msg.charAt(0); + boolean[] recording = new boolean[1]; + System.setOut(new PrintStream(new OutputStream() + { + + StringBuffer out = new StringBuffer(); + + @Override + public void write(int b) throws IOException + { + + if (recording[0]) + { + out.append((char) b); + if (out.length() == len) + { + if (out.toString().equals(msg)) + { + r.run(); + } + recording[0] = false; + out.setLength(0); + } + } + else if (b == c0) + { + out.append((char) b); + recording[0] = true; + } + } + + })); + + // TODO Auto-generated method stub + + } + private static void flushEvents() { ((sun.awt.SunToolkit) Toolkit.getDefaultToolkit()).flushPendingEvents();