GPL license added
[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 \r
20 package jalview.bin;\r
21 \r
22 import jalview.gui.*;\r
23 import javax.swing.*;\r
24 import java.awt.event.*;\r
25 import jalview.io.*;\r
26 \r
27 import org.apache.log4j.*;\r
28 \r
29 public class Jalview extends JApplet\r
30 {\r
31   public static JApplet applet;\r
32   Desktop frame;\r
33   public void init()\r
34   {\r
35     applet = this;\r
36     Cache.loadProperties();\r
37     jalview.gui.Preferences.initPreferences();\r
38 \r
39     frame = new Desktop();\r
40     frame.setResizable(true);\r
41     frame.setVisible(true);\r
42     frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);\r
43     frame.addWindowListener(new WindowAdapter()\r
44     {\r
45       public void windowClosing(WindowEvent e)\r
46       {\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     {\r
56       jalview.bin.Cache.setProperty("LAST_DIRECTORY", file);\r
57       String protocol = "File";\r
58       if (file.indexOf("http:") > -1)\r
59         protocol = "URL";\r
60 \r
61       String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
62 \r
63       frame.LoadFile(file, protocol, format);\r
64     }\r
65   }\r
66 \r
67   public void destroy()\r
68   {\r
69     if(applet!=null)\r
70       applet.stop();\r
71     else\r
72       System.exit(0);\r
73     frame.setVisible(false);\r
74   }\r
75 \r
76   private static void initLogger() {\r
77     Logger l = Logger.getLogger("org.apache.axis");\r
78     if (Cache.getProperty("logs.Axis.Level")==null) {\r
79       Cache.setProperty("logs.Axis.Level", Level.INFO.toString());\r
80     }\r
81 \r
82     l.setLevel(Level.toLevel(Cache.getProperty("logs.Axis.Level")));\r
83     ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),"System.err");\r
84     ap.setName("Axis");\r
85     l.addAppender(ap);\r
86   }\r
87    public static void main(String[] args) {\r
88 \r
89     Cache.loadProperties();\r
90     jalview.gui.Preferences.initPreferences();\r
91     try {\r
92       initLogger();\r
93     } catch (Exception e) {\r
94       System.err.println("Problems initializing the log4j system\n");\r
95       e.printStackTrace();\r
96     }\r
97     try{\r
98        UIManager.setLookAndFeel(\r
99    //   "javax.swing.plaf.metal.MetalLookAndFeel"\r
100     //  "javax.swing.plaf.multi.MultiLookAndFeel"\r
101          UIManager.getSystemLookAndFeelClassName()\r
102      //    UIManager.getCrossPlatformLookAndFeelClassName()\r
103        // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"\r
104        //   "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"\r
105        //  "com.sun.java.swing.plaf.motif.MotifLookAndFeel"\r
106      );\r
107      }\r
108      catch (Exception ex)\r
109      {}\r
110 \r
111      Desktop frame = new Desktop();\r
112      frame.setResizable(true);\r
113      frame.setVisible(true);\r
114 \r
115 \r
116 \r
117      if(args!=null && args.length>0)\r
118      {\r
119          String file=null;\r
120          if(args[0].equals("-open"))\r
121            file = args[1];\r
122          else\r
123            file = args[0];\r
124 \r
125          String protocol = "File";\r
126          if(file.indexOf("http:")>-1)\r
127            protocol = "URL";\r
128 \r
129          String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
130 \r
131          frame.LoadFile(file, protocol, format);\r
132      }\r
133 \r
134      if(jalview.gui.Preferences.showStartupFile &&\r
135          jalview.gui.Preferences.startupFile!=null)\r
136      {\r
137        String file = jalview.gui.Preferences.startupFile;\r
138        String protocol = "File";\r
139        if (file.indexOf("http:") > -1)\r
140          protocol = "URL";\r
141 \r
142        if(file.endsWith(".jar"))\r
143          Jalview2XML.LoadJalviewAlign(file);\r
144        else\r
145        {\r
146          String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
147          frame.LoadFile(file, protocol, format);\r
148        }\r
149      }\r
150 \r
151 \r
152 \r
153    }\r
154 \r
155 }\r
156 \r