From: amwaterhouse Date: Thu, 5 Oct 2006 16:22:07 +0000 (+0000) Subject: OutOfMemoryError test X-Git-Tag: Release_2_2~318 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8e520ab1d2d745a408b3780971fa0fe92c649f32;p=jalview.git OutOfMemoryError test --- diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index dc18cb7..7fa4fda 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -27,13 +27,15 @@ import jalview.gui.*; import jalview.datamodel.*; import java.util.Vector; import java.util.StringTokenizer; +import javax.swing.SwingUtilities; -public class FileLoader +public class FileLoader implements Runnable { String file; String protocol; String format; AlignViewport viewport; + AlignFrame alignFrame; public void LoadFile(AlignViewport viewport, String file, String protocol, String format) { @@ -41,16 +43,26 @@ public class FileLoader LoadFile(file, protocol, format); } + + public void LoadFile(String file, String protocol, String format) { this.file = file; this.protocol = protocol; this.format = format; - LoadingThread loader = new LoadingThread(); - loader.start(); + final Thread loader = new Thread(this); + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + loader.start(); + } + }); } + public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, String format) { @@ -58,8 +70,9 @@ public class FileLoader this.protocol = protocol; this.format = format; - LoadingThread loader = new LoadingThread(); + Thread loader = new Thread(this); loader.start(); + while (loader.isAlive()) { try @@ -70,7 +83,7 @@ public class FileLoader {} } - return loader.af; + return alignFrame; } @@ -114,98 +127,120 @@ public class FileLoader jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); } - - class LoadingThread - extends Thread - { - - AlignFrame af; - - - public void run() { - if (Desktop.instance != null) - Desktop.instance.startLoading(file); + try{ + if (Desktop.instance != null) + Desktop.instance.startLoading(file); - SequenceI[] sequences = null; + SequenceI[] sequences = null; - if (format.equalsIgnoreCase("Jalview")) - { - af = new Jalview2XML().LoadJalviewAlign(file); - } - else - { - String error = AppletFormatAdapter.SUPPORTED_FORMATS; - - if (FormatAdapter.isValidFormat(format)) + if (format.equalsIgnoreCase("Jalview")) { - try - { - sequences = new FormatAdapter().readFile(file, protocol, format); - } - catch (java.io.IOException ex) - { - error = ex.getMessage(); - } + alignFrame = new Jalview2XML().LoadJalviewAlign(file); } - - if ( (sequences != null) && (sequences.length > 0)) + else { - if(viewport!=null) - { - for(int i=0; i 0)) { - public void run() + if (viewport != null) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - errorMessage, - "Error loading file", - JOptionPane.WARNING_MESSAGE); + for (int i = 0; i < sequences.length; i++) + { + viewport.getAlignment().addSequence(sequences[i]); + } + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + + } + else + { + Alignment al = new Alignment(sequences); + + alignFrame = new AlignFrame(al, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + alignFrame.currentFileFormat = format; + alignFrame.statusBar.setText("Successfully loaded file " + file); + + Desktop.addInternalFrame(alignFrame, file, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + + try + { + alignFrame.setMaximum(jalview.bin.Cache.getDefault( + "SHOW_FULLSCREEN", false)); + } + catch (java.beans.PropertyVetoException ex) + { + } } - }); + } + else + { + if (Desktop.instance != null) + Desktop.instance.stopLoading(); + + final String errorMessage = "Couldn't load file " + file + "\n" + + error; + + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + errorMessage, + "Error loading file", + JOptionPane.WARNING_MESSAGE); + } + }); + } } - } - if (af != null) + if (alignFrame != null) + { + updateRecentlyOpened(); + } + } + catch (OutOfMemoryError er) { - updateRecentlyOpened(); + + er.printStackTrace(); + alignFrame = null; + + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Out of memory loading file "+file+"!!" + + + "\nSee help files for increasing Java Virtual Machine memory." + , "Out of memory", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + }); } - if (Desktop.instance != null) + System.gc(); + if (Desktop.instance != null) Desktop.instance.stopLoading(); } - } }