JAL-4128 Catch RasterFormatException caused whilst resizing Overview window, recalcul... bug/JAL-4128_resizing_overview_with_solid_drags_causes_exception
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 20 Feb 2023 10:46:11 +0000 (10:46 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 20 Feb 2023 10:46:11 +0000 (10:46 +0000)
src/jalview/gui/OverviewCanvas.java
src/jalview/viewmodel/OverviewDimensions.java

index 586ac2c..99dba3d 100644 (file)
@@ -24,11 +24,13 @@ import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.image.BufferedImage;
+import java.awt.image.RasterFormatException;
 
 import javax.swing.JPanel;
 
 import jalview.api.AlignViewportI;
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.renderer.OverviewRenderer;
 import jalview.renderer.OverviewResColourFinder;
 import jalview.viewmodel.OverviewDimensions;
@@ -223,27 +225,36 @@ public class OverviewCanvas extends JPanel
         if (od.getGraphHeight() > 0 && od.getSequencesHeight() > 0 // BH 2019
         )
         {
-          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();
+          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(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();
+          } catch (RasterFormatException e)
+          {
+            Console.debug(
+                    "Scaling miscalculation resizing Overview window");
+            od.setWidth(getWidth());
+            od.setHeight(getHeight());
+          }
         }
         else
         {
index 0235081..1251207 100644 (file)
  */
 package jalview.viewmodel;
 
+import java.awt.Graphics;
+
 import jalview.api.AlignmentColsCollectionI;
 import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.HiddenSequences;
 
-import java.awt.Graphics;
-
 public abstract class OverviewDimensions
 {
   protected static final int MAX_WIDTH = 400;
@@ -172,13 +172,13 @@ public abstract class OverviewDimensions
 
   public void setWidth(int w)
   {
-    width = w;
+    width = w < 1 ? 1 : w;
     widthRatio = (float) alwidth / width;
   }
 
   public void setHeight(int h)
   {
-    sequencesHeight = h - graphHeight;
+    sequencesHeight = (h < 1 ? 1 : h) - graphHeight;
     heightRatio = (float) alheight / sequencesHeight;
   }