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