+package jalview.io;\r
+\r
+import jalview.gui.AlignFrame;\r
+import jalview.gui.Jalview2XML;\r
+import javax.swing.JOptionPane;\r
+import jalview.datamodel.Alignment;\r
+import jalview.gui.Desktop;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.gui.Preferences;\r
+\r
+public class FileLoader\r
+{\r
+ public void LoadFile(String file, String protocol, String format)\r
+ {\r
+ LoadingThread loader = new LoadingThread(file, protocol, format);\r
+ loader.start();\r
+ }\r
+\r
+ public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,\r
+ String format)\r
+ {\r
+ LoadingThread loader = new LoadingThread(file, protocol, format);\r
+ loader.start();\r
+ while (loader.isAlive())\r
+ {\r
+ try\r
+ {\r
+ Thread.sleep(50);\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
+ }\r
+\r
+ return loader.af;\r
+ }\r
+\r
+\r
+ class LoadingThread\r
+ extends Thread\r
+{\r
+ String file;\r
+ String protocol;\r
+ String format;\r
+ AlignFrame af;\r
+\r
+ public LoadingThread(String file, String protocol, String format)\r
+ {\r
+ this.file = file;\r
+ this.protocol = protocol;\r
+ this.format = format;\r
+ }\r
+\r
+ public void run()\r
+ {\r
+ SequenceI[] sequences = null;\r
+\r
+ if (format.equalsIgnoreCase("Jalview"))\r
+ {\r
+ af = Jalview2XML.LoadJalviewAlign(file);\r
+ }\r
+ else\r
+ {\r
+ if (FormatAdapter.formats.contains(format))\r
+ {\r
+ sequences = FormatAdapter.readFile(file, protocol, format);\r
+ }\r
+\r
+ if ( (sequences != null) && (sequences.length > 0))\r
+ {\r
+ af = new AlignFrame(new Alignment(sequences));\r
+ af.currentFileFormat = format;\r
+ af.statusBar.setText("Successfully loaded file " + file);\r
+\r
+ Desktop.addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,\r
+ AlignFrame.NEW_WINDOW_HEIGHT);\r
+\r
+\r
+ try\r
+ {\r
+ af.setMaximum(Preferences.showFullscreen);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+ }\r
+ else\r
+ {\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Couldn't open file.\n" +\r
+ "Formats currently supported are\n" +\r
+ "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!\r
+ , "Error loading file",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+}\r