JAL-3253-applet JAL-3383 Overview
[jalview.git] / src / jalview / gui / OverviewCanvas.java
index aafac38..de55996 100644 (file)
@@ -47,7 +47,7 @@ public class OverviewCanvas extends JPanel
 
   private boolean disposed = false;
 
-  private BufferedImage lastMiniMe = null;
+  BufferedImage lastMiniMe = null;
 
   // Can set different properties in this seqCanvas than
   // main visible SeqCanvas
@@ -73,15 +73,18 @@ public class OverviewCanvas extends JPanel
 
   private OverviewPanel panel;
 
+  private boolean showProgress;
+
   public OverviewCanvas(OverviewPanel panel,
           OverviewDimensions overviewDims,
           AlignViewportI alignvp, ProgressPanel pp)
   {
     this.panel = panel;
     od = overviewDims;
+    lastMiniMe = null;
     av = alignvp;
     progressPanel = pp;
-
+    showProgress = (pp != null);
     sr = new SequenceRenderer(av);
     sr.renderGaps = false;
     fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
@@ -106,6 +109,7 @@ public class OverviewCanvas extends JPanel
   public void resetOviewDims(OverviewDimensions overviewDims)
   {
     od = overviewDims;
+    lastMiniMe = null;
   }
 
   /**
@@ -123,6 +127,7 @@ public class OverviewCanvas extends JPanel
       else
       {
         updaterunning = true;
+        restart = false;
       }
       return restart;
     }
@@ -154,46 +159,31 @@ public class OverviewCanvas extends JPanel
     this.showSequenceFeatures = showSequenceFeatures;
     this.showAnnotation = showAnnotation;
     this.featureRenderer = featureRenderer;
-
-    // System.out.println("OC draw " + ++ndraw + " showseqf="
-    // + showSequenceFeatures + " showAnno=" + showAnnotation);
-
     if (showSequenceFeatures)
     {
       fr.transferSettings(featureRenderer);
     }
-
     setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
-
     AlignmentI al = av.getAlignment();
-    or = new OverviewRenderer(panel.ap, fr, od, al,
-            av.getResidueShading(), cf,
-            progressPanel != null);
-    if (progressPanel != null)
+    or = new OverviewRenderer(panel.ap, fr, od, al, av.getResidueShading(),
+            cf, showProgress);
+    if (showProgress)
     {
       or.addPropertyChangeListener(progressPanel);
     }
-    or.draw(od.getRows(al), od.getColumns(al));
+    or.drawMiniMe();
   }
 
-  void finalizeDraw(BufferedImage miniMe)
+  synchronized void finalizeDraw(BufferedImage miniMe)
   {
-    Graphics mg = miniMe.getGraphics();
-    if (showAnnotation)
-    {
-      mg.translate(0, od.getSequencesHeight());
-      or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
-              od.getGraphHeight(), od.getColumns(av.getAlignment()));
-      mg.translate(0, -od.getSequencesHeight());
-    }
-    mg.dispose(); // BH 2019
-    if (progressPanel != null)
+
+    if (showProgress && or != null)
     {
       or.removePropertyChangeListener(progressPanel);
     }
-    or = null;
     if (restart)
     {
+      or = null;
       restart = false;
       if (!disposed)
       {
@@ -202,12 +192,17 @@ public class OverviewCanvas extends JPanel
     }
     else
     {
+      if (showAnnotation && or != null)
+      {
+        or.drawGraph(av.getAlignmentConservationAnnotation());
+      }
+      or = null;
       updaterunning = false;
       lastMiniMe = miniMe;
       repaint();
     }
-
   }
+
   @Override
   public void paintComponent(Graphics g)
   {
@@ -240,40 +235,56 @@ public class OverviewCanvas extends JPanel
     else if (drawMe)
     {
       // is this a resize?
-      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 (w != od.getWidth() || h != od.getHeight())
       {
-        od.setWidth(w);
-        od.setHeight(h);
+
+        lastMiniMe = null;
         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());
+        // // if there is annotation, scale the alignment and annotation
+        // // separately
+        // if (od.getGraphHeight() <= 0 && od.getSequencesHeight() <= 0)
+        // {
+        // od.setWidth(w);
+        // od.setHeight(h);
+        // return;
+        // }
+        // try
+        // {
+        // 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
+        //
+        // // right -- this fails with fast user action.
+        //
+        // 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();
+        //
+        // } catch (RasterFormatException e)
+        // {
+        // System.out.println("OC Raster Exception " + lastMiniMe.getWidth()
+        // + "/" + w + "," + lastMiniMe.getHeight() + "/" + h + " "
+        // + od.getSequencesHeight() + " " + od.getGraphHeight());
+        // }
+        // 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());
       }
     }
 
@@ -288,7 +299,7 @@ public class OverviewCanvas extends JPanel
     od.drawBox(g);
   }
 
-  private int ndraw, npaint, nrepaint;
+  // private int ndraw, npaint, nrepaint;
 
   // @Override
   // public void repaint()
@@ -301,6 +312,7 @@ public class OverviewCanvas extends JPanel
   {
     disposed = true;
     od = null;
+    lastMiniMe = null;
     synchronized (this)
     {
       setRestart("dispose");