From: gmungoc Date: Thu, 22 Sep 2016 14:15:01 +0000 (+0100) Subject: JAL-2216 null currentAlignFrame on close all windows; remove action X-Git-Tag: Release_2_10_0~39^2^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8c9072337270d0e4c26c569346d5ba1f829e08d3;p=jalview.git JAL-2216 null currentAlignFrame on close all windows; remove action listener from Window menu item when window closed --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 387a2a9..00b359a 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -64,12 +64,10 @@ import java.awt.event.FocusListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; @@ -102,6 +100,8 @@ import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkEvent.EventType; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; @@ -814,24 +814,25 @@ public class Desktop extends jalview.jbgui.GDesktop implements * ((openFrameCount - 1) % 10) + yOffset); } + /* + * add an entry for the new frame in the Window menu + * (and remove it when the frame is closed) + */ final JMenuItem menuItem = new JMenuItem(title); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + frame.addInternalFrameListener(new InternalFrameAdapter() { @Override - public void internalFrameActivated( - javax.swing.event.InternalFrameEvent evt) + public void internalFrameActivated(InternalFrameEvent evt) { JInternalFrame itf = desktop.getSelectedFrame(); if (itf != null) { itf.requestFocus(); } - } @Override - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) + public void internalFrameClosed(InternalFrameEvent evt) { PaintRefresher.RemoveComponent(frame); @@ -843,11 +844,23 @@ public class Desktop extends jalview.jbgui.GDesktop implements { openFrameCount--; } + + /* + * ensure no reference to alignFrame retained by menu item listener + */ + if (menuItem.getActionListeners().length > 0) + { + menuItem.removeActionListener(menuItem.getActionListeners()[0]); + } windowMenu.remove(menuItem); JInternalFrame itf = desktop.getSelectedFrame(); if (itf != null) { itf.requestFocus(); + if (itf instanceof AlignFrame) + { + Jalview.setCurrentAlignFrame((AlignFrame) itf); + } } System.gc(); }; @@ -868,47 +881,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } }); - menuItem.addMouseListener(new MouseListener() - { - - @Override - public void mouseReleased(MouseEvent e) - { - } - - @Override - public void mousePressed(MouseEvent e) - { - } - - @Override - public void mouseExited(MouseEvent e) - { - try - { - frame.setSelected(false); - } catch (PropertyVetoException e1) - { - } - } - - @Override - public void mouseEntered(MouseEvent e) - { - try - { - frame.setSelected(true); - } catch (PropertyVetoException e1) - { - } - } - - @Override - public void mouseClicked(MouseEvent e) - { - - } - }); windowMenu.add(menuItem); @@ -1328,6 +1300,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements @Override public void closeAll_actionPerformed(ActionEvent e) { + // TODO show a progress bar while closing? JInternalFrame[] frames = desktop.getAllFrames(); for (int i = 0; i < frames.length; i++) { @@ -1338,6 +1311,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { } } + Jalview.setCurrentAlignFrame(null); System.out.println("ALL CLOSED"); if (v_client != null) { @@ -1354,6 +1328,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { ssm.resetAll(); } + System.gc(); } @Override