From 950896c0a1a41d799a135f913f438fdc53158093 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 4 Jul 2017 09:35:01 +0100 Subject: [PATCH] JAL-2608 tidy up OverviewPanel when closed --- src/jalview/appletgui/AlignFrame.java | 3 ++- src/jalview/appletgui/OverviewPanel.java | 25 +++++++++++++++++++++++++ src/jalview/gui/AlignFrame.java | 3 ++- src/jalview/gui/OverviewPanel.java | 27 +++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 4ffdfc1..65d652d 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -2617,7 +2617,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } Frame frame = new Frame(); - OverviewPanel overview = new OverviewPanel(alignPanel); + final OverviewPanel overview = new OverviewPanel(alignPanel); frame.add(overview); // +50 must allow for applet frame window jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage( @@ -2632,6 +2632,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, @Override public void windowClosing(WindowEvent e) { + overview.dispose(); if (ap != null) { ap.setOverviewPanel(null); diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index b3c4a37..ccdfee1 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -160,6 +160,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); @@ -257,4 +265,21 @@ public class OverviewPanel extends Panel implements Runnable, 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; + } + } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1a58e21..6b6ff9a 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3259,7 +3259,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } JInternalFrame frame = new JInternalFrame(); - OverviewPanel overview = new OverviewPanel(alignPanel); + final OverviewPanel overview = new OverviewPanel(alignPanel); frame.setContentPane(overview); Desktop.addInternalFrame(frame, MessageManager.formatMessage( "label.overview_params", new Object[] { this.getTitle() }), @@ -3272,6 +3272,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void internalFrameClosed( javax.swing.event.InternalFrameEvent evt) { + overview.dispose(); alignPanel.setOverviewPanel(null); }; }); diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 62e7a68..7a4456e 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -147,7 +147,6 @@ public class OverviewPanel extends JPanel implements Runnable, } }); - updateOverviewImage(); } @@ -205,6 +204,14 @@ public class OverviewPanel extends JPanel implements Runnable, */ public void updateOverviewImage() { + if (oviewCanvas == null) + { + /* + * panel has been disposed + */ + return; + } + if ((getWidth() > 0) && (getHeight() > 0)) { od.setWidth(getWidth()); @@ -221,7 +228,6 @@ public class OverviewPanel extends JPanel implements Runnable, Thread thread = new Thread(this); thread.start(); repaint(); - } @Override @@ -251,4 +257,21 @@ public class OverviewPanel extends JPanel implements Runnable, { setBoxPosition(); } + + /** + * 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; + } + } } -- 1.7.10.2