X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FOverviewCanvas.java;h=7f4e9622df0cf4b1bf5324e69e12d03b6d0a0e93;hb=refs%2Fheads%2FJAL-3437_load_project;hp=ede3b94d89d02f2b533e31a771dbc7ff10af96c0;hpb=e4bc7e3c94320f057b6015ba6262ac84edb6788d;p=jalview.git diff --git a/src/jalview/appletgui/OverviewCanvas.java b/src/jalview/appletgui/OverviewCanvas.java index ede3b94..7f4e962 100644 --- a/src/jalview/appletgui/OverviewCanvas.java +++ b/src/jalview/appletgui/OverviewCanvas.java @@ -21,17 +21,19 @@ package jalview.appletgui; import jalview.renderer.OverviewRenderer; -import jalview.renderer.seqfeatures.FeatureColourFinder; +import jalview.renderer.OverviewResColourFinder; import jalview.viewmodel.OverviewDimensions; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; -import java.awt.Panel; +import java.awt.image.BufferedImage; -public class OverviewCanvas extends Panel +@SuppressWarnings("serial") +public class OverviewCanvas extends Component { // This is set true if the alignment view changes whilst // the overview is being calculated @@ -41,33 +43,37 @@ public class OverviewCanvas extends Panel private OverviewDimensions od; + private OverviewRenderer or = null; + private Image miniMe; private Image offscreen; private AlignViewport av; - // Can set different properties in this seqCanvas than - // main visible SeqCanvas - private SequenceRenderer sr; + private boolean showSequenceFeatures; + + private boolean showAnnotation; + + private jalview.api.FeatureRenderer featureRenderer; private jalview.renderer.seqfeatures.FeatureRenderer fr; private Frame nullFrame; - public OverviewCanvas(OverviewDimensions overviewDims, + private OverviewPanel panel; + + public OverviewCanvas(OverviewPanel panel, + OverviewDimensions overviewDims, AlignViewport alignvp) { + this.panel = panel; od = overviewDims; av = alignvp; nullFrame = new Frame(); nullFrame.addNotify(); - sr = new SequenceRenderer(av); - sr.graphics = nullFrame.getGraphics(); - sr.renderGaps = false; - sr.forOverview = true; fr = new jalview.renderer.seqfeatures.FeatureRenderer(av); } @@ -93,6 +99,10 @@ public class OverviewCanvas extends Panel if (updaterunning) { restart = true; + if (or != null) + { + or.setRedraw(true); + } } else { @@ -102,59 +112,24 @@ public class OverviewCanvas extends Panel } } - /** - * Draw the overview sequences - * - * @param showSequenceFeatures - * true if sequence features are to be shown - * @param showAnnotation - * true if the annotation is to be shown - * @param transferRenderer - * 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; if (showSequenceFeatures) { - fr.transferSettings(transferRenderer); + fr.transferSettings(featureRenderer); } - FeatureColourFinder finder = new FeatureColourFinder(fr); setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); - OverviewRenderer or = new OverviewRenderer(sr, finder, od); - miniMe = nullFrame.createImage(od.getWidth(), od.getHeight()); + or = new OverviewRenderer(panel.ap, fr, od, av.getAlignment(), + av.getResidueShading(), new OverviewResColourFinder()); offscreen = nullFrame.createImage(od.getWidth(), od.getHeight()); - - miniMe = or.draw(od.getRows(av.getAlignment()), - od.getColumns(av.getAlignment().getHiddenColumns())); - - Graphics mg = miniMe.getGraphics(); - - // checks for conservation annotation to make sure overview works for DNA - // too - if (showAnnotation) - { - mg.translate(0, od.getSequencesHeight()); - or.drawGraph(mg, av.getAlignmentConservationAnnotation(), - av.getCharWidth(), od.getGraphHeight(), - od.getColumns(av.getAlignment().getHiddenColumns())); - mg.translate(0, -od.getSequencesHeight()); - } - System.gc(); - - if (restart) - { - restart = false; - draw(showSequenceFeatures, showAnnotation, transferRenderer); - } - else - { - updaterunning = false; - } + or.drawMiniMe(); } @Override @@ -166,13 +141,43 @@ public class OverviewCanvas extends Panel @Override public void paint(Graphics g) { - Graphics og = offscreen.getGraphics(); if (miniMe != null) { + Graphics og = offscreen.getGraphics(); og.drawImage(miniMe, 0, 0, this); og.setColor(Color.red); od.drawBox(og); g.drawImage(offscreen, 0, 0, this); + og.dispose(); + } + } + + /** + * Nulls references to protect against potential memory leaks + */ + void dispose() + { + od = null; + } + + public void finalizeDraw(BufferedImage miniMe) + { + if (restart) + { + restart = false; + draw(showSequenceFeatures, showAnnotation, featureRenderer); + } + else + { + this.miniMe = miniMe; + // checks for conservation annotation to make sure overview works for DNA + // too + if (showAnnotation) + { + or.drawGraph(av.getAlignmentConservationAnnotation()); + } + updaterunning = false; + repaint(); } }