isAMac() -> isAMacAndNotJS(), isWindows() -> isWindowsAndNotJS()
[jalview.git] / src / jalview / bin / Jalview.java
index 0d7143d..474c707 100755 (executable)
@@ -41,6 +41,8 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -60,8 +62,12 @@ import java.security.Policy;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.swing.LookAndFeel;
+import javax.swing.Timer;
 import javax.swing.UIManager;
 
 import groovy.lang.Binding;
@@ -70,7 +76,14 @@ import groovy.util.GroovyScriptEngine;
 /**
  * Main class for Jalview Application <br>
  * <br>
- * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
+ * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
+ * jalview.bin.Jalview
+ * 
+ * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
+ * jalview.bin.Jalview jalview.bin.Jalview
+ * 
+ * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
+ * embellish '*' to e.g. '*.jar')
  * 
  * @author $author$
  * @version $Revision$
@@ -89,13 +102,21 @@ public class Jalview
 
   public static AlignFrame currentAlignFrame;
 
-  public static boolean isJS = /** @j2sNative true || */ // BH 2018
-          false;
+  /**
+   * Answers true if Jalview is running as Javascript, else false. The value is
+   * set at compile time.
+   * 
+   * @return
+   */
+  public static boolean isJS()
+  {
+    return /** @j2sNative true || */
+    false;
+  }
 
   static
   {
-
-    if (!isJS)
+    if (!isJS())
     { // BH 2018
     // grab all the rights we can the JVM
     Policy.setPolicy(new Policy()
@@ -160,7 +181,6 @@ public class Jalview
           af.setProgressBar(MessageManager
                   .getString("status.das_features_being_retrived"), id);
           af.featureSettings_actionPerformed(null);
-          af.featureSettings.fetchDasFeatures(dasSources, true);
           af.setProgressBar(null, id);
           synchronized (us)
           {
@@ -190,17 +210,47 @@ public class Jalview
    */
   public static void main(String[] args)
   {
+//     setLogging(); // BH - for event debugging in JavaScript
     instance = new Jalview();
     instance.doMain(args);
+}
+
+  private static void logClass(String name) 
+  {    
+         // BH - for event debugging in JavaScript
+      ConsoleHandler consoleHandler = new ConsoleHandler();
+      consoleHandler.setLevel(Level.ALL);
+      Logger logger = Logger.getLogger(name);
+      logger.setLevel(Level.ALL);
+      logger.addHandler(consoleHandler);
   }
 
+  @SuppressWarnings("unused")
+  private static void setLogging() 
+  {
+         // BH - for event debugging in JavaScript (Java mode only)
+       if (!(/** @j2sNative true ||*/false)) 
+       {
+               Logger.getLogger("").setLevel(Level.ALL);
+        logClass("java.awt.EventDispatchThread");
+        logClass("java.awt.EventQueue");
+        logClass("java.awt.Component");
+        logClass("java.awt.focus.Component");
+        logClass("java.awt.focus.DefaultKeyboardFocusManager"); 
+       }       
+
+  }
+  
+
+  
+
   /**
    * @param args
    */
   void doMain(String[] args)
   {
 
-    if (!isJS)
+    if (!isJS())
     {
       System.setSecurityManager(null);
     }
@@ -288,7 +338,7 @@ public class Jalview
     {
       error.printStackTrace();
       System.out.println("\nEssential logging libraries not found."
-              + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
+              + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
       System.exit(0);
     }
 
@@ -302,7 +352,7 @@ public class Jalview
       System.err.println("Unexpected Look and Feel Exception");
       ex.printStackTrace();
     }
-    if (Platform.isAMac())
+    if (Platform.isAMacAndNotJS())
     {
 
       LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
@@ -350,7 +400,16 @@ public class Jalview
 
     if (!headless)
     {
-      desktop = new Desktop();
+      desktop = new Desktop() 
+//      {
+// // BH testing
+//       @Override
+//       protected void processEvent(AWTEvent e) {
+//               System.out.println("Jalview.java " + e);
+//               super.processEvent(e);
+//       }
+//       }
+      ;
       desktop.setInBatchMode(true); // indicate we are starting up
       desktop.setVisible(true);
 
@@ -531,7 +590,7 @@ public class Jalview
       }
       System.out.println("CMD [-open " + file + "] executed successfully!");
 
-      if (!isJS && !file.startsWith("http://"))
+      if (!isJS() && !file.startsWith("http://"))
       {
         if (!(new File(file)).exists())
         {
@@ -750,7 +809,8 @@ public class Jalview
             continue;
           }
 
-          if (af.saveAlignment(file, format))
+          af.saveAlignment(file, format);
+          if (af.isSaveAlignmentSuccessful())
           {
             System.out.println("Written alignment in " + format
                     + " format to " + file);