JAL-2587 First working attempt
[jalview.git] / src / jalview / gui / OverviewCanvas.java
index 14ffad6..694f804 100644 (file)
@@ -57,6 +57,8 @@ public class OverviewCanvas extends JComponent
 
   private AlignViewportI av;
 
+  private boolean resize = false;
+
   public OverviewCanvas(OverviewDimensions overviewDims,
           AlignViewportI alignvp)
   {
@@ -164,6 +166,7 @@ public class OverviewCanvas extends JComponent
   @Override
   public void paintComponent(Graphics g)
   {
+
     if (restart)
     {
       if (lastMiniMe == null)
@@ -184,6 +187,8 @@ public class OverviewCanvas extends JComponent
               && ((getWidth() != od.getWidth())
                       || (getHeight() != od.getHeight())))
       {
+        resize = true;
+
         // scale the alignment and annotation separately *** if there is
         // annotation ***
         if (od.getGraphHeight() > 0)
@@ -199,7 +204,7 @@ public class OverviewCanvas extends JComponent
 
           // stick the images back together so lastMiniMe is consistent in the
           // event
-          // of a repaint
+          // of a repaint - BUT probably not thread safe
           lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
                   BufferedImage.TYPE_INT_RGB);
           Graphics lg = lastMiniMe.getGraphics();
@@ -210,26 +215,30 @@ public class OverviewCanvas extends JComponent
           lg.dispose();
         }
 
-        g.drawImage(lastMiniMe, 0, 0, od.getWidth(), od.getHeight(), null);
+        // scale lastMiniMe to the new size
+        g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
+
+        // make sure the box is in the right place
+        od.setBoxPosition(av.getAlignment().getHiddenSequences(),
+                av.getAlignment().getHiddenColumns());
       }
       else
       {
+        System.out.println("Same size");
         g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
-        if (lastMiniMe != miniMe)
+        if (lastMiniMe != miniMe && !resize)
         {
           g.setColor(TRANS_GREY);
           g.fillRect(0, 0, getWidth(), getHeight());
         }
+        resize = false;
       }
 
     }
 
+    // draw the box
     g.setColor(Color.red);
 
-
-    od.setBoxPosition(av.getAlignment().getHiddenSequences(),
-            av.getAlignment().getHiddenColumns());
-
     od.drawBox(g);
   }
 }