JAL-3848 add compbio and jalview to direct connection list for J2S
[jalview.git] / src / jalview / bin / Jalview.java
index fea99fb..1c7e4ea 100755 (executable)
@@ -73,7 +73,6 @@ import jalview.schemes.ColourSchemeProperty;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
-//import netscape.javascript.JSObject;
 
 /**
  * Main class for Jalview Application <br>
@@ -111,7 +110,6 @@ public class Jalview implements ApplicationSingletonI
   // }
   public static Jalview getInstance()
   {
-    System.out.println("Hello, MW!!!!!!!!!!!!");
     return (Jalview) ApplicationSingletonProvider
             .getInstance(Jalview.class);
   }
@@ -188,8 +186,8 @@ public class Jalview implements ApplicationSingletonI
   class FeatureFetcher
   {
     /*
-     * TODO: generalise to track all jalview events to orchestrate batch processing
-     * events.
+     * TODO: generalise to track all jalview events to orchestrate batch
+     * processing events.
      */
 
     private int queued = 0;
@@ -267,6 +265,11 @@ public class Jalview implements ApplicationSingletonI
       System.setSecurityManager(null);
     }
 
+    /*
+     * @j2sNative J2S.db._DirectDatabaseCalls["compbio.dundee.ac.uk"]=null;
+     * @j2sNative J2S.db._DirectDatabaseCalls["jalview.org"]=null;
+     * 
+     */
     System.out
             .println("Java version: " + System.getProperty("java.version"));
     System.out.println("Java Home: " + System.getProperty("java.home"));
@@ -340,13 +343,6 @@ public class Jalview implements ApplicationSingletonI
         }
         headless = true;
       }
-      if (GraphicsEnvironment.isHeadless())
-      {
-        headless = true;
-      }
-      // <<?
-
-      // anything else!
 
       final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
       allowServices = !("none".equals(jabawsUrl));
@@ -470,7 +466,12 @@ public class Jalview implements ApplicationSingletonI
         System.out.println("Error setting Taskbar: " + t.getMessage());
       }
       desktop.setVisible(true);
-
+      if (Platform.isJS())
+        Cache.setProperty("SHOW_JWS2_SERVICES", "false");
+      if (allowServices)
+      {
+        desktop.startServiceDiscovery();
+      }
       if (!isJS)
       /**
        * Java only
@@ -478,8 +479,6 @@ public class Jalview implements ApplicationSingletonI
        * @j2sIgnore
        */
       {
-        if (allowServices)
-          desktop.startServiceDiscovery();
         if (!aparser.contains("nousagestats"))
         {
           startUsageStats(desktop);
@@ -772,6 +771,10 @@ public class Jalview implements ApplicationSingletonI
           createOutputFiles(aparser, format);
         }
       }
+      if (headless)
+      {
+        af.getViewport().getCalcManager().shutdown();
+      }
     }
     // extract groovy arguments before anything else.
     // Once all other stuff is done, execute any groovy scripts (in order)
@@ -982,8 +985,7 @@ public class Jalview implements ApplicationSingletonI
    * @param aparser
    * @param format
    */
-  private void createOutputFiles(ArgsParser aparser,
-          FileFormatI format)
+  private void createOutputFiles(ArgsParser aparser, FileFormatI format)
   {
     AlignFrame af = currentAlignFrame;
     while (aparser.getSize() >= 2)
@@ -1038,28 +1040,51 @@ public class Jalview implements ApplicationSingletonI
                 "Creating image map: " + imageFile.getAbsolutePath());
         continue;
       default:
-        format = FileFormats.getInstance().forName(outputFormat);
-        if (format == null)
+        // fall through - try to parse as an alignment data export format
+        FileFormatI outFormat = null;
+        try
+        {
+          outFormat = FileFormats.getInstance().forName(outputFormat);
+        } catch (Exception formatP)
         {
-          System.out.println("Invalid file format: " + outputFormat);
-          break;
         }
-        fname = new File(aparser.nextValue()).getAbsolutePath();
-        af.saveAlignment(fname, format);
+        if (outFormat == null)
+        {
+          System.out.println("Couldn't parse " + outputFormat
+                  + " as a valid Jalview format string.");
+          continue;
+        }
+        if (!outFormat.isWritable())
+        {
+          System.out.println(
+                  "This version of Jalview does not support alignment export as "
+                          + outputFormat);
+          continue;
+        }
+        // record file as it was passed to Jalview so it is recognisable to the CLI
+        // caller
+        String file;
+        fname = new File(file = aparser.nextValue()).getAbsolutePath();
+        // JBPNote - yuck - really wish we did have a bean returned from this which gave
+        // success/fail like before !
+        af.saveAlignment(fname, outFormat);
         if (!af.isSaveAlignmentSuccessful())
         {
-          System.out.println("Error writing file " + fname + " in " + format
-                  + " format!!");
-          break;
+          System.out.println("Written alignment in " + outputFormat
+                  + " format to " + file);
+          continue;
+        }
+        else
+        {
+          System.out.println("Error writing file " + file + " in "
+                  + outputFormat + " format!!");
         }
-        continue;
       }
-      System.out.println("Unknown arg: " + outputFormat);      
-      break;
     }
+    // ??? Should report - 'ignoring' extra args here...
     while (aparser.getSize() > 0)
     {
-      System.out.println("Unknown arg: " + aparser.nextValue());
+      System.out.println("Ignoring extra argument: " + aparser.nextValue());
     }
   }