X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=9b06fdd9af28f158a0542ca9f31defbf86986422;hb=49236af7c1d2b9e2cd5f4ffca47922fdeb12cbbe;hp=a3ef2372b9548fee30986163d808447abaae2d28;hpb=2096047f177913a0ea9295a1e61782fce2f8d893;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index a3ef237..9b06fdd 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -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,71 +74,127 @@ 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 (format.equalsIgnoreCase("Jalview")) + if (historyItems != null) { - af = new Jalview2XML().LoadJalviewAlign(file); + st = new StringTokenizer(historyItems, "\t"); + + while (st.hasMoreTokens()) + { + recent.addElement(st.nextElement().toString().trim()); + } } - else + + if (recent.contains(file)) + { + 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() { - String errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS; + Desktop.instance.startLoading(file); - if (FormatAdapter.formats.contains(format)) + SequenceI[] sequences = null; + + if (format.equalsIgnoreCase("Jalview")) { - try{ - sequences = new FormatAdapter().readFile(file, protocol, format); - }catch(java.io.IOException ex) - { - errorMessage = ex.getMessage(); - } + 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