Merge branch 'Jalview-JS/develop' of https://source.jalview.org/git/jalview.git into...
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 16 Jun 2020 12:00:49 +0000 (13:00 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 16 Jun 2020 12:00:49 +0000 (13:00 +0100)
src/jalview/gui/Desktop.java
src/jalview/util/Platform.java

index a13a38b..2f76eba 100644 (file)
@@ -121,7 +121,6 @@ import jalview.util.BrowserLauncher;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.util.ShortcutKeyMaskExWrapper;
 import jalview.util.UrlConstants;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.ParamManager;
@@ -841,7 +840,8 @@ public class Desktop extends GDesktop
           final JInternalFrame frame, String title, int w, int h)
   {
     // 58 classes
-    getInstance().addFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h,
+    
+    addInternalFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h, 
             FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300);
   }
 
@@ -869,8 +869,20 @@ public class Desktop extends GDesktop
           final JInternalFrame frame, String title, boolean makeVisible,
           int w, int h, boolean resizable, boolean ignoreMinSize)
   {
-    // 15 classes
-    getInstance().addFrame(frame, title, makeVisible, w, h, resizable,
+    // 15 classes call this method directly.
+    
+    // TODO: allow callers to determine X and Y position of frame (eg. via
+    // bounds object).
+    // TODO: consider fixing method to update entries in the window submenu with
+    // the current window title
+
+    frame.setTitle(title);
+    if (frame.getWidth() < 1 || frame.getHeight() < 1)
+    {
+      frame.setSize(w, h);
+    }
+    if (getInstance() != null)
+      getInstance().addFrame(frame, makeVisible, resizable,
             ignoreMinSize);
   }
 
@@ -887,29 +899,11 @@ public class Desktop extends GDesktop
   public final static boolean FRAME_ALLOW_ANY_SIZE = true;
 
   public final static boolean FRAME_SET_MIN_SIZE_300 = false;
-
-  private void addFrame(JInternalFrame frame, String title,
-          boolean makeVisible, int w, int h, boolean resizable,
+  
+  private void addFrame(JInternalFrame frame,
+          boolean makeVisible, boolean resizable,
           boolean ignoreMinSize)
   {
-    // TODO: allow callers to determine X and Y position of frame (eg. via
-    // bounds object).
-    // TODO: consider fixing method to update entries in the window submenu with
-    // the current window title
-
-    frame.setTitle(title);
-    if (frame.getWidth() < 1 || frame.getHeight() < 1)
-    {
-      frame.setSize(w, h);
-    }
-    // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
-    // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
-    // IF JALVIEW IS RUNNING HEADLESS
-    // ///////////////////////////////////////////////
-    if (Jalview.isHeadlessMode())
-    {
-      return;
-    }
 
     openFrameCount++;
     
@@ -951,7 +945,7 @@ public class Desktop extends GDesktop
      * add an entry for the new frame in the Window menu 
      * (and remove it when the frame is closed)
      */
-    final JMenuItem menuItem = new JMenuItem(title);
+    final JMenuItem menuItem = new JMenuItem(frame.getTitle());
     frame.addInternalFrameListener(new InternalFrameAdapter()
     {
       @Override
index ac84846..c068acc 100644 (file)
@@ -22,6 +22,7 @@ package jalview.util;
 
 import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.GraphicsEnvironment;
 import java.awt.Toolkit;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
@@ -75,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
@@ -96,7 +95,6 @@ public class Platform
       }
     }
   }
-  // private static Boolean isHeadless = null;
 
   /**
    * added to group mouse events into Windows and nonWindows (mac, unix, linux)
@@ -116,48 +114,50 @@ public class Platform
 
   static
   {
-    // Using non-deprecated Extended key mask modifiers, but Java 8 has no
-    // getMenuShortcutKeyMaskEx method
-    Toolkit tk = Toolkit.getDefaultToolkit();
-    Method method = null;
-    try
-    {
-      method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx");
-    } catch (NoSuchMethodException e)
-    {
-      System.err.println(
-              "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask.");
-    }
-    if (method == null)
+    if (!GraphicsEnvironment.isHeadless())
     {
+      // Using non-deprecated Extended key mask modifiers, but Java 8 has no
+      // getMenuShortcutKeyMaskEx method
+      Toolkit tk = Toolkit.getDefaultToolkit();
+      Method method = null;
       try
       {
-        method = tk.getClass().getMethod("getMenuShortcutKeyMask");
-      } catch (NoSuchMethodException e)
+        method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx");
+      } catch (Exception e)
       {
         System.err.println(
-                "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask.");
-        e.printStackTrace();
+                "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask.");
       }
-    }
-    if (method != null)
-    {
-      try
+      if (method == null)
       {
-        method.setAccessible(true);
-        SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0]));
-      } catch (Exception e)
+        try
+        {
+          method = tk.getClass().getMethod("getMenuShortcutKeyMask");
+        } catch (Exception e)
+        {
+          System.err.println(
+                  "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask.");
+          e.printStackTrace();
+        }
+      }
+      if (method != null)
       {
-        e.printStackTrace();
+        try
+        {
+          method.setAccessible(true);
+          SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0]));
+        } catch (Exception e)
+        {
+          e.printStackTrace();
+        }
+      }
+      if (SHORTCUT_KEY_MASK <= 0xF)
+      {
+        // shift this into the extended region (was Java 8)
+        SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6;
       }
-    }
-    if (SHORTCUT_KEY_MASK <= 0xF)
-    {
-      // shift this into the extended region (was Java 8)
-      SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6;
     }
   }
-
   /**
    * added to group mouse events into Windows and nonWindows (mac, unix, linux)
    * 
@@ -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;
-  }
 
   /**
    *