Formatted source
[jalview.git] / src / jalview / bin / Jalview.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package jalview.bin;\r
20 \r
21 import jalview.gui.*;\r
22 \r
23 import jalview.io.*;\r
24 \r
25 import org.apache.log4j.*;\r
26 \r
27 import java.awt.event.*;\r
28 \r
29 import javax.swing.*;\r
30 \r
31 \r
32 public class Jalview extends JApplet {\r
33     public static JApplet applet;\r
34     Desktop frame;\r
35 \r
36     public void init() {\r
37         applet = this;\r
38         Cache.loadProperties();\r
39         jalview.gui.Preferences.initPreferences();\r
40 \r
41         frame = new Desktop();\r
42         frame.setResizable(true);\r
43         frame.setVisible(true);\r
44         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);\r
45         frame.addWindowListener(new WindowAdapter() {\r
46                 public void windowClosing(WindowEvent e) {\r
47                     applet.stop();\r
48                     applet.destroy();\r
49                 }\r
50             });\r
51 \r
52         String file = getParameter("alignment");\r
53 \r
54         if (file != null) {\r
55             jalview.bin.Cache.setProperty("LAST_DIRECTORY", file);\r
56 \r
57             String protocol = "File";\r
58 \r
59             if (file.indexOf("http:") > -1) {\r
60                 protocol = "URL";\r
61             }\r
62 \r
63             String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
64 \r
65             frame.LoadFile(file, protocol, format);\r
66         }\r
67     }\r
68 \r
69     public void destroy() {\r
70         if (applet != null) {\r
71             applet.stop();\r
72         } else {\r
73             System.exit(0);\r
74         }\r
75 \r
76         frame.setVisible(false);\r
77     }\r
78 \r
79     private static void initLogger() {\r
80         Logger l = Logger.getLogger("org.apache.axis");\r
81 \r
82         if (Cache.getProperty("logs.Axis.Level") == null) {\r
83             Cache.setProperty("logs.Axis.Level", Level.INFO.toString());\r
84         }\r
85 \r
86         l.setLevel(Level.toLevel(Cache.getProperty("logs.Axis.Level")));\r
87 \r
88         ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),\r
89                 "System.err");\r
90         ap.setName("Axis");\r
91         l.addAppender(ap);\r
92     }\r
93 \r
94     public static void main(String[] args) {\r
95         Cache.loadProperties();\r
96         jalview.gui.Preferences.initPreferences();\r
97 \r
98         try {\r
99             initLogger();\r
100         } catch (Exception e) {\r
101             System.err.println("Problems initializing the log4j system\n");\r
102             e.printStackTrace();\r
103         }\r
104 \r
105         try {\r
106             UIManager.setLookAndFeel(\r
107             //   "javax.swing.plaf.metal.MetalLookAndFeel"\r
108             //  "javax.swing.plaf.multi.MultiLookAndFeel"\r
109             UIManager.getSystemLookAndFeelClassName());\r
110         } catch (Exception ex) {\r
111         }\r
112 \r
113         Desktop frame = new Desktop();\r
114         frame.setResizable(true);\r
115         frame.setVisible(true);\r
116 \r
117         if ((args != null) && (args.length > 0)) {\r
118             String file = null;\r
119 \r
120             if (args[0].equals("-open")) {\r
121                 file = args[1];\r
122             } else {\r
123                 file = args[0];\r
124             }\r
125 \r
126             String protocol = "File";\r
127 \r
128             if (file.indexOf("http:") > -1) {\r
129                 protocol = "URL";\r
130             }\r
131 \r
132             String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
133 \r
134             frame.LoadFile(file, protocol, format);\r
135         }\r
136 \r
137         if (jalview.gui.Preferences.showStartupFile &&\r
138                 (jalview.gui.Preferences.startupFile != null)) {\r
139             String file = jalview.gui.Preferences.startupFile;\r
140             String protocol = "File";\r
141 \r
142             if (file.indexOf("http:") > -1) {\r
143                 protocol = "URL";\r
144             }\r
145 \r
146             if (file.endsWith(".jar")) {\r
147                 Jalview2XML.LoadJalviewAlign(file);\r
148             } else {\r
149                 String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
150                 frame.LoadFile(file, protocol, format);\r
151             }\r
152         }\r
153     }\r
154 }\r