X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=7fa4fdaadb28967ca12627e2a1a2e66c21e0592f;hb=f3581eb4882e66b7d66a9573be5103358196fd2d;hp=0fc4aa86af4e812147062be4bef39a366332c8ca;hpb=73522f02bc614929defe2a61bd1c0787fb747fa7;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 0fc4aa8..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() { - if (Desktop.instance != null) - Desktop.instance.startLoading(file); - - SequenceI[] sequences = null; + try{ + if (Desktop.instance != null) + Desktop.instance.startLoading(file); - if (format.equalsIgnoreCase("Jalview")) - { - af = new Jalview2XML().LoadJalviewAlign(file); - } - else - { - String errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS; + SequenceI[] sequences = null; - if (FormatAdapter.formats.contains(format)) + if (format.equalsIgnoreCase("Jalview")) { - try - { - sequences = new FormatAdapter().readFile(file, protocol, format); - } - catch (java.io.IOException ex) + alignFrame = new Jalview2XML().LoadJalviewAlign(file); + } + else + { + String error = AppletFormatAdapter.SUPPORTED_FORMATS; + + if (FormatAdapter.isValidFormat(format)) { - errorMessage = ex.getMessage(); + try + { + sequences = new FormatAdapter().readFile(file, protocol, format); + } + catch (java.io.IOException ex) + { + error = ex.getMessage(); + } } - } - if ( (sequences != null) && (sequences.length > 0)) - { - if(viewport!=null) + if ( (sequences != null) && (sequences.length > 0)) { - for(int i=0; i