From: kiramt Date: Thu, 10 Aug 2017 10:20:09 +0000 (+0100) Subject: JAL-2587 prevented double overview recalc on opening overview X-Git-Tag: Release_2_10_2b1~4^2^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=67affee2e65ca942447570c35526c04d64f41fe1;p=jalview.git JAL-2587 prevented double overview recalc on opening overview --- diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index e49fd19..997d214 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -168,9 +168,6 @@ public class OverviewCanvas extends JComponent public void draw(boolean showSequenceFeatures, boolean showAnnotation, FeatureRenderer transferRenderer) { - // System.out.println(this.getHeight()); - // setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); - miniMe = null; veryLastMiniMe = lastMiniMe; @@ -214,7 +211,6 @@ public class OverviewCanvas extends JComponent @Override public void paintComponent(Graphics g) { - if (restart) { if (lastMiniMe == null) @@ -231,12 +227,12 @@ public class OverviewCanvas extends JComponent } else if (lastMiniMe != null) { + // is this a resize? if ((getWidth() > 0) && (getHeight() > 0) && ((getWidth() != od.getWidth()) || (getHeight() != od.getHeight()))) { - // scale the alignment and annotation separately *** if there is - // annotation *** + // if there is annotation, scale the alignment and annotation separately if (od.getGraphHeight() > 0) { BufferedImage topImage = lastMiniMe.getSubimage(0, 0, @@ -263,8 +259,6 @@ public class OverviewCanvas extends JComponent } else { - System.out.println("Resetting height from/to: " + od.getHeight() - + " " + getHeight()); od.setWidth(getWidth()); od.setHeight(getHeight()); } @@ -276,7 +270,7 @@ public class OverviewCanvas extends JComponent od.setBoxPosition(av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); } - else + else // not a resize { if (alpha != 0) // this is a timer triggered dissolve { @@ -292,20 +286,12 @@ public class OverviewCanvas extends JComponent g2d.dispose(); } - /* else if (lastMiniMe != miniMe) - { - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); - g.setColor(TRANS_GREY); - g.fillRect(0, 0, getWidth(), getHeight()); - }*/ else { // fall back to normal behaviour g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); } - } - } // draw the box diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 4a0fadf..39f1500 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -71,6 +71,8 @@ public class OverviewPanel extends JPanel implements Runnable, private ProgressPanel progressPanel; + boolean resizing = false; + /** * Creates a new OverviewPanel object. * @@ -86,8 +88,6 @@ public class OverviewPanel extends JPanel implements Runnable, (av.isShowAnnotation() && av .getAlignmentConservationAnnotation() != null)); - // setSize(od.getWidth(), od.getHeight() + 20); - setLayout(new BorderLayout()); progressPanel = new ProgressPanel(OverviewRenderer.UPDATE, MessageManager.getString("label.oview_calc")); @@ -98,12 +98,35 @@ public class OverviewPanel extends JPanel implements Runnable, av.getRanges().addPropertyChangeListener(this); + // without this the overview window does not size to fit the overview canvas + setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent evt) { - updateOverviewImage(); + // Resize is called on the initial display of the overview. + // This code adjusts sizes to account for the progress bar if it has not + // already been accounted for, which triggers another resize call for + // the correct sizing, at which point the overview image is updated. + // (This avoids a double recalculation of the image.) + if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + + progressPanel.getHeight()) + { + updateOverviewImage(); + } + else + { + if ((getWidth() > 0) && (getHeight() > 0)) + { + od.setWidth(getWidth()); + od.setHeight(getHeight() - progressPanel.getHeight()); + } + + setPreferredSize(new Dimension(od.getWidth(), + od.getHeight() + progressPanel.getHeight())); + } } }); @@ -199,9 +222,6 @@ public class OverviewPanel extends JPanel implements Runnable, } } }); - - setPreferredSize(new Dimension(od.getWidth(), - od.getHeight())); } /*