From 4ed094c1b9defe721d27e5c52b467dc49032f5ed Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 1 Sep 2017 10:43:21 +0100 Subject: [PATCH] JAL-2216 remove alignment listener when Tree Panel is closed --- src/jalview/gui/TreePanel.java | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 5e14fce..c07648d 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -55,6 +55,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; @@ -63,6 +64,8 @@ import javax.imageio.ImageIO; import javax.swing.ButtonGroup; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; import org.jibble.epsgraphics.EpsGraphics2D; @@ -141,7 +144,32 @@ public class TreePanel extends GTreePanel buildAssociatedViewMenu(); - av.addPropertyChangeListener(new java.beans.PropertyChangeListener() + final PropertyChangeListener listener = addAlignmentListener(); + + /* + * remove listener when window is closed, so that this + * panel can be garbage collected + */ + addInternalFrameListener(new InternalFrameAdapter() + { + @Override + public void internalFrameClosed(InternalFrameEvent evt) + { + av.removePropertyChangeListener(listener); + } + }); + + TreeLoader tl = new TreeLoader(newTree, inputData); + tl.start(); + + } + + /** + * @return + */ + protected PropertyChangeListener addAlignmentListener() + { + final PropertyChangeListener listener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) @@ -168,11 +196,9 @@ public class TreePanel extends GTreePanel repaint(); } } - }); - - TreeLoader tl = new TreeLoader(newTree, inputData); - tl.start(); - + }; + av.addPropertyChangeListener(listener); + return listener; } @Override -- 1.7.10.2