JAL-3435 AlignFrame not setting JInternalFrameListener in JS
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 23 Sep 2019 12:20:26 +0000 (08:20 -0400)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 23 Sep 2019 12:20:26 +0000 (08:20 -0400)
src/jalview/gui/AlignFrame.java

index bac06e9..4d29919 100644 (file)
@@ -131,6 +131,7 @@ import java.awt.event.MouseEvent;
 import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
@@ -413,10 +414,24 @@ public class AlignFrame extends GAlignFrame
     if (Desktop.getDesktopPane() != null)
     {
       this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
-      if (!Platform.isJS())
+      PropertyChangeListener serviceListener = (Platform.isJS() ? null
+              : addServiceListeners());
+      addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
       {
-        addServiceListeners();
-      }
+        @Override
+        public void internalFrameClosed(
+                javax.swing.event.InternalFrameEvent evt)
+        {
+          // System.out.println("deregistering discoverer listener");
+          if (serviceListener != null)
+          {
+            Desktop.getInstance().removeJalviewPropertyChangeListener(
+                    "services", serviceListener);
+          }
+          closeMenuItem_actionPerformed(true);
+        }
+      });
+
       setGUINucleotide();
     }
 
@@ -833,11 +848,9 @@ public class AlignFrame extends GAlignFrame
   }
 
   /* Set up intrinsic listeners for dynamically generated GUI bits. */
-  private void addServiceListeners()
+  private PropertyChangeListener addServiceListeners()
   {
-    final java.beans.PropertyChangeListener thisListener;
-    Desktop.getInstance().addJalviewPropertyChangeListener("services",
-            thisListener = new java.beans.PropertyChangeListener()
+    PropertyChangeListener serviceListener = new PropertyChangeListener()
             {
               @Override
               public void propertyChange(PropertyChangeEvent evt)
@@ -857,19 +870,10 @@ public class AlignFrame extends GAlignFrame
                   });
                 }
               }
-            });
-    addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
-    {
-      @Override
-      public void internalFrameClosed(
-              javax.swing.event.InternalFrameEvent evt)
-      {
-        // System.out.println("deregistering discoverer listener");
-        Desktop.getInstance().removeJalviewPropertyChangeListener("services",
-                thisListener);
-        closeMenuItem_actionPerformed(true);
-      }
-    });
+    };
+
+    Desktop.getInstance().addJalviewPropertyChangeListener("services",
+            serviceListener);
     // Finally, build the menu once to get current service state
     new Thread(new Runnable()
     {
@@ -879,6 +883,7 @@ public class AlignFrame extends GAlignFrame
         BuildWebServiceMenu();
       }
     }).start();
+    return serviceListener;
   }
 
   /**