system.exit or destroy if applet or app
[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 java.applet.Applet;\r
16 \r
17 public class Jalview extends JApplet\r
18 {\r
19   public static JApplet applet;\r
20   Desktop frame;\r
21   public void init()\r
22   {\r
23     applet = this;\r
24 \r
25     frame = new Desktop();\r
26     frame.setResizable(true);\r
27     frame.setVisible(true);\r
28     frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);\r
29     frame.addWindowListener(new WindowAdapter()\r
30     {\r
31       public void windowClosing(WindowEvent e)\r
32       {\r
33           applet.stop();\r
34           applet.destroy();\r
35       }\r
36     });\r
37 \r
38     String file = getParameter("alignment");\r
39 \r
40     if(file!=null)\r
41     {\r
42       jalview.bin.Cache.LAST_DIRECTORY = file;\r
43       String protocol = "File";\r
44       if (file.indexOf("http:") > -1)\r
45         protocol = "URL";\r
46 \r
47       String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
48 \r
49       frame.LoadFile(file, protocol, format);\r
50     }\r
51   }\r
52 \r
53   public void destroy()\r
54   {\r
55     if(applet!=null)\r
56       applet.stop();\r
57     else\r
58       System.exit(0);\r
59     frame.setVisible(false);\r
60   }\r
61 \r
62    public static void main(String[] args) {\r
63      try{\r
64        UIManager.setLookAndFeel(\r
65    //   "javax.swing.plaf.metal.MetalLookAndFeel"\r
66     //  "javax.swing.plaf.multi.MultiLookAndFeel"\r
67          UIManager.getCrossPlatformLookAndFeelClassName()\r
68        // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"\r
69        //   "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"\r
70        //  "com.sun.java.swing.plaf.motif.MotifLookAndFeel"\r
71      );\r
72      }\r
73      catch (Exception ex)\r
74      {}\r
75 \r
76     // JFrame.setDefaultLookAndFeelDecorated(true);\r
77      Desktop frame = new Desktop();\r
78      frame.setResizable(true);\r
79      frame.setVisible(true);\r
80 \r
81 \r
82      if(args!=null && args.length>0)\r
83      {\r
84          String file = args[0];\r
85          jalview.bin.Cache.LAST_DIRECTORY = file;\r
86          String protocol = "File";\r
87          if(file.indexOf("http:")>-1)\r
88            protocol = "URL";\r
89 \r
90          String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
91 \r
92          frame.LoadFile(file, protocol, format);\r
93      }\r
94 \r
95    }\r
96 \r
97 }\r