X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOverviewCanvas.java;h=aafac388284d2c5d45915f86e7f1bd03261b518c;hb=04e88679fd837e9fe36d186e5eacdd5f13a89927;hp=1f55ea6f6509032fcbce7a8f09bbc7f559093762;hpb=3f308bf567cb401b0f735c8f5e9ff57eea083011;p=jalview.git diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 1f55ea6..aafac38 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; import jalview.renderer.OverviewRenderer; import jalview.renderer.OverviewResColourFinder; import jalview.viewmodel.OverviewDimensions; @@ -31,9 +32,10 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; -import javax.swing.JComponent; +import javax.swing.JPanel; -public class OverviewCanvas extends JComponent +@SuppressWarnings("serial") +public class OverviewCanvas extends JPanel { private static final Color TRANS_GREY = new Color(100, 100, 100, 25); @@ -43,9 +45,7 @@ public class OverviewCanvas extends JComponent private volatile boolean updaterunning = false; - private boolean dispose = false; - - private BufferedImage miniMe; + private boolean disposed = false; private BufferedImage lastMiniMe = null; @@ -65,9 +65,19 @@ public class OverviewCanvas extends JComponent private ProgressPanel progressPanel; - public OverviewCanvas(OverviewDimensions overviewDims, + private boolean showSequenceFeatures; + + private boolean showAnnotation; + + private jalview.api.FeatureRenderer featureRenderer; + + private OverviewPanel panel; + + public OverviewCanvas(OverviewPanel panel, + OverviewDimensions overviewDims, AlignViewportI alignvp, ProgressPanel pp) { + this.panel = panel; od = overviewDims; av = alignvp; progressPanel = pp; @@ -84,6 +94,7 @@ public class OverviewCanvas extends JComponent cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol); setSize(od.getWidth(), od.getHeight()); + setPreferredSize(getSize()); // BH 2019.07.29 added } /** @@ -107,11 +118,7 @@ public class OverviewCanvas extends JComponent { if (updaterunning) { - restart = true; - if (or != null) - { - or.setRedraw(true); - } + setRestart("restartDraw"); } else { @@ -121,6 +128,16 @@ public class OverviewCanvas extends JComponent } } + private void setRestart(String why) + { + // System.out.println("OC restart true " + why); + restart = true; + if (or != null) + { + or.setRedraw(true); + } + } + /** * Draw the overview sequences * @@ -128,31 +145,40 @@ public class OverviewCanvas extends JComponent * true if sequence features are to be shown * @param showAnnotation * true if the annotation is to be shown - * @param transferRenderer + * @param featureRenderer * the renderer to transfer feature colouring from */ public void draw(boolean showSequenceFeatures, boolean showAnnotation, - FeatureRenderer transferRenderer) + jalview.api.FeatureRenderer featureRenderer) { - miniMe = null; + this.showSequenceFeatures = showSequenceFeatures; + this.showAnnotation = showAnnotation; + this.featureRenderer = featureRenderer; + + // System.out.println("OC draw " + ++ndraw + " showseqf=" + // + showSequenceFeatures + " showAnno=" + showAnnotation); if (showSequenceFeatures) { - fr.transferSettings(transferRenderer); + fr.transferSettings(featureRenderer); } setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); - or = new OverviewRenderer(fr, od, av.getAlignment(), - av.getResidueShading(), cf); - - or.addPropertyChangeListener(progressPanel); - - miniMe = or.draw(od.getRows(av.getAlignment()), - od.getColumns(av.getAlignment())); + AlignmentI al = av.getAlignment(); + or = new OverviewRenderer(panel.ap, fr, od, al, + av.getResidueShading(), cf, + progressPanel != null); + if (progressPanel != null) + { + or.addPropertyChangeListener(progressPanel); + } + or.draw(od.getRows(al), od.getColumns(al)); + } + void finalizeDraw(BufferedImage miniMe) + { Graphics mg = miniMe.getGraphics(); - if (showAnnotation) { mg.translate(0, od.getSequencesHeight()); @@ -160,111 +186,125 @@ public class OverviewCanvas extends JComponent od.getGraphHeight(), od.getColumns(av.getAlignment())); mg.translate(0, -od.getSequencesHeight()); } - System.gc(); - - or.removePropertyChangeListener(progressPanel); + mg.dispose(); // BH 2019 + if (progressPanel != null) + { + or.removePropertyChangeListener(progressPanel); + } or = null; if (restart) { restart = false; - if (!dispose) + if (!disposed) { - draw(showSequenceFeatures, showAnnotation, transferRenderer); + draw(showSequenceFeatures, showAnnotation, featureRenderer); } } else { updaterunning = false; lastMiniMe = miniMe; + repaint(); } - } + } @Override public void paintComponent(Graphics g) { - super.paintComponent(g); + int w = getWidth(); + int h = getHeight(); + if (w == 0 || od.getBoxWidth() <= 0) + { + // BH 2019.07.27 removes two unnecessary paints, since boxwidth can be -1 + // or 0 during early-stage painting + return; + } + + boolean drawMe = (lastMiniMe != null); if (restart) { - if (lastMiniMe == null) + if (drawMe) { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); + g.drawImage(lastMiniMe, 0, 0, w, h, this); } else { - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + g.setColor(Color.white); + g.fillRect(0, 0, w, h); } g.setColor(TRANS_GREY); - g.fillRect(0, 0, getWidth(), getHeight()); + g.fillRect(0, 0, w, h); + drawMe = false; } - else if (lastMiniMe != null) + else if (drawMe) { // is this a resize? - if ((getWidth() > 0) && (getHeight() > 0) - && ((getWidth() != od.getWidth()) - || (getHeight() != od.getHeight()))) + if (w != od.getWidth() || h != od.getHeight()) { + // if there is annotation, scale the alignment and annotation + // separately + if (od.getGraphHeight() <= 0 && od.getSequencesHeight() <= 0) { - // if there is annotation, scale the alignment and annotation - // separately - if (od.getGraphHeight() > 0) - { - BufferedImage topImage = lastMiniMe.getSubimage(0, 0, - od.getWidth(), od.getSequencesHeight()); - BufferedImage bottomImage = lastMiniMe.getSubimage(0, - od.getSequencesHeight(), od.getWidth(), - od.getGraphHeight()); - - // must be done at this point as we rely on using old width/height - // above, and new width/height below - od.setWidth(getWidth()); - od.setHeight(getHeight()); - - // stick the images back together so lastMiniMe is consistent in the - // event of a repaint - BUT probably not thread safe - lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(), - BufferedImage.TYPE_INT_RGB); - Graphics lg = lastMiniMe.getGraphics(); - lg.drawImage(topImage, 0, 0, od.getWidth(), - od.getSequencesHeight(), null); - lg.drawImage(bottomImage, 0, od.getSequencesHeight(), - od.getWidth(), od.getGraphHeight(), this); - lg.dispose(); - } - else - { - od.setWidth(getWidth()); - od.setHeight(getHeight()); - } - - // make sure the box is in the right place - od.setBoxPosition(av.getAlignment().getHiddenSequences(), - av.getAlignment().getHiddenColumns()); + od.setWidth(w); + od.setHeight(h); + return; + } + // System.out.println("OC new subimages"); + BufferedImage topImage = lastMiniMe.getSubimage(0, 0, od.getWidth(), + od.getSequencesHeight()); + BufferedImage bottomImage = lastMiniMe.getSubimage(0, + od.getSequencesHeight(), od.getWidth(), od.getGraphHeight()); + + // must be done at this point as we rely on using old width/height + // above, and new width/height below + od.setWidth(w); + od.setHeight(h); + + // stick the images back together so lastMiniMe is consistent in the + // event of a repaint - BUT probably not thread safe + // System.out.println("OC new lastminime " + w + " " + h); + lastMiniMe = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics lg = lastMiniMe.getGraphics(); + lg.drawImage(topImage, 0, 0, w, od.getSequencesHeight(), null); + lg.drawImage(bottomImage, 0, od.getSequencesHeight(), w, + od.getGraphHeight(), this); + lg.dispose(); + // BH 2019: removed -- this is now taken care of using vpbox in + // OverviewDimension + // // make sure the box is in the right place + // od.setBoxPosition(av.getAlignment().getHiddenSequences(), + // av.getAlignment().getHiddenColumns()); } - // fall back to normal behaviour - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); } - else + + if (drawMe) { - g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this); + g.drawImage(lastMiniMe, 0, 0, w, h, this); } - // draw the box g.setColor(Color.red); + // System.out.println("OC paintComponent nd=" + ndraw + " nr=" + nrepaint + // + " np=" + ++npaint); od.drawBox(g); } + private int ndraw, npaint, nrepaint; + + // @Override + // public void repaint() + // { + // System.out.println("OC repaint " + (++nrepaint)); + // super.repaint(); + // } public void dispose() { - dispose = true; + disposed = true; + od = null; synchronized (this) { - restart = true; - if (or != null) - { - or.setRedraw(true); - } + setRestart("dispose"); } } + }