JAL-2611 reinstated missed commit
[jalview.git] / src / jalview / appletgui / OverviewPanel.java
index 76c4e86..e74e1cd 100755 (executable)
@@ -67,7 +67,8 @@ public class OverviewPanel extends Panel implements Runnable,
     setLayout(null);
 
     od = new OverviewDimensionsShowHidden(av.getRanges(),
-            (av.isShowAnnotation() && av.getSequenceConsensusHash() != null));
+            (av.isShowAnnotation()
+                    && av.getSequenceConsensusHash() != null));
 
     oviewCanvas = new OverviewCanvas(od, av);
     setLayout(new BorderLayout());
@@ -112,7 +113,8 @@ public class OverviewPanel extends Panel implements Runnable,
   @Override
   public void mouseClicked(MouseEvent evt)
   {
-    if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
+    if ((evt.getModifiers()
+            & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
     {
       showPopupMenu(evt);
     }
@@ -146,11 +148,12 @@ public class OverviewPanel extends Panel implements Runnable,
     }
     else
     {
+      // don't do anything if the mouse press is in the overview's box
+      // (wait to see if it's a drag instead)
+      // otherwise update the viewport
       if (!od.isPositionInBox(evt.getX(), evt.getY()))
-      {
-        // don't do anything if the mouse press is in the overview's box
-        // (wait to see if it's a drag instead)
-        // otherwise update the viewport
+      { 
+       draggingBox = false;
         od.updateViewportFromMouse(evt.getX(), evt.getY(),
                 av.getAlignment().getHiddenSequences(),
                 av.getAlignment().getHiddenColumns());
@@ -168,16 +171,13 @@ public class OverviewPanel extends Panel implements Runnable,
   @Override
   public void mouseReleased(MouseEvent evt)
   {
-    if (draggingBox)
-    {
-      draggingBox = false;
-    }
   }
 
   @Override
   public void mouseDragged(MouseEvent evt)
   {
-    if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
+    if ((evt.getModifiers()
+            & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
     {
       if (!Platform.isAMac())
       {
@@ -209,6 +209,14 @@ public class OverviewPanel extends Panel implements Runnable,
    */
   public void updateOverviewImage()
   {
+    if (oviewCanvas == null)
+    {
+      /*
+       * panel has been disposed
+       */
+      return;
+    }
+
     if ((getSize().width > 0) && (getSize().height > 0))
     {
       od.setWidth(getSize().width);
@@ -236,8 +244,8 @@ public class OverviewPanel extends Panel implements Runnable,
   public void run()
   {
     oviewCanvas.draw(av.isShowSequenceFeatures(),
-            (av.isShowAnnotation() && av
-                    .getAlignmentConservationAnnotation() != null),
+            (av.isShowAnnotation()
+                    && av.getAlignmentConservationAnnotation() != null),
             ap.seqPanel.seqCanvas.getFeatureRenderer());
     setBoxPosition();
   }
@@ -249,9 +257,8 @@ public class OverviewPanel extends Panel implements Runnable,
    */
   private void setBoxPosition()
   {
-    od.setBoxPosition(av.getAlignment()
-.getHiddenSequences(), av
-            .getAlignment().getHiddenColumns());
+    od.setBoxPosition(av.getAlignment().getHiddenSequences(),
+            av.getAlignment().getHiddenColumns());
     repaint();
   }
 
@@ -293,17 +300,34 @@ public class OverviewPanel extends Panel implements Runnable,
     {
       showHidden = false;
       od = new OverviewDimensionsHideHidden(av.getRanges(),
-              (av.isShowAnnotation() && av
-                      .getAlignmentConservationAnnotation() != null));
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
     }
     else
     {
       showHidden = true;
       od = new OverviewDimensionsShowHidden(av.getRanges(),
-              (av.isShowAnnotation() && av
-                      .getAlignmentConservationAnnotation() != null));
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
     }
     oviewCanvas.resetOviewDims(od);
     updateOverviewImage();
   }
+
+  /**
+   * Removes this object as a property change listener, and nulls references
+   */
+  protected void dispose()
+  {
+    try
+    {
+      av.getRanges().removePropertyChangeListener(this);
+    } finally
+    {
+      av = null;
+      oviewCanvas = null;
+      ap = null;
+      od = null;
+    }
+  }
 }