X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=277e11dd84ab24874e80c089f9ef538233f41a07;hb=49db0dff1da16c3355b43a41498c1fc93ef47e91;hp=cb2b3ed93106801c7bd44070bc8d9a4f208e8823;hpb=be8b1d254f658181eec3c29dc696114e3ffdd4df;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index cb2b3ed..277e11d 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -123,6 +123,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public AlignmentPanel(AlignFrame af, final AlignViewport av) { + setName("AligmentPanel"); // setBackground(Color.white); // BH 2019 alignFrame = af; this.av = av; @@ -568,17 +569,24 @@ public class AlignmentPanel extends GAlignmentPanel implements { // BH 2018.04.18 comment: addNotify() is not appropriate here. We // are not changing ancestors, and keyboard action listeners do - // not need to be reset. addNotify() is a very expensive operation, + // not need to be reset, and most importantly, we can't be sure we are actually + // connected to resources. + + // addNotify() is a very expensive operation, // requiring a full re-layout of all parents and children. + // Note in JComponent: + // This method is called by the toolkit internally and should // not be called directly by programs. + // I note that addNotify() is called in several areas of Jalview. int annotationHeight = getAnnotationPanel().adjustPanelHeight(); annotationHeight = getAnnotationPanel() .adjustForAlignFrame(adjustPanelHeight, annotationHeight); + // BH no!! hscroll.addNotify(); annotationScroller.setPreferredSize( new Dimension(annotationScroller.getWidth(), annotationHeight)); @@ -594,9 +602,6 @@ public class AlignmentPanel extends GAlignmentPanel implements /** * update alignment layout for viewport settings - * - * @param wrap - * DOCUMENT ME! */ public void updateLayout() { @@ -618,9 +623,24 @@ public class AlignmentPanel extends GAlignmentPanel implements { annotationScroller.setVisible(true); annotationSpaceFillerHolder.setVisible(true); - validateAnnotationDimensions(false); } + idSpaceFillerPanel1.setVisible(!wrap); + + /* + * defer dimension calculations if panel not yet added to a Window + * BH 2020.06.09 + */ + if (getTopLevelAncestor() == null) + { + repaint(); + return; + } + + if (!wrap && av.isShowAnnotation()) + { + validateAnnotationDimensions(false); + } int canvasWidth = getSeqPanel().seqCanvas.getWidth(); if (canvasWidth > 0) { // may not yet be laid out @@ -641,7 +661,10 @@ public class AlignmentPanel extends GAlignmentPanel implements } } - idSpaceFillerPanel1.setVisible(!wrap); + // System.out.println("ap dim = " + getSize()); + // these values will go negative if getSize() returns (0,0): + // System.out.println("seqpan dim = " + getSeqPanel().getSize()); + // System.out.println("seqcan dim = " + getSeqPanel().seqCanvas.getSize()); repaint(); } @@ -655,10 +678,8 @@ 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) { - int x = xpos; - int y = ypos; if (av == null || av.getAlignment() == null) { @@ -673,40 +694,13 @@ public class AlignmentPanel extends GAlignmentPanel implements { 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) - { - vextent = height; - } - - if ((hextent + x) > width) - { - x = width - hextent; - } - - if ((vextent + y) > height) - { - y = height - vextent; - } - - if (y < 0) - { - y = 0; - } - - if (x < 0) - { - x = 0; - } - + + hextent = Math.min(getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(), width); + vextent = Math.min(getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(), height); + + x = Math.max(0, Math.min(x, width - hextent)); + y = Math.max(0, Math.min(y, height - vextent)); + updateRanges(x, y); updateScrollBars(x, y, width, height); } @@ -868,12 +862,12 @@ public class AlignmentPanel extends GAlignmentPanel implements if (updateOverview) { alignFrame.repaint(); - if (overviewPanel != null) { overviewPanel.updateOverviewImage(); } } else { + invalidate(); // needed so that the id width adjuster works correctly repaint(); } } @@ -881,6 +875,7 @@ public class AlignmentPanel extends GAlignmentPanel implements @Override public void paintComponent(Graphics g) { + // BH OUCH! invalidate(); // needed so that the id width adjuster works correctly Dimension d = getIdPanel().getIdCanvas().getPreferredSize(); @@ -1947,7 +1942,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } av.setSelectionGroup(null); av.getColumnSelection().clear(); - av.setSelectionGroup(null); + av.setSearchResults(null); getIdPanel().getIdCanvas().searchResults = null; av.sendSelection(); // JAL-2034 - should delegate to