stop multiple dialogs appearing one after another (in progress for JAL-414)
authorjprocter <Jim Procter>
Mon, 14 Jun 2010 12:47:21 +0000 (12:47 +0000)
committerjprocter <Jim Procter>
Mon, 14 Jun 2010 12:47:21 +0000 (12:47 +0000)
src/jalview/gui/OOMWarning.java

index 3f2b5a8..48db5d9 100644 (file)
@@ -25,6 +25,8 @@ public class OOMWarning implements Runnable
 \r
   String instructions = "";\r
 \r
+  public static boolean oomInprogress = false;\r
+\r
   Component desktop = null;\r
 \r
   /**\r
@@ -40,22 +42,27 @@ public class OOMWarning implements Runnable
   OOMWarning(final String action, final OutOfMemoryError oomex,\r
           final Component instance)\r
   {\r
-    this.action = action;\r
-    desktop = instance;\r
-    if (oomex != null)\r
+    if (!oomInprogress)\r
     {\r
-      if (jalview.bin.Cache.log != null)\r
-      {\r
-        jalview.bin.Cache.log.error("Out of Memory when " + action, oomex);\r
-      }\r
-      else\r
+      oomInprogress = true;\r
+      this.action = action;\r
+      desktop = instance;\r
+      if (oomex != null)\r
       {\r
-        System.err.println("Out of Memory when " + action);\r
-        oomex.printStackTrace();\r
+        if (jalview.bin.Cache.log != null)\r
+        {\r
+          jalview.bin.Cache.log\r
+                  .error("Out of Memory when " + action, oomex);\r
+        }\r
+        else\r
+        {\r
+          System.err.println("Out of Memory when " + action);\r
+          oomex.printStackTrace();\r
+        }\r
       }\r
+      javax.swing.SwingUtilities.invokeLater(this);\r
+      System.gc();\r
     }\r
-    javax.swing.SwingUtilities.invokeLater(this);\r
-    System.gc();\r
   }\r
 \r
   public OOMWarning(String string, OutOfMemoryError oomerror)\r
@@ -74,6 +81,8 @@ public class OOMWarning implements Runnable
                             + "\nSee help files for increasing Java Virtual Machine memory.",\r
                     "Out of memory",\r
                     javax.swing.JOptionPane.WARNING_MESSAGE);\r
+    // hope that there's enough memory left that no more appear.\r
+    oomInprogress=false;\r
   }\r
 \r
 }\r