From ff19b30084bdeeb73ae6983d617992220baf495b Mon Sep 17 00:00:00 2001 From: BobHanson Date: Sat, 4 Apr 2020 10:42:22 -0500 Subject: [PATCH] JAL-3253 JAL-3260 SwingJS-3.2.9.v1e and tests --- src/jalview/gui/AlignmentPanel.java | 172 +++++++----------------------- src/jalview/gui/Desktop.java | 4 +- test/jalview/gui/AlignmentPanelTest.java | 2 + 3 files changed, 42 insertions(+), 136 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index a553e65..1c2e91c 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -67,8 +67,6 @@ 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. @@ -157,13 +155,11 @@ 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 @@ -182,9 +178,6 @@ public class AlignmentPanel extends GAlignmentPanel implements / av.getCharHeight(); ranges.setViewportWidth(widthInRes); - ViewportRanges.sTest += "AP.resize chht=" + av.getCharHeight() - + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " " - + heightInSeq + "\n"; ranges.setViewportHeight(heightInSeq); } } @@ -213,46 +206,6 @@ 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; @@ -690,87 +643,64 @@ 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 boolean setScrollValues(int xpos, int ypos) + public void setScrollValues(int xpos, int ypos) { int x = xpos; int y = ypos; if (av == null || av.getAlignment() == null) { - return false; + return; } if (av.getWrapAlignment()) { - return setScrollingForWrappedPanel(x); + setScrollingForWrappedPanel(x); } - 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) - { - hextent = width; - } - - if (vextent > height) + else { - vextent = height; - } + int width = av.getAlignment().getVisibleWidth(); + int height = av.getAlignment().getHeight(); - if ((hextent + x) > width) - { - x = width - hextent; - } + hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); + vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); - if ((vextent + y) > height) - { - y = height - vextent; - } + if (hextent > width) + { + hextent = width; + } - if (y < 0) - { - y = 0; - } + if (vextent > height) + { + vextent = height; + } - if (x < 0) - { - x = 0; - } + if ((hextent + x) > width) + { + x = width - hextent; + } - // update the scroll values and return true if they changed + if ((vextent + y) > height) + { + y = height - vextent; + } - return (setIfChanged(hscroll, x, hextent, 0, width) - + setIfChanged(vscroll, y, vextent, 0, height) != 0); + if (y < 0) + { + y = 0; + } - } + if (x < 0) + { + x = 0; + } - /** - * 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; + // update the scroll values + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); } - sb.setValues(val, extent, min, max); - return 1; } /** @@ -814,7 +744,6 @@ public class AlignmentPanel extends GAlignmentPanel implements int y = vscroll.getValue(); int height = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); - // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport // ranges values are the same @@ -822,11 +751,6 @@ public class AlignmentPanel extends GAlignmentPanel implements { return; } - - ViewportRanges.sTest += "AP.adjvalChanged chht=" + av.getCharHeight() - + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " newHt=" - + height + "\n"; - ranges.setViewportStartAndHeight(y, height); } repaint(); @@ -923,20 +847,6 @@ 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! * @@ -947,8 +857,6 @@ 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(); @@ -962,10 +870,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * though I still think this call should be elsewhere. */ ViewportRanges ranges = av.getRanges(); - if (!setScrollValues(ranges.getStartRes(), ranges.getStartSeq())) - { - // super.paintComponent(g); - } + setScrollValues(ranges.getStartRes(), ranges.getStartSeq()); super.paintComponent(g); } @@ -976,7 +881,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * @param topLeftColumn * the column position at top left (0..) */ - private boolean setScrollingForWrappedPanel(int topLeftColumn) + private void setScrollingForWrappedPanel(int topLeftColumn) { ViewportRanges ranges = av.getRanges(); int scrollPosition = ranges.getWrappedScrollPosition(topLeftColumn); @@ -987,8 +892,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * so we add extent (1) to the maxScroll value */ vscroll.setUnitIncrement(1); - return (setIfChanged(vscroll, scrollPosition, 1, 0, - maxScroll + 1) != 0); + vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1); } /** diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index cc4cc48..e13a63e 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() || Jalview.isSynchronous() ? null + return Jalview.isHeadlessMode() ? 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() || Jalview.isSynchronous()) + if (Jalview.isHeadlessMode()) { return; } diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index 5ae8f20..51d3e37 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -215,6 +215,7 @@ public class AlignmentPanelTest af.getViewport().showAllHiddenColumns(); af.alignPanel.setScrollValues(scrollpos, 5); af.paintImmediately(af.getBounds()); + waitSome(); assertEquals(ranges.getEndRes(), af.getViewport() .getAlignment().getWidth() - 1); @@ -260,6 +261,7 @@ public class AlignmentPanelTest // System.out.println("APT range end3 " + ranges.getEndRes()); // endRes back to original value + System.out.println(endres + " vs " + ranges.getEndRes()); assertEquals(ranges.getEndRes(), endres); } -- 1.7.10.2