From fd45447c22c4bb229e2383ab8010d3a60a48f86d Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 22 Mar 2017 16:29:45 +0000 Subject: [PATCH] JAL-2388 Rationalised overview panel drawing thread --- src/jalview/gui/OverviewCanvas.java | 59 +++++++++++++++++++++++++---------- src/jalview/gui/OverviewPanel.java | 20 ++++++------ 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 6a7e56c..df831e1 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.gui; import jalview.api.AlignViewportI; @@ -13,19 +33,20 @@ import java.awt.image.BufferedImage; import javax.swing.JComponent; + public class OverviewCanvas extends JComponent { private static final Color TRANS_GREY = new Color(100, 100, 100, 25); + // This is set true if the alignment view changes whilst + // the overview is being calculated + private volatile boolean restart = false; + private BufferedImage miniMe; private BufferedImage lastMiniMe = null; - public boolean updating = false; - // This is set true if the user resizes whilst - // the overview is being calculated - public volatile boolean updateAgain = false; // Can set different properties in this seqCanvas than // main visible SeqCanvas @@ -37,19 +58,16 @@ public class OverviewCanvas extends JComponent OverviewDimensions od; - OverviewPanel op; - AlignViewport av; AlignmentPanel ap; public OverviewCanvas(OverviewDimensions overviewDims, - AlignViewportI alignvp, AlignmentPanel alignp, OverviewPanel overp) + AlignViewportI alignvp, AlignmentPanel alignp) { od = overviewDims; av = alignp.av; ap = alignp; - op = overp; sr = new SequenceRenderer(av); sr.renderGaps = false; @@ -57,6 +75,15 @@ public class OverviewCanvas extends JComponent fr = new FeatureRenderer(ap); } + /* + * Signals to drawing code that the associated alignment viewport + * has changed and a redraw will be required + */ + public void restartDraw() + { + restart = true; + } + public void draw(boolean showSequenceFeatures, boolean showAnnotation) { miniMe = null; @@ -96,7 +123,7 @@ public class OverviewCanvas extends JComponent if (showAnnotation) { renderer.updateFromAlignViewport(av); - for (int col = 0; col < od.getWidth() && !updateAgain; col++) + for (int col = 0; col < od.getWidth() && !restart; col++) { mg.translate(col, od.getSequencesHeight()); renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(), @@ -109,12 +136,10 @@ public class OverviewCanvas extends JComponent } System.gc(); - updating = false; - - if (updateAgain) + if (restart) { - updateAgain = false; - op.updateOverviewImage(); + restart = false; + draw(showSequenceFeatures, showAnnotation); } else { @@ -125,7 +150,7 @@ public class OverviewCanvas extends JComponent @Override public void paintComponent(Graphics g) { - if (updating || updateAgain) + if (restart) { if (lastMiniMe == null) { @@ -170,7 +195,7 @@ public class OverviewCanvas extends JComponent // get hidden row and hidden column map once at beginning. // clone featureRenderer settings to avoid race conditions... if state is // updated just need to refresh again - for (int row = 0; row < od.getSequencesHeight() && !updateAgain; row++) + for (int row = 0; row < od.getSequencesHeight() && !restart; row++) { boolean doCopy = true; int currentrow = (int) (row * sampleRow); @@ -186,7 +211,7 @@ public class OverviewCanvas extends JComponent seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow); } - for (int col = 0; col < od.getWidth() && !updateAgain; col++) + for (int col = 0; col < od.getWidth() && !restart; col++) { if (doCopy) { diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index f58a2a5..bc4a19f 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -49,6 +49,8 @@ public class OverviewPanel extends JPanel implements Runnable private AlignmentPanel ap; + boolean updateRunning = false; + /** * Creates a new OverviewPanel object. * @@ -64,7 +66,7 @@ public class OverviewPanel extends JPanel implements Runnable (av.isShowAnnotation() && av .getAlignmentConservationAnnotation() != null)); - oviewCanvas = new OverviewCanvas(od, av, ap, this); + oviewCanvas = new OverviewCanvas(od, av, ap); setLayout(new BorderLayout()); add(oviewCanvas, BorderLayout.CENTER); @@ -119,14 +121,6 @@ public class OverviewPanel extends JPanel implements Runnable */ public void updateOverviewImage() { - if (oviewCanvas.updating) - { - oviewCanvas.updateAgain = true; - return; - } - - oviewCanvas.updating = true; - if ((getWidth() > 0) && (getHeight() > 0)) { od.setWidth(getWidth()); @@ -135,9 +129,17 @@ public class OverviewPanel extends JPanel implements Runnable setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); + if (updateRunning) + { + oviewCanvas.restartDraw(); + return; + } + + updateRunning = true; Thread thread = new Thread(this); thread.start(); repaint(); + updateRunning = false; } @Override -- 1.7.10.2