X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=dc18cb799be5307f5194b3beb8005a20aa3109f1;hb=60b22c7b9ccf824a85fa2761e34dfdfba415a8a1;hp=26aff08d94833f4a8bbdbb55939107b3b7515879;hpb=008ad05ffd2964c864cdab0f18dff2fb36c82242;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 26aff08..dc18cb7 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 @@ -22,22 +22,43 @@ package jalview.io; import jalview.gui.AlignFrame; import jalview.gui.Jalview2XML; import javax.swing.JOptionPane; -import jalview.datamodel.Alignment; -import jalview.gui.Desktop; -import jalview.datamodel.SequenceI; + +import jalview.gui.*; +import jalview.datamodel.*; +import java.util.Vector; +import java.util.StringTokenizer; public class FileLoader { + String file; + String protocol; + String format; + AlignViewport viewport; + + public void LoadFile(AlignViewport viewport, String file, String protocol, String format) + { + this.viewport = viewport; + LoadFile(file, protocol, format); + } + public void LoadFile(String file, String protocol, String format) { - LoadingThread loader = new LoadingThread(file, protocol, format); + this.file = file; + this.protocol = protocol; + this.format = format; + + LoadingThread loader = new LoadingThread(); loader.start(); } public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, String format) { - LoadingThread loader = new LoadingThread(file, protocol, format); + this.file = file; + this.protocol = protocol; + this.format = format; + + LoadingThread loader = new LoadingThread(); loader.start(); while (loader.isAlive()) { @@ -53,65 +74,138 @@ public class FileLoader } - class LoadingThread - extends Thread -{ - String file; - String protocol; - String format; - AlignFrame af; - public LoadingThread(String file, String protocol, String format) + public void updateRecentlyOpened() { - this.file = file; - this.protocol = protocol; - this.format = format; - } + Vector recent = new Vector(); - public void run() - { - SequenceI[] sequences = null; + String type = protocol.equals(FormatAdapter.FILE) + ? "RECENT_FILE" : "RECENT_URL"; + + String historyItems = jalview.bin.Cache.getProperty(type); - if (format.equalsIgnoreCase("Jalview")) + StringTokenizer st; + + if (historyItems != null) { - af = Jalview2XML.LoadJalviewAlign(file); + st = new StringTokenizer(historyItems, "\t"); + + while (st.hasMoreTokens()) + { + recent.addElement(st.nextElement().toString().trim()); + } } - else + + if (recent.contains(file)) { - if (FormatAdapter.formats.contains(format)) + recent.remove(file); + } + + StringBuffer newHistory = new StringBuffer(file); + for (int i = 0; i < recent.size() && i < 10; i++) + { + newHistory.append("\t"); + newHistory.append(recent.elementAt(i)); + } + + jalview.bin.Cache.setProperty(type, newHistory.toString()); + + if(type.equals(FormatAdapter.FILE)) + 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; + + if (format.equalsIgnoreCase("Jalview")) { - sequences = new FormatAdapter().readFile(file, protocol, format); + af = new Jalview2XML().LoadJalviewAlign(file); } - - if ( (sequences != null) && (sequences.length > 0)) + else { - af = new AlignFrame(new Alignment(sequences)); - af.currentFileFormat = format; - af.statusBar.setText("Successfully loaded file " + file); - - Desktop.addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, - AlignFrame.NEW_WINDOW_HEIGHT); + String error = AppletFormatAdapter.SUPPORTED_FORMATS; + if (FormatAdapter.isValidFormat(format)) + { + try + { + sequences = new FormatAdapter().readFile(file, protocol, format); + } + catch (java.io.IOException ex) + { + error = ex.getMessage(); + } + } - try + if ( (sequences != null) && (sequences.length > 0)) { - af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); + if(viewport!=null) + { + for(int i=0; i