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