JAL-3446 CommandLineOperation test
[jalview.git] / src / jalview / gui / Desktop.java
index a1d9a09..d4f479a 100644 (file)
@@ -530,41 +530,40 @@ public class Desktop extends GDesktop
                     }
                   });
         }
+      }
+      this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
 
-        this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
-
-        this.addWindowListener(new WindowAdapter()
+      this.addWindowListener(new WindowAdapter()
+      {
+        @Override
+        public void windowClosing(WindowEvent evt)
         {
-          @Override
-          public void windowClosing(WindowEvent evt)
-          {
-            quit();
-          }
-        });
+          quit();
+        }
+      });
 
-        MouseAdapter ma;
-        this.addMouseListener(ma = new MouseAdapter()
+      MouseAdapter ma;
+      this.addMouseListener(ma = new MouseAdapter()
+      {
+        @Override
+        public void mousePressed(MouseEvent evt)
         {
-          @Override
-          public void mousePressed(MouseEvent evt)
+          if (evt.isPopupTrigger()) // Mac
           {
-            if (evt.isPopupTrigger()) // Mac
-            {
-              showPasteMenu(evt.getX(), evt.getY());
-            }
+            showPasteMenu(evt.getX(), evt.getY());
           }
+        }
 
-          @Override
-          public void mouseReleased(MouseEvent evt)
+        @Override
+        public void mouseReleased(MouseEvent evt)
+        {
+          if (evt.isPopupTrigger()) // Windows
           {
-            if (evt.isPopupTrigger()) // Windows
-            {
-              showPasteMenu(evt.getX(), evt.getY());
-            }
+            showPasteMenu(evt.getX(), evt.getY());
           }
-        });
-        desktopPane.addMouseListener(ma);
-      }
+        }
+      });
+      desktopPane.addMouseListener(ma);
     } catch (Throwable t)
     {
       t.printStackTrace();
@@ -842,7 +841,13 @@ 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,
+    
+    setFrame(frame, title, w, h);
+
+    // Headless operation has no Desktop instance, only the static class.
+
+    if (getInstance() != null)
+      getInstance().addFrame(frame, Desktop.FRAME_MAKE_VISIBLE,
             FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300);
   }
 
@@ -871,7 +876,10 @@ public class Desktop extends GDesktop
           int w, int h, boolean resizable, boolean ignoreMinSize)
   {
     // 15 classes
-    getInstance().addFrame(frame, title, makeVisible, w, h, resizable,
+    setFrame(frame, title, w, h);
+
+    if (getInstance() != null)
+      getInstance().addFrame(frame, makeVisible, resizable,
             ignoreMinSize);
   }
 
@@ -889,9 +897,8 @@ public class Desktop extends GDesktop
 
   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,
-          boolean ignoreMinSize)
+  private static void setFrame(JInternalFrame frame, String title,
+          int w, int h)
   {
     // TODO: allow callers to determine X and Y position of frame (eg. via
     // bounds object).
@@ -903,14 +910,12 @@ public class Desktop extends GDesktop
     {
       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;
-    }
+  }
+  
+  private void addFrame(JInternalFrame frame,
+          boolean makeVisible, boolean resizable,
+          boolean ignoreMinSize)
+  {
 
     openFrameCount++;
     
@@ -952,7 +957,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
@@ -1054,7 +1059,7 @@ public class Desktop extends GDesktop
     KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
             InputEvent.CTRL_DOWN_MASK);
     KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
-            ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx());
+            Platform.SHORTCUT_KEY_MASK);
 
     InputMap inputMap = frame
             .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
@@ -2506,12 +2511,10 @@ public class Desktop extends GDesktop
    */
   protected void addQuitHandler()
   {
-    getRootPane()
-            .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
-                    KeyStroke
-                            .getKeyStroke(KeyEvent.VK_Q,
-                                    jalview.util.ShortcutKeyMaskExWrapper
-                                            .getMenuShortcutKeyMaskEx()),
+
+    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
+            .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
+                    Platform.SHORTCUT_KEY_MASK),
                     "Quit");
     getRootPane().getActionMap().put("Quit", new AbstractAction()
     {