Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix window closing.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 14 Oct 2014 13:19:02 +0000 (15:19 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 14 Oct 2014 13:19:02 +0000 (15:19 +0200)
DrawingWindow.java

index 4172235..670c854 100644 (file)
@@ -621,6 +621,8 @@ public class DrawingWindow {
         colorMap = Collections.unmodifiableMap(m);
     }
 
+    private static int instances = 0;
+
     private final String title; // window's title
     private JFrame frame;       // the frame (window)
     private DWPanel panel;      // the panel showing the image
@@ -630,6 +632,7 @@ public class DrawingWindow {
 
     // To be run on the Event Dispatching Thread
     void createGUI() {
+        DrawingWindow.instances++;
         panel = new DWPanel(this);
         frame = new JFrame(title);
         frame.add(panel);
@@ -643,6 +646,13 @@ public class DrawingWindow {
                     }
                 }
             });
+        frame.addWindowListener(new WindowAdapter(){
+                public void windowClosed(WindowEvent e) {
+                    // System.err.println("CLOSED: " + DrawingWindow.instances);
+                    if (--DrawingWindow.instances == 0)
+                        System.exit(0);
+                }
+            });
         frame.setLocationByPlatform(true);
         frame.setVisible(true);
     }