Applet has main method, excutable
authoramwaterhouse <Andrew Waterhouse>
Thu, 15 Sep 2005 09:09:17 +0000 (09:09 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 15 Sep 2005 09:09:17 +0000 (09:09 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/IdPanel.java
src/jalview/bin/JalviewLite.java

index 14a341d..289e761 100755 (executable)
@@ -48,40 +48,43 @@ public class AlignFrame
     add(alignPanel);\r
     alignPanel.validate();\r
 \r
-    String treeFile = applet.getParameter("treeFile");\r
-    if (treeFile != null)\r
+    if(applet!=null)\r
     {\r
-      try\r
+      String treeFile = applet.getParameter("treeFile");\r
+      if (treeFile != null)\r
       {\r
-        treeFile = treeFile;\r
-        jalview.io.NewickFile fin = new jalview.io.NewickFile(applet.\r
-            getCodeBase() + treeFile, "URL");\r
-        fin.parse();\r
+        try\r
+        {\r
+          treeFile = treeFile;\r
+          jalview.io.NewickFile fin = new jalview.io.NewickFile(applet.\r
+              getCodeBase() + treeFile, "URL");\r
+          fin.parse();\r
 \r
-        if (fin.getTree() != null)\r
+          if (fin.getTree() != null)\r
+          {\r
+            TreePanel tp = null;\r
+            tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),\r
+                               fin, "FromFile", applet.getCodeBase() + treeFile);\r
+            jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);\r
+            addTreeMenuItem(tp, treeFile);\r
+          }\r
+        }\r
+        catch (Exception ex)\r
         {\r
-          TreePanel tp = null;\r
-          tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),\r
-                             fin, "FromFile", applet.getCodeBase() + treeFile);\r
-          jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);\r
-          addTreeMenuItem(tp, treeFile);\r
+          ex.printStackTrace();\r
         }\r
       }\r
-      catch (Exception ex)\r
+\r
+      String param = applet.getParameter("sortBy");\r
+      if (param != null)\r
       {\r
-        ex.printStackTrace();\r
+        if (param.equalsIgnoreCase("Id"))\r
+          sortIDMenuItem_actionPerformed(null);\r
+        else if (param.equalsIgnoreCase("Pairwise Identity"))\r
+          sortPairwiseMenuItem_actionPerformed(null);\r
       }\r
     }\r
 \r
-    String param = applet.getParameter("sortBy");\r
-    if(param!=null)\r
-    {\r
-      if (param.equalsIgnoreCase("Id"))\r
-        sortIDMenuItem_actionPerformed(null);\r
-      else if (param.equalsIgnoreCase("Pairwise Identity"))\r
-        sortPairwiseMenuItem_actionPerformed(null);\r
-    }\r
-\r
     this.addWindowListener(new WindowAdapter()\r
     {\r
       public void windowClosing(WindowEvent e)\r
@@ -127,6 +130,8 @@ public class AlignFrame
   {\r
     PaintRefresher.components.remove(viewport.alignment);\r
     dispose();\r
+    if(PaintRefresher.components.size()==0 && applet==null)\r
+      System.exit(0);\r
   }\r
 \r
   Stack historyList = new Stack();\r
index f3db9be..b6e6a2b 100755 (executable)
@@ -50,14 +50,17 @@ public class IdPanel
     idCanvas.addMouseMotionListener(this);\r
 \r
     String label, url;\r
-    for(int i=1; i<10; i++)\r
+    if(parent.alignFrame.applet!=null)\r
     {\r
-      label = parent.alignFrame.applet.getParameter("linkLabel_"+i);\r
-      url = parent.alignFrame.applet.getParameter("linkURL_"+i);\r
+      for (int i = 1; i < 10; i++)\r
+      {\r
+        label = parent.alignFrame.applet.getParameter("linkLabel_" + i);\r
+        url = parent.alignFrame.applet.getParameter("linkURL_" + i);\r
 \r
-      if(label!=null && url!=null)\r
-        links.addElement(label+"|"+url);\r
+        if (label != null && url != null)\r
+          links.addElement(label + "|" + url);\r
 \r
+      }\r
     }\r
     if (links.size() < 1)\r
     {\r
index b99d642..c9ec391 100755 (executable)
@@ -98,6 +98,26 @@ public class JalviewLite extends Applet
         }\r
     }\r
 \r
+    public static void main(String [] args)\r
+    {\r
+      if(args.length!=1)\r
+      {\r
+        System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");\r
+        System.exit(1);\r
+      }\r
+\r
+      String format = jalview.io.IdentifyFile.Identify(args[0],"File");\r
+      SequenceI[] sequences = FormatAdapter.readFile(args[0], "File", format);\r
+\r
+      if ( (sequences != null) && (sequences.length > 0))\r
+      {\r
+        AlignFrame af = new AlignFrame(new Alignment(sequences), null);\r
+        addFrame(af, args[0], AlignFrame.NEW_WINDOW_WIDTH,\r
+                 AlignFrame.NEW_WINDOW_HEIGHT);\r
+        af.statusBar.setText("Successfully loaded file " + args[0]);\r
+      }\r
+    }\r
+\r
     /**\r
      * Displays the given URL in a new browser window\r
      *\r
@@ -111,14 +131,21 @@ public class JalviewLite extends Applet
 \r
       public static void showURL(String url, String target)\r
       {\r
-        try\r
+        if(applet==null)\r
         {\r
-          applet.getAppletContext().showDocument(new java.net.URL(url),\r
-                                                 target);\r
+          System.out.println("Not running as applet - no browser available.");\r
         }\r
-        catch (Exception ex)\r
+        else\r
         {\r
-          ex.printStackTrace();\r
+          try\r
+          {\r
+            applet.getAppletContext().showDocument(new java.net.URL(url),\r
+                target);\r
+          }\r
+          catch (Exception ex)\r
+          {\r
+            ex.printStackTrace();\r
+          }\r
         }\r
       }\r
 \r