X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=7fa4fdaadb28967ca12627e2a1a2e66c21e0592f;hb=c97c8a9e4fd58a4927e040e314c5be3c5356745e;hp=7db0b9041a6b39ea56fb06a87b1af2cb284daa7c;hpb=ca91ef118ff467dee590a67d8ea762c98451660a;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 7db0b90..7fa4fda 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* Copyright (C) 2006 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 @@ -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,92 +127,120 @@ public class FileLoader jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); } - - class LoadingThread - extends Thread - { - - AlignFrame af; - - - public void run() { - 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 errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS; - - if (FormatAdapter.formats.contains(format)) + if (format.equalsIgnoreCase("Jalview")) { - try - { - sequences = new FormatAdapter().readFile(file, protocol, format); - } - catch (java.io.IOException ex) - { - errorMessage = ex.getMessage(); - } + alignFrame = new Jalview2XML().LoadJalviewAlign(file); } - - if ( (sequences != null) && (sequences.length > 0)) + else { - if(viewport!=null) - { - for(int i=0; i 0)) + { + if (viewport != null) + { + 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); + } + }); + } } - else + + if (alignFrame != null) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Couldn't load file " + file + - "\n" - + errorMessage, - "Error loading file", - JOptionPane.WARNING_MESSAGE); + updateRecentlyOpened(); } } - - if (af != null) + 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); + } + }); } - Desktop.instance.stopLoading(); + System.gc(); + if (Desktop.instance != null) + Desktop.instance.stopLoading(); + } - } }