refer to local default setting for proxy when connecting to
[jalview.git] / src / jalview / bin / Jalview.java
index 2c68662..b83bdc0 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -36,7 +36,7 @@ import java.util.*;
 import javax.swing.*;
 
 import jalview.gui.*;
-import jalview.io.AppletFormatAdapter;
+import jalview.util.Platform;
 
 /**
  * Main class for Jalview Application <br>
@@ -79,6 +79,12 @@ 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");
+    }
 
     ArgsParser aparser = new ArgsParser(args);
     boolean headless = false;
@@ -89,6 +95,7 @@ public class Jalview
               .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
                       + "-nodisplay\tRun Jalview without User Interface.\n"
                       + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
+                      + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
                       + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
                       + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
                       + "-features FILE\tUse the given file to mark features on the alignment.\n"
@@ -165,20 +172,15 @@ public class Jalview
 
     try
     {
-      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()
-      // UIManager.getCrossPlatformLookAndFeelClassName()
-              // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
-              // "javax.swing.plaf.metal.MetalLookAndFeel"
-              // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
-              // "com.sun.java.swing.plaf.motif.MotifLookAndFeel"
-
-              );
+      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     } catch (Exception ex)
     {
     }
+
     if (!headless)
     {
       desktop = new Desktop();
+      desktop.setInBatchMode(true); // indicate we are starting up
       desktop.setVisible(true);
       desktop.startServiceDiscovery();
       if (!aparser.contains("nousagestats"))
@@ -246,7 +248,7 @@ public class Jalview
       {
         try
         {
-          String viprotocol = Jalview.checkProtocol(vamsasImport);
+          String viprotocol = jalview.io.AppletFormatAdapter.checkProtocol(vamsasImport);
           if (viprotocol == jalview.io.FormatAdapter.FILE)
           {
             inSession = desktop.vamsasImport(new File(vamsasImport));
@@ -331,7 +333,7 @@ public class Jalview
         }
       }
 
-      protocol = checkProtocol(file);
+      protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
 
       format = new jalview.io.IdentifyFile().Identify(file, protocol);
 
@@ -367,20 +369,20 @@ public class Jalview
       data = aparser.getValue("groups", true);
       if (data != null)
       {
-        af.parseFeaturesFile(data, checkProtocol(data));
+        af.parseFeaturesFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
         System.out.println("Added " + data);
       }
       data = aparser.getValue("features", true);
       if (data != null)
       {
-        af.parseFeaturesFile(data, checkProtocol(data));
+        af.parseFeaturesFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
         System.out.println("Added " + data);
       }
 
       data = aparser.getValue("annotations", true);
       if (data != null)
       {
-        af.loadJalviewDataFile(data);
+        af.loadJalviewDataFile(data, null, null, null);
         System.out.println("Added " + data);
       }
       // set or clear the sortbytree flag.
@@ -398,7 +400,7 @@ public class Jalview
         jalview.io.NewickFile fin = null;
         try
         {
-          fin = new jalview.io.NewickFile(data, checkProtocol(data));
+          fin = new jalview.io.NewickFile(data, jalview.io.AppletFormatAdapter.checkProtocol(data));
           if (fin != null)
           {
             af.getViewport().setCurrentTree(
@@ -411,7 +413,7 @@ public class Jalview
           ex.printStackTrace(System.err);
         }
       }
-      // todo - load PDB structure to alignment
+      // TODO - load PDB structure(s) to alignment JAL-629
       // (associate with identical sequence in alignment, or a specified
       // sequence)
 
@@ -440,7 +442,7 @@ public class Jalview
         if (jalview.bin.Cache.groovyJarsPresent())
         {
           System.out.println("Executing script " + groovyscript);
-          executeGroovyScript(groovyscript, desktop);
+          executeGroovyScript(groovyscript, new Object[] {desktop,af});
         }
         else
         {
@@ -502,7 +504,7 @@ public class Jalview
             && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
     {
       file = jalview.bin.Cache.getDefault("STARTUP_FILE",
-              "http://www.jalview.org/examples/exampleFile_2_3.jar");
+              jalview.bin.Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/examples/exampleFile_2_3.jar");
 
       protocol = "File";
 
@@ -536,13 +538,13 @@ public class Jalview
         startFeatureFetching(getFeatures);
       }
     }
-    // execute a groovy script.
+    // Once all other stuff is done, execute any groovy scripts (in order)
     if (groovyscript != null)
     {
       if (jalview.bin.Cache.groovyJarsPresent())
       {
         System.out.println("Executing script " + groovyscript);
-        executeGroovyScript(groovyscript, desktop);
+        executeGroovyScript(groovyscript, new Object[] { desktop, startUpAlframe});
       }
       else
       {
@@ -551,8 +553,11 @@ public class Jalview
                         + groovyscript);
       }
     }
-
-    // Once all other stuff is done, execute any groovy scripts (in order)
+    // and finally, turn off batch mode indicator - if the desktop still exists
+    if (desktop != null)
+    {
+      desktop.setInBatchMode(false);
+    }
   }
 
   private static void startUsageStats(final Desktop desktop)
@@ -596,7 +601,7 @@ public class Jalview
    *          'Jalview' object.
    */
   private static void executeGroovyScript(String groovyscript,
-          Object jalviewContext)
+          Object[] jalviewContext)
   {
     if (jalviewContext == null)
     {
@@ -665,15 +670,36 @@ public class Jalview
        * = new Binding(); binding.setVariable("input", "world");
        * gse.run("hello.groovy", binding); </code>
        */
-      ClassLoader cl = jalviewContext.getClass().getClassLoader();
+      Class[] bspec;
+      Object[] binding;
+      int blen=((jalviewContext[0]==null) ? 0 : 1) + ((jalviewContext[1]==null) ? 0 : 1);
+      String cnames[] = new String[] { "Jalview", "currentAlFrame"};
+      bspec=new Class[blen*2];
+      binding=new Object[blen*2];
+      blen=0;
+      ClassLoader cl=null;
+      for (int jc=0;jc<jalviewContext.length;jc++)
+      {
+       if (jalviewContext[jc]!=null) { 
+         if (cl==null)
+         {
+                 cl = jalviewContext[jc].getClass().getClassLoader();
+         }
+               bspec[blen*2] = String.class;
+         bspec[blen*2+1] = Object.class;
+         binding[blen*2]=cnames[jc];
+         binding[blen*2+1]=jalviewContext[jc];
+         blen++;
+        }
+      }
       Class gbindingc = cl.loadClass("groovy.lang.Binding");
       Constructor gbcons = gbindingc.getConstructor(null);
       Object gbinding = gbcons.newInstance(null);
+      
       java.lang.reflect.Method setvar = gbindingc.getMethod("setVariable",
-              new Class[]
-              { String.class, Object.class });
-      setvar.invoke(gbinding, new Object[]
-      { "Jalview", jalviewContext });
+              bspec);
+      
+      setvar.invoke(gbinding, binding);
       Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
       Constructor gseccons = gsec.getConstructor(new Class[]
       { URL[].class }); // String[].class });
@@ -786,17 +812,6 @@ public class Jalview
     }
     return ff;
   }
-
-  private static String checkProtocol(String file)
-  {
-    String protocol = jalview.io.FormatAdapter.FILE;
-
-    if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
-    {
-      protocol = jalview.io.FormatAdapter.URL;
-    }
-    return protocol;
-  }
 }
 
 /**