JAL-1759 merge from develop
[jalview.git] / src / jalview / bin / Jalview.java
index 5bb5e98..f6d0099 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.bin;
 
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
+import jalview.io.BioJsHTMLOutput;
 import jalview.io.HtmlSvgOutput;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -45,7 +46,7 @@ import java.security.CodeSource;
 import java.security.PermissionCollection;
 import java.security.Permissions;
 import java.security.Policy;
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
 
@@ -93,23 +94,6 @@ public class Jalview
     System.out.println(System.getProperty("os.arch") + " "
             + System.getProperty("os.name") + " "
             + System.getProperty("os.version"));
-    // if (new Platform().isAMac())
-    // {
-    // // System.setProperty("com.apple.mrj.application.apple.menu.about.name",
-    // // "Jalview");
-    // // System.setProperty("apple.laf.useScreenMenuBar", "true");
-    // try
-    // {
-    // UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
-    // .getLookAndFeel());
-    // System.out
-    // .println("--------------------------------------------> in here");
-    // } catch (UnsupportedLookAndFeelException e)
-    // {
-    // // TODO Auto-generated catch block
-    // e.printStackTrace();
-    // }
-    // }
 
     ArgsParser aparser = new ArgsParser(args);
     boolean headless = false;
@@ -241,8 +225,13 @@ public class Jalview
       desktop.checkForNews();
     }
 
+    if (!isHeadlessMode())
+    {
+      BioJsHTMLOutput.updateBioJS();
+    }
+
     String file = null, protocol = null, format = null, data = null;
-    jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
+    jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(!headless);
     Vector getFeatures = null; // vector of das source nicknames to fetch
     // features from
     // loading is done.
@@ -532,8 +521,10 @@ public class Jalview
           }
           else if (format.equalsIgnoreCase("eps"))
           {
-            System.out.println("Creating EPS file: " + file);
-            af.createEPS(new java.io.File(file));
+            File outputFile = new java.io.File(file);
+            System.out.println("Creating EPS file: "
+                    + outputFile.getAbsolutePath());
+            af.createEPS(outputFile);
             continue;
           }
 
@@ -820,7 +811,7 @@ public class Jalview
        * = new Binding(); binding.setVariable("input", "world");
        * gse.run("hello.groovy", binding); </code>
        */
-      Class[] bspec;
+      Class<?>[] bspec;
       Object[] binding;
       int blen = ((jalviewContext[0] == null) ? 0 : 1)
               + ((jalviewContext[1] == null) ? 0 : 1);
@@ -830,7 +821,7 @@ public class Jalview
       binding = new Object[blen * 2];
       blen = 0;
       ClassLoader cl = null;
-      Map vbinding = new Hashtable();
+      Map<String, Object> vbinding = new HashMap<String, Object>();
       for (int jc = 0; jc < jalviewContext.length; jc++)
       {
         if (jalviewContext[jc] != null)
@@ -847,8 +838,8 @@ public class Jalview
           blen++;
         }
       }
-      Class gbindingc = cl.loadClass("groovy.lang.Binding");
-      Constructor gbcons;
+      Class<?> gbindingc = cl.loadClass("groovy.lang.Binding");
+      Constructor<?> gbcons;
       Object gbinding;
       try
       {
@@ -858,15 +849,15 @@ public class Jalview
       {
         // old style binding config - using series of string/object values to
         // setVariable.
-        gbcons = gbindingc.getConstructor(null);
-        gbinding = gbcons.newInstance(null);
+        gbcons = gbindingc.getConstructor();
+        gbinding = gbcons.newInstance();
         java.lang.reflect.Method setvar = gbindingc.getMethod(
                 "setVariable", bspec);
         setvar.invoke(gbinding, binding);
       }
-      ;
-      Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
-      Constructor gseccons = gsec.getConstructor(new Class[]
+
+      Class<?> gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
+      Constructor<?> gseccons = gsec.getConstructor(new Class[]
       { URL[].class }); // String[].class });
       Object gse = gseccons.newInstance(new Object[]
       { new URL[]
@@ -966,7 +957,7 @@ public class Jalview
   private static FeatureFetcher startFeatureFetching(final Vector dasSources)
   {
     FeatureFetcher ff = new FeatureFetcher();
-    AlignFrame afs[] = Desktop.getAlignframes();
+    AlignFrame afs[] = Desktop.getAlignFrames();
     if (afs == null || afs.length == 0)
     {
       return null;
@@ -977,6 +968,16 @@ public class Jalview
     }
     return ff;
   }
+
+  public static boolean isHeadlessMode()
+  {
+    String isheadless = System.getProperty("java.awt.headless");
+    if (isheadless != null && isheadless.equalsIgnoreCase("true"))
+    {
+      return true;
+    }
+    return false;
+  }
 }
 
 /**
@@ -1145,4 +1146,4 @@ class FeatureFetcher
     return queued == 0 && running == 0;
   }
 
-};
+}