From 0eb1ca5fbc6e21ae91e8d80a1bfa2b95f2957bd3 Mon Sep 17 00:00:00 2001 From: hansonr Date: Thu, 9 May 2019 08:32:00 -0500 Subject: [PATCH] JAL-3253 preliminary static fixes for JavaScript part 4 of 3 working on getting TestNG working with singletons --- src/jalview/bin/Cache.java | 2 -- src/jalview/bin/Jalview.java | 12 +++++++++++- src/jalview/gui/Desktop.java | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index d7542b8..09f8de7 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -210,8 +210,6 @@ import org.apache.log4j.SimpleLayout; 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 diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 9e3382a..9da666b 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -106,6 +106,12 @@ import groovy.util.GroovyScriptEngine; */ public class Jalview { + + public Jalview() + { + setInstance(this); + } + static { Platform.getURLCommandArguments(); @@ -126,6 +132,10 @@ public class Jalview public static Jalview getInstance() { + if (instance == null) + { + instance = new Jalview(); + } 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 - setInstance(new Jalview()); + new Jalview(); getInstance().doMain(args); } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 88835c6..38cdf35 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -198,6 +198,10 @@ public class Desktop extends jalview.jbgui.GDesktop public static Desktop getInstance() { + if (instance == null) + { + new Desktop(true); + } Desktop d; @SuppressWarnings("unused") ThreadGroup g = Thread.currentThread().getThreadGroup(); @@ -250,6 +254,8 @@ public class Desktop extends jalview.jbgui.GDesktop public JInternalFrame conservationSlider, PIDSlider; + private boolean instanceOnly; + 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() { - 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 @@ -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 // /////////////////////////////////////////////// - if (getInstance() == null || Jalview.isHeadlessMode()) + if (getInstance().instanceOnly || Jalview.isHeadlessMode()) { return; } @@ -3276,7 +3286,7 @@ public class Desktop extends jalview.jbgui.GDesktop } ; } - if (getInstance() == null) + if (instanceOnly) { return; } -- 1.7.10.2