JAL-3563 adds Jalview.setSynchronous()
[jalview.git] / src / jalview / bin / Jalview.java
index ff8d52f..13ac248 100755 (executable)
@@ -86,6 +86,7 @@ import java.util.Map;
 import java.util.Vector;
 
 import javax.swing.LookAndFeel;
+import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 
 import groovy.lang.Binding;
@@ -148,6 +149,8 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
 
   private boolean noAnnotation;
 
+  public static final String TERMINATOR_LINE = "Jalview argument parsing complete.";
+
   public boolean getStartCalculations()
   {
     return !noCalculation;
@@ -312,6 +315,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
             || "true".equals(System.getProperty("java.awt.headless")))
     {
       headless = true;
+      setSynchronous(true);
     }
 
     if (isJS)
@@ -346,7 +350,6 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
         System.exit(0);
       }
 
-
       // anything else!
 
       final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
@@ -402,11 +405,11 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     try
     {
       if (!isJS && Platform.isWin())
-       {
+      {
         UIManager.setLookAndFeel(
                 headless ? "javax.swing.plaf.metal.MetalLookAndFeel"
                         : UIManager.getSystemLookAndFeelClassName());
-//      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
       }
     } catch (Exception ex)
     {
@@ -460,7 +463,21 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
       SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
     }
 
-    if (!headless)
+    if (headless)
+    {
+      // If this is not tested, then
+
+      if (aparser.contains(ArgsParser.NOUSAGESTATS))
+      {
+        System.err.println("CMD [-nousagestats] executed successfully!");
+      }
+      if (aparser.contains(ArgsParser.NOQUESTIONNAIRE))
+      {
+        System.err.println("CMD [-noquestionnaire] executed successfully!");
+      }
+
+    }
+    else
     {
       desktop = Desktop.getInstance();
       desktop.setInBatchMode(true); // indicate we are starting up
@@ -527,6 +544,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     }
 
     parseArguments(aparser, true);
+    System.err.println(TERMINATOR_LINE);
   }
 
   /**
@@ -2170,5 +2188,84 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     // + " " + status);
   }
 
-}
+  /**
+   * flag to allow selected Runnable and Thread processes to run synchronously
+   * 
+   * JAL-3563
+   * 
+   */
+  private static boolean isSynchronous = false;
+
+  /**
+   * Set Jalview to run selected processes synchronously in test and headless
+   * environments.
+   * 
+   * JAL-3563
+   * 
+   * @param b
+   * @author Bob Hanson
+   */
+  public static void setSynchronous(boolean b)
+  {
+
+    isSynchronous = b;
+
+  }
+
+  /**
+   * Allows optional synchronous running of a Runnable that would otherwise use
+   * SwingUtilities.invokeLater.
+   * 
+   * JAL-3563
+   * 
+   * @param t
+   * @author Bob Hanson
+   */
+  public static boolean isSynchronous()
+  {
+    return isSynchronous;
+  }
+
+  /**
+   * Allows optional synchronous running of a Runnable that would otherwise use
+   * SwingUtilities.invokeLater.
+   * 
+   * JAL-3563
+   * 
+   * @param t
+   * @author Bob Hanson
+   */
+  public static void execRunnable(Runnable r)
+  {
+    if (isSynchronous())
+    {
+      r.run();
+    }
+    else
+    {
+      SwingUtilities.invokeLater(r);
+    }
+  }
+
+  /**
+   * Allows optional synchronous running of a thread that would otherwise be run
+   * using start().
+   * 
+   * JAL-3563
+   * 
+   * @param t
+   * @author Bob Hanson
+   */
+  public static void execThread(Thread t)
+  {
+    if (isSynchronous())
+    {
+      t.run();
+    }
+    else
+    {
+      t.start();
+    }
+  }
 
+}
\ No newline at end of file