X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=86c1cf4cc139ed5790de492c951682bd5842fe6c;hb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;hp=7db0b9041a6b39ea56fb06a87b1af2cb284daa7c;hpb=ca91ef118ff467dee590a67d8ea762c98451660a;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 7db0b90..86c1cf4 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -1,41 +1,42 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 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 -*/ + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + */ package jalview.io; -import jalview.gui.AlignFrame; -import jalview.gui.Jalview2XML; -import javax.swing.JOptionPane; +import java.util.*; + +import javax.swing.*; -import jalview.gui.*; import jalview.datamodel.*; -import java.util.Vector; -import java.util.StringTokenizer; +import jalview.gui.*; 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) + public void LoadFile(AlignViewport viewport, String file, String protocol, + String format) { this.viewport = viewport; LoadFile(file, protocol, format); @@ -47,19 +48,27 @@ public class FileLoader 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) + String format) { this.file = file; this.protocol = protocol; this.format = format; - LoadingThread loader = new LoadingThread(); + Thread loader = new Thread(this); loader.start(); + while (loader.isAlive()) { try @@ -70,11 +79,9 @@ public class FileLoader {} } - return loader.af; + return alignFrame; } - - public void updateRecentlyOpened() { Vector recent = new Vector(); @@ -110,96 +117,130 @@ public class FileLoader jalview.bin.Cache.setProperty(type, newHistory.toString()); - if(type.equals(FormatAdapter.FILE)) + if (type.equals(FormatAdapter.FILE)) + { jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); + } } - - class LoadingThread - extends Thread + public void run() { - - AlignFrame af; - - - - public void run() + try { - Desktop.instance.startLoading(file); + if (Desktop.instance != null) + { + Desktop.instance.startLoading(file); + } - SequenceI[] sequences = null; + Alignment al = null; if (format.equalsIgnoreCase("Jalview")) { - af = new Jalview2XML().LoadJalviewAlign(file); + alignFrame = new Jalview2XML().LoadJalviewAlign(file); } else { - String errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS; + String error = AppletFormatAdapter.SUPPORTED_FORMATS; - if (FormatAdapter.formats.contains(format)) + if (FormatAdapter.isValidFormat(format)) { try { - sequences = new FormatAdapter().readFile(file, protocol, format); + al = new FormatAdapter().readFile(file, protocol, format); } catch (java.io.IOException ex) { - errorMessage = ex.getMessage(); + error = ex.getMessage(); } } - if ( (sequences != null) && (sequences.length > 0)) + if ( (al != null) && (al.getHeight() > 0)) { - if(viewport!=null) + if (viewport != null) { - for(int i=0; i