From 7a79aff7269435b0719c9cd4f30893b81fa2f7b0 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 3 Aug 2005 13:07:39 +0000 Subject: [PATCH] FileLoading removed from desktop --- src/jalview/io/FileLoader.java | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 src/jalview/io/FileLoader.java diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java new file mode 100755 index 0000000..d2d477e --- /dev/null +++ b/src/jalview/io/FileLoader.java @@ -0,0 +1,99 @@ +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; + +public class FileLoader +{ + public void LoadFile(String file, String protocol, String format) + { + LoadingThread loader = new LoadingThread(file, protocol, format); + loader.start(); + } + + public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, + String format) + { + LoadingThread loader = new LoadingThread(file, protocol, format); + loader.start(); + while (loader.isAlive()) + { + try + { + Thread.sleep(50); + } + catch (Exception ex) + {} + } + + return loader.af; + } + + + class LoadingThread + extends Thread +{ + String file; + String protocol; + String format; + AlignFrame af; + + public LoadingThread(String file, String protocol, String format) + { + this.file = file; + this.protocol = protocol; + this.format = format; + } + + public void run() + { + SequenceI[] sequences = null; + + if (format.equalsIgnoreCase("Jalview")) + { + af = Jalview2XML.LoadJalviewAlign(file); + } + else + { + if (FormatAdapter.formats.contains(format)) + { + sequences = FormatAdapter.readFile(file, protocol, format); + } + + if ( (sequences != null) && (sequences.length > 0)) + { + 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); + + + try + { + af.setMaximum(Preferences.showFullscreen); + } + catch (Exception ex) + { + } + } + else + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Couldn't open file.\n" + + "Formats currently supported are\n" + + "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter! + , "Error loading file", + JOptionPane.WARNING_MESSAGE); + } + } + } +} + +} -- 1.7.10.2