JAL-3662 JAL-3660 JAL-3561 source formatting
[jalview.git] / src / jalview / bin / Jalview.java
index 4a5c733..4f76776 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.bin;
 
+import java.awt.GraphicsEnvironment;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -72,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>
@@ -110,6 +110,7 @@ public class Jalview implements ApplicationSingletonI
   // }
   public static Jalview getInstance()
   {
+    System.out.println("Hello, MW!!!!!!!!!!!!");
     return (Jalview) ApplicationSingletonProvider
             .getInstance(Jalview.class);
   }
@@ -326,11 +327,20 @@ public class Jalview implements ApplicationSingletonI
         showUsage();
         System.exit(0);
       }
-      // ?>>
+      // BH note: Only -nodisplay is official; others are deprecated?
       if (aparser.contains("nodisplay") || aparser.contains("nogui")
-              || aparser.contains("headless"))
+              || aparser.contains("headless")
+              || GraphicsEnvironment.isHeadless())
+      {
+        if (!isJS) {
+          // BH Definitely not a good idea in JavaScript; 
+          // probably should not be here for Java, either.  
+          System.setProperty("java.awt.headless", "true");
+        }
+        headless = true;
+      }
+      if (GraphicsEnvironment.isHeadless())
       {
-        System.setProperty("java.awt.headless", "true");
         headless = true;
       }
       // <<?
@@ -372,11 +382,6 @@ public class Jalview implements ApplicationSingletonI
       }
       defs = aparser.getValue("setprop");
     }
-    if (System.getProperty("java.awt.headless") != null
-            && System.getProperty("java.awt.headless").equals("true"))
-    {
-      headless = true;
-    }
     System.setProperty("http.agent",
             "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
     try
@@ -976,8 +981,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)
@@ -1031,29 +1035,52 @@ public class Jalview implements ApplicationSingletonI
         System.out.println(
                 "Creating image map: " + imageFile.getAbsolutePath());
         continue;
-      }
-      if (!Platform.isJS()) /** @j2sIgnore */
-      {
-        // skipping outputFormat?
-        System.out.println("Unknown arg: " + outputFormat);      
-        fname = new File(aparser.nextValue()).getAbsolutePath();
-        af.saveAlignment(fname, format);
-        if (af.isSaveAlignmentSuccessful())
+      default:
+        // fall through - try to parse as an alignment data export format
+        FileFormatI outFormat = null;
+        try
+        {
+          outFormat = FileFormats.getInstance().forName(outputFormat);
+        } catch (Exception formatP)
+        {
+        }
+        if (outFormat == null)
+        {
+          System.out.println("Couldn't parse " + outputFormat
+                  + " as a valid Jalview format string.");
+          continue;
+        }
+        if (!outFormat.isWritable())
         {
           System.out.println(
-                  "Written alignment in " + format + " format to " + fname);
+                  "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("Written alignment in " + outputFormat
+                  + " format to " + file);
+          continue;
         }
         else
         {
-          System.out.println("Error writing file " + fname + " in " + format
-                  + " format!!");
+          System.out.println("Error writing file " + file + " in "
+                  + outputFormat + " format!!");
         }
       }
-      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());
     }
   }