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(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); } 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); } } } } }