JAL-3253 temporary branch SwingJS upgrade with testNG fixes Java 8
[jalview.git] / src / jalview / gui / Desktop.java
index 4eff90a..e13a63e 100644 (file)
@@ -227,23 +227,6 @@ public class Desktop extends GDesktop
 
   public JInternalFrame PIDSlider;
 
-  /**
-   * just an instance (for testng, probably); no actual frames
-   * 
-   * This flag, when set true, allows a headless-like operation, with a Desktop
-   * object but no actual frames. The issue has to do with the mess-up of the
-   * Windows JInternalFrame implementation, which surreptitiously and
-   * unforgivingly accesses a native peer class, preventing headless operation.
-   * 
-   * It is set by invoking the Desktop(true) constructor.
-   * 
-   * It is possible that we can remove this option now, since headless mode is
-   * finally working on Windows through careful attention to not creating any
-   * JInternalFrame objects when in that mode.
-   * 
-   */
-  private boolean instanceOnly;
-
   class MyDesktopManager implements DesktopManager
   {
 
@@ -382,28 +365,11 @@ public class Desktop extends GDesktop
             : (Desktop) ApplicationSingletonProvider
                     .getInstance(Desktop.class);
   }
-
-  /**
-   * For testing purposes, this constructor can be utilized to allow the creation 
-   * of a singleton Desktop instance without the formation of frames. The Cache is 
-   * initialized, but that is all. 
-   * 
-   * It is not currently used. 
-   * 
-   * @param forInstance
-   */
-  public Desktop(boolean forInstance)
-  {
-
-    Cache.initLogger();
-    instanceOnly = true;
-  }
   
   /**
    * Private constructor enforces singleton pattern. It is called by reflection
    * from ApplicationSingletonProvider.getInstance().
    */
-  @SuppressWarnings("unused")
   private Desktop()
   {
     Cache.initLogger();
@@ -475,7 +441,7 @@ public class Desktop extends GDesktop
       // it deletes the unneeded Java-only code form the JavaScript version
       // completely (@j2sIgnore), since it will never be used there.
 
-      if (!Platform.isJS())
+      if (!Platform.isJS() && !Jalview.isSynchronous())
       /**
        * Java only
        * 
@@ -550,39 +516,42 @@ public class Desktop extends GDesktop
 
       }
 
-      this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
-
-      this.addWindowListener(new WindowAdapter()
+      if (!Jalview.isSynchronous())
       {
-        @Override
-        public void windowClosing(WindowEvent evt)
-        {
-          quit();
-        }
-      });
+        this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
 
-      MouseAdapter ma;
-      this.addMouseListener(ma = new MouseAdapter()
-      {
-        @Override
-        public void mousePressed(MouseEvent evt)
+        this.addWindowListener(new WindowAdapter()
         {
-          if (evt.isPopupTrigger()) // Mac
+          @Override
+          public void windowClosing(WindowEvent evt)
           {
-            showPasteMenu(evt.getX(), evt.getY());
+            quit();
           }
-        }
+        });
 
-        @Override
-        public void mouseReleased(MouseEvent evt)
+        MouseAdapter ma;
+        this.addMouseListener(ma = new MouseAdapter()
         {
-          if (evt.isPopupTrigger()) // Windows
+          @Override
+          public void mousePressed(MouseEvent evt)
           {
-            showPasteMenu(evt.getX(), evt.getY());
+            if (evt.isPopupTrigger()) // Mac
+            {
+              showPasteMenu(evt.getX(), evt.getY());
+            }
           }
-        }
-      });
-      desktopPane.addMouseListener(ma);
+
+          @Override
+          public void mouseReleased(MouseEvent evt)
+          {
+            if (evt.isPopupTrigger()) // Windows
+            {
+              showPasteMenu(evt.getX(), evt.getY());
+            }
+          }
+        });
+        desktopPane.addMouseListener(ma);
+      }
     } catch (Throwable t)
     {
       t.printStackTrace();
@@ -934,7 +903,7 @@ public class Desktop extends GDesktop
     // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
     // IF JALVIEW IS RUNNING HEADLESS
     // ///////////////////////////////////////////////
-    if (Jalview.isHeadlessMode() || Desktop.getInstance().instanceOnly)
+    if (Jalview.isHeadlessMode())
     {
       return;
     }
@@ -964,7 +933,8 @@ public class Desktop extends GDesktop
     frame.setIconifiable(resizable);
     frame.setOpaque(Platform.isJS());
 
-    if (frame.getX() < 1 && frame.getY() < 1)
+    boolean isEmbedded = (Platform.getDimIfEmbedded(frame, -1, -1) != null);
+    if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1)
     {
       frame.setLocation(xOffset * openFrameCount,
               yOffset * ((openFrameCount - 1) % 10) + yOffset);
@@ -1880,7 +1850,7 @@ public class Desktop extends GDesktop
           {
                try 
             {
-              new Jalview2XML().loadJalviewAlign(choice);
+              new Jalview2XML().loadJalviewAlign(selectedFile);
             } catch (OutOfMemoryError oom)
                {
                  new OOMWarning("Whilst loading project from " + choice, oom);
@@ -3316,7 +3286,7 @@ public class Desktop extends GDesktop
           {
           }
         }
-        if (instanceOnly)
+        if (Jalview.isHeadlessMode())
         {
           return;
         }