From: gmungoc Date: Fri, 1 Sep 2017 09:43:21 +0000 (+0100) Subject: JAL-2216 remove alignment listener when Tree Panel is closed X-Git-Tag: Release_2_10_3b1~58^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4ed094c1b9defe721d27e5c52b467dc49032f5ed;p=jalview.git JAL-2216 remove alignment listener when Tree Panel is closed --- 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