Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / src / jalview / util / Platform.java
index bc21fa1..daaab3a 100644 (file)
@@ -76,8 +76,6 @@ public class Platform
   private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null,
           isWin = null;
 
-  private static Boolean isHeadless = null;
-
   private static swingjs.api.JSUtilI jsutil;
 
   static
@@ -97,7 +95,6 @@ public class Platform
       }
     }
   }
-  // private static Boolean isHeadless = null;
 
   /**
    * added to group mouse events into Windows and nonWindows (mac, unix, linux)
@@ -111,10 +108,14 @@ public class Platform
             : isMac);
   }
 
-  public static int SHORTCUT_KEY_MASK = (Platform.isMac() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK);
+  public static int SHORTCUT_KEY_MASK = (Platform.isMac()
+          ? KeyEvent.META_DOWN_MASK
+          : KeyEvent.CTRL_DOWN_MASK);
+
   static
   {
+    if (!GraphicsEnvironment.isHeadless())
+    {
       // Using non-deprecated Extended key mask modifiers, but Java 8 has no
       // getMenuShortcutKeyMaskEx method
       Toolkit tk = Toolkit.getDefaultToolkit();
@@ -122,7 +123,7 @@ public class Platform
       try
       {
         method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx");
-      } catch (NoSuchMethodException e)
+      } catch (Exception e)
       {
         System.err.println(
                 "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask.");
@@ -132,7 +133,7 @@ public class Platform
         try
         {
           method = tk.getClass().getMethod("getMenuShortcutKeyMask");
-        } catch (NoSuchMethodException e)
+        } catch (Exception e)
         {
           System.err.println(
                   "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask.");
@@ -157,7 +158,6 @@ public class Platform
       }
     }
   }
-
   /**
    * added to group mouse events into Windows and nonWindows (mac, unix, linux)
    * 
@@ -192,7 +192,7 @@ public class Platform
   }
 
   /**
-   * Check if we are on a Microsoft plaform...
+   * Check if we are on a Microsoft platform...
    * 
    * @return true if we have to cope with another platform variation
    */
@@ -201,18 +201,6 @@ public class Platform
     return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin);
   }
 
-  /**
-   *
-   * @return true if we are running in non-interactive no UI mode
-   */
-  public static boolean isHeadless()
-  {
-    if (isHeadless == null)
-    {
-      isHeadless = "true".equals(System.getProperty("java.awt.headless"));
-    }
-    return isHeadless;
-  }
 
   /**
    * 
@@ -259,12 +247,13 @@ public class Platform
    */
   protected static boolean isControlDown(MouseEvent e, boolean aMac)
   {
-//
-//    System.out.println(e.isPopupTrigger() 
-//            + " " + ((SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0) 
-//            + " " + e.isControlDown());
-    return (aMac ? !e.isPopupTrigger()
-            && (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0
+    //
+    // System.out.println(e.isPopupTrigger()
+    // + " " + ((SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0)
+    // + " " + e.isControlDown());
+    return (aMac
+            ? !e.isPopupTrigger()
+                    && (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0
             : e.isControlDown());
   }
 
@@ -674,20 +663,22 @@ public class Platform
   public static void getURLCommandArguments()
   {
 
-    try {
-    /**
-     * Retrieve the first query field as command arguments to Jalview. Include
-     * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's __Info.args
-     * element to this value.
-     * 
-     * @j2sNative var a =
-     *            decodeURI((document.location.href.replace("&","?").split("?j2s")[0]
-     *            + "?").split("?")[1].split("#")[0]); a &&
-     *            (J2S.thisApplet.__Info.args = a.split(" "));
-     *            
-     *            System.out.println("URL arguments: " + a);
-     */
-    } catch (Throwable t) {
+    try
+    {
+      /**
+       * Retrieve the first query field as command arguments to Jalview. Include
+       * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's
+       * __Info.args element to this value.
+       * 
+       * @j2sNative var a =
+       *            decodeURI((document.location.href.replace("&","?").split("?j2s")[0]
+       *            + "?").split("?")[1].split("#")[0]); a &&
+       *            (J2S.thisApplet.__Info.args = a.split(" "));
+       * 
+       *            System.out.println("URL arguments: " + a);
+       */
+    } catch (Throwable t)
+    {
     }
   }
 
@@ -851,7 +842,8 @@ public class Platform
    * 
    * @param frame
    *          a JFrame or JInternalFrame
-   * @param type "name", "node", "init", "dim", or any DOM attribute, such as "id"
+   * @param type
+   *          "name", "node", "init", "dim", or any DOM attribute, such as "id"
    * @return null if frame is not embedded.
    */
   public static Object getEmbeddedAttribute(Component frame, String type)
@@ -967,17 +959,17 @@ public class Platform
    */
   public static String getAppID(String frameType)
   {
-    
+
     String id = Jalview.getInstance().j2sAppletID;
     if (id == null)
     {
-      Jalview.getInstance().j2sAppletID = id = (isJS ? (String) jsutil
-              .getAppletAttribute("_id") : "jalview");
+      Jalview.getInstance().j2sAppletID = id = (isJS
+              ? (String) jsutil.getAppletAttribute("_id")
+              : "jalview");
     }
     return id + (frameType == null ? "" : "-" + frameType);
   }
 
-
   /**
    * Option to avoid unnecessary seeking of nonexistent resources in JavaScript.
    * Works in Java as well.