use OOMwarning to warn user when out of Memory occurs
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 326ac07..3dc967e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
+ * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- *
+ * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
@@ -154,9 +154,9 @@ public class AlignmentPanel
   }
 
   /**
-   * DOCUMENT ME!
+   * Calculate the width of the alignment labels based on the displayed names and any bounds on label width set in preferences.
    *
-   * @return DOCUMENT ME!
+   * @return Dimension giving the maximum width of the alignment label panel that should be used.
    */
   public Dimension calculateIdWidth()
   {
@@ -166,7 +166,8 @@ public class AlignmentPanel
         new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));
 
     AlignmentI al = av.getAlignment();
-
+    int afwidth = (alignFrame!=null ? alignFrame.getWidth() : 300); 
+    int maxwidth = Math.max(20,Math.min(afwidth-200,(int) 2*afwidth/3));  
     int i = 0;
     int idWidth = 0;
     String id;
@@ -205,7 +206,7 @@ public class AlignmentPanel
       }
     }
 
-    return new Dimension(idWidth, 12);
+    return new Dimension(Math.min(maxwidth, idWidth), 12);
   }
 
   /**
@@ -985,19 +986,12 @@ public class AlignmentPanel
     }
     catch (OutOfMemoryError err)
     {
+      // Be noisy here.
       System.out.println("########################\n"
                          + "OUT OF MEMORY " + file + "\n"
                          + "########################");
-
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                                            "Out of Memory Creating Image!!"
-                                            +
-                                            "\nSee help files for increasing Java Virtual Machine memory."
-                                            , "Out of memory",
-                                            JOptionPane.WARNING_MESSAGE);
-      System.out.println("Create IMAGE: " + err);
-      System.gc();
-
+      new OOMWarning("Creating Image for "+file,err);
+      // System.out.println("Create IMAGE: " + err);
     }
     catch (Exception ex)
     {