JAL-3253 preliminary static fixes for JavaScript part 4 of 3
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Thu, 9 May 2019 13:32:00 +0000 (08:32 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Thu, 9 May 2019 13:32:00 +0000 (08:32 -0500)
working on getting TestNG working with singletons

src/jalview/bin/Cache.java
src/jalview/bin/Jalview.java
src/jalview/gui/Desktop.java

index d7542b8..09f8de7 100755 (executable)
@@ -210,8 +210,6 @@ import org.apache.log4j.SimpleLayout;
 public class Cache
 {
 
 public class Cache
 {
 
-  static Cache instance;
-
   /**
    * In Java, this will be a static field instance, which will be
    * application-specific; in JavaScript it will be an applet-specific instance
   /**
    * In Java, this will be a static field instance, which will be
    * application-specific; in JavaScript it will be an applet-specific instance
index 9e3382a..9da666b 100755 (executable)
@@ -106,6 +106,12 @@ import groovy.util.GroovyScriptEngine;
  */
 public class Jalview
 {
  */
 public class Jalview
 {
+
+  public Jalview()
+  {
+    setInstance(this);
+  }
+
   static
   {
     Platform.getURLCommandArguments();
   static
   {
     Platform.getURLCommandArguments();
@@ -126,6 +132,10 @@ public class Jalview
 
   public static Jalview getInstance()
   {
 
   public static Jalview getInstance()
   {
+    if (instance == null)
+    {
+      instance = new Jalview();
+    }
     Jalview j;
     @SuppressWarnings("unused")
     ThreadGroup g = Thread.currentThread().getThreadGroup();
     Jalview j;
     @SuppressWarnings("unused")
     ThreadGroup g = Thread.currentThread().getThreadGroup();
@@ -260,7 +270,7 @@ public class Jalview
   public static void main(String[] args)
   {
     // setLogging(); // BH - for event debugging in JavaScript
   public static void main(String[] args)
   {
     // setLogging(); // BH - for event debugging in JavaScript
-    setInstance(new Jalview());
+    new Jalview();
     getInstance().doMain(args);
   }
 
     getInstance().doMain(args);
   }
 
index 88835c6..38cdf35 100644 (file)
@@ -198,6 +198,10 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   public static Desktop getInstance()
   {
 
   public static Desktop getInstance()
   {
+    if (instance == null)
+    {
+      new Desktop(true);
+    }
     Desktop d;
     @SuppressWarnings("unused")
     ThreadGroup g = Thread.currentThread().getThreadGroup();
     Desktop d;
     @SuppressWarnings("unused")
     ThreadGroup g = Thread.currentThread().getThreadGroup();
@@ -250,6 +254,8 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   public JInternalFrame conservationSlider, PIDSlider;
 
 
   public JInternalFrame conservationSlider, PIDSlider;
 
+  private boolean instanceOnly;
+
   class MyDesktopManager implements DesktopManager
   {
 
   class MyDesktopManager implements DesktopManager
   {
 
@@ -373,12 +379,16 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   }
 
 
   }
 
+  public Desktop(boolean forInstance)
+  {
+    instanceOnly = true;
+    setInstance(this);
+  }
   /**
    * Creates a new Desktop object.
    */
   public Desktop()
   {
   /**
    * Creates a new Desktop object.
    */
   public Desktop()
   {
-    super();
     /**
      * A note to implementors. It is ESSENTIAL that any activities that might
      * block are spawned off as threads rather than waited for during this
     /**
      * A note to implementors. It is ESSENTIAL that any activities that might
      * block are spawned off as threads rather than waited for during this
@@ -892,7 +902,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
     // IF JALVIEW IS RUNNING HEADLESS
     // ///////////////////////////////////////////////
     // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
     // IF JALVIEW IS RUNNING HEADLESS
     // ///////////////////////////////////////////////
-    if (getInstance() == null || Jalview.isHeadlessMode())
+    if (getInstance().instanceOnly || Jalview.isHeadlessMode())
     {
       return;
     }
     {
       return;
     }
@@ -3276,7 +3286,7 @@ public class Desktop extends jalview.jbgui.GDesktop
           }
           ;
         }
           }
           ;
         }
-        if (getInstance() == null)
+        if (instanceOnly)
         {
           return;
         }
         {
           return;
         }