Sleep for longer
[jalview.git] / src / jalview / io / FileLoader.java
1 package jalview.io;\r
2 \r
3 import jalview.gui.AlignFrame;\r
4 import jalview.gui.Jalview2XML;\r
5 import javax.swing.JOptionPane;\r
6 import jalview.datamodel.Alignment;\r
7 import jalview.gui.Desktop;\r
8 import jalview.datamodel.SequenceI;\r
9 \r
10 public class FileLoader\r
11 {\r
12   public void LoadFile(String file, String protocol, String format)\r
13   {\r
14     LoadingThread loader = new LoadingThread(file, protocol, format);\r
15     loader.start();\r
16   }\r
17 \r
18   public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,\r
19                                                   String format)\r
20   {\r
21     LoadingThread loader = new LoadingThread(file, protocol, format);\r
22     loader.start();\r
23     while (loader.isAlive())\r
24     {\r
25       try\r
26       {\r
27         Thread.sleep(500);\r
28       }\r
29       catch (Exception ex)\r
30       {}\r
31     }\r
32 \r
33     return loader.af;\r
34   }\r
35 \r
36 \r
37   class LoadingThread\r
38     extends Thread\r
39 {\r
40   String file;\r
41   String protocol;\r
42   String format;\r
43   AlignFrame af;\r
44 \r
45   public LoadingThread(String file, String protocol, String format)\r
46   {\r
47     this.file = file;\r
48     this.protocol = protocol;\r
49     this.format = format;\r
50   }\r
51 \r
52   public void run()\r
53   {\r
54     SequenceI[] sequences = null;\r
55 \r
56     if (format.equalsIgnoreCase("Jalview"))\r
57     {\r
58       af = Jalview2XML.LoadJalviewAlign(file);\r
59     }\r
60     else\r
61     {\r
62       if (FormatAdapter.formats.contains(format))\r
63       {\r
64         sequences = FormatAdapter.readFile(file, protocol, format);\r
65       }\r
66 \r
67       if ( (sequences != null) && (sequences.length > 0))\r
68       {\r
69         af = new AlignFrame(new Alignment(sequences));\r
70         af.currentFileFormat = format;\r
71         af.statusBar.setText("Successfully loaded file " + file);\r
72 \r
73         Desktop.addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,\r
74                            AlignFrame.NEW_WINDOW_HEIGHT);\r
75 \r
76 \r
77         try\r
78         {\r
79           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));\r
80         }\r
81         catch (Exception ex)\r
82         {\r
83         }\r
84       }\r
85       else\r
86       {\r
87         JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
88                                               "Couldn't open file.\n" +\r
89                                               "Formats currently supported are\n" +\r
90                                               "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!\r
91                                               , "Error loading file",\r
92                                               JOptionPane.WARNING_MESSAGE);\r
93       }\r
94     }\r
95   }\r
96 }\r
97 \r
98 }\r