X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=67c72c224d1fa05213375865372f336c44042540;hb=0d6e36143a2d7471edb7ef386d0b79095e0cd63e;hp=40b8ffb3fa3c0198f9fd229629f804387a9f0635;hpb=258c0056231d8a97c1d40dd665260e7814d11206;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 40b8ffb..67c72c2 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -1,31 +1,70 @@ +/* +* 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 +*/ + 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.Preferences; + +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()) { try { - Thread.sleep(50); + Thread.sleep(500); } catch (Exception ex) {} @@ -35,65 +74,130 @@ 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); + + StringTokenizer st; + + if (historyItems != null) + { + st = new StringTokenizer(historyItems, "\t"); + + while (st.hasMoreTokens()) + { + recent.addElement(st.nextElement().toString().trim()); + } + } - if (format.equalsIgnoreCase("Jalview")) + if (recent.contains(file)) { - af = Jalview2XML.LoadJalviewAlign(file); + recent.remove(file); } - else + + StringBuffer newHistory = new StringBuffer(file); + for (int i = 0; i < recent.size() && i < 10; i++) { - if (FormatAdapter.formats.contains(format)) + 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() + { + Desktop.instance.startLoading(file); + + SequenceI[] sequences = null; + + if (format.equalsIgnoreCase("Jalview")) { - sequences = 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 errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS; + if (FormatAdapter.formats.contains(format)) + { + try + { + sequences = new FormatAdapter().readFile(file, protocol, format); + } + catch (java.io.IOException ex) + { + errorMessage = 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