added castor logger configuration.
[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 laxis = Logger.getLogger("org.apache.axis");\r
81         Logger lcastor = Logger.getLogger("org.exolab.castor");\r
82         if (Cache.getProperty("logs.Axis.Level") == null) {\r
83             Cache.setProperty("logs.Axis.Level", Level.INFO.toString());\r
84         }\r
85         if (Cache.getProperty("logs.Castor.Level") == null) {\r
86             Cache.setProperty("logs.Castor.Level", Level.INFO.toString());\r
87         }\r
88 \r
89         laxis.setLevel(Level.toLevel(Cache.getProperty("logs.Axis.Level")));\r
90         lcastor.setLevel(Level.toLevel(Cache.getProperty("logs.Castor.Level")));\r
91 \r
92         ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),\r
93                 "System.err");\r
94         ap.setName("JalviewLogger");\r
95         laxis.addAppender(ap);\r
96         lcastor.addAppender(ap);\r
97     }\r
98 \r
99     public static void main(String[] args) {\r
100         Cache.loadProperties();\r
101         jalview.gui.Preferences.initPreferences();\r
102 \r
103         try {\r
104             initLogger();\r
105         } catch (Exception e) {\r
106             System.err.println("Problems initializing the log4j system\n");\r
107             e.printStackTrace();\r
108         }\r
109 \r
110         try {\r
111             UIManager.setLookAndFeel(\r
112             //   "javax.swing.plaf.metal.MetalLookAndFeel"\r
113             //  "javax.swing.plaf.multi.MultiLookAndFeel"\r
114             UIManager.getSystemLookAndFeelClassName());\r
115         } catch (Exception ex) {\r
116         }\r
117 \r
118         Desktop frame = new Desktop();\r
119         frame.setResizable(true);\r
120         frame.setVisible(true);\r
121 \r
122         if ((args != null) && (args.length > 0)) {\r
123             String file = null;\r
124 \r
125             if (args[0].equals("-open")) {\r
126                 file = args[1];\r
127             } else {\r
128                 file = args[0];\r
129             }\r
130 \r
131             String protocol = "File";\r
132 \r
133             if (file.indexOf("http:") > -1) {\r
134                 protocol = "URL";\r
135             }\r
136 \r
137             String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
138 \r
139             frame.LoadFile(file, protocol, format);\r
140         }\r
141 \r
142         if (jalview.gui.Preferences.showStartupFile &&\r
143                 (jalview.gui.Preferences.startupFile != null)) {\r
144             String file = jalview.gui.Preferences.startupFile;\r
145             String protocol = "File";\r
146 \r
147             if (file.indexOf("http:") > -1) {\r
148                 protocol = "URL";\r
149             }\r
150 \r
151             if (file.endsWith(".jar")) {\r
152                 Jalview2XML.LoadJalviewAlign(file);\r
153             } else {\r
154                 String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
155                 frame.LoadFile(file, protocol, format);\r
156             }\r
157         }\r
158     }\r
159 }\r