From: James Procter Date: Wed, 7 Jun 2023 13:02:11 +0000 (+0100) Subject: JAL-4195 tidy up desktop instances after creating them X-Git-Tag: Release_2_11_4_0~213^2~22^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2b5c2dd88dd2f087fdf61427e59704d7bf05d627;p=jalview.git JAL-4195 tidy up desktop instances after creating them --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 6f2faae..1fcc591 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -3571,4 +3571,17 @@ public class Desktop extends jalview.jbgui.GDesktop jalview.bin.Console.debug(Cache.getStackTraceString(e)); } } + + /** + * closes the current instance window, disposes and forgets about it. + */ + public static void closeDesktop() + { + if (Desktop.instance != null) { + Desktop.instance.closeAll_actionPerformed(null); + Desktop.instance.setVisible(false); + Desktop.instance.dispose(); + Desktop.instance = null; + } + } } diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index b4c927b..61892df 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -49,8 +49,15 @@ public class CommandsTest @AfterMethod(alwaysRun = true) public void tearDown() { - if (Desktop.instance != null) - Desktop.instance.closeAll_actionPerformed(null); + Desktop.closeDesktop(); + } + + public static void callJalviewMain(String[] args) { + if (Jalview.getInstance()!=null) { + Jalview.getInstance().doMain(args); + } else { + Jalview.main(args); + } } /* --setprops is currently disabled so this test won't work @@ -71,7 +78,7 @@ public class CommandsTest int numFrames, String[] sequences) { String[] args = (cmdLine + " --gui").split("\\s+"); - Jalview.main(args); + callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs, @@ -111,7 +118,7 @@ public class CommandsTest { cleanupFiles(filenames); String[] args = (cmdLine + " --gui").split("\\s+"); - Jalview.main(args); + callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); File lastFile = null; @@ -139,7 +146,7 @@ public class CommandsTest { cleanupFiles(filenames); String[] args = (cmdLine + " --gui").split("\\s+"); - Jalview.main(args); + callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); File lastFile = null; @@ -297,7 +304,7 @@ public class CommandsTest String[] nonfilenames) { String[] args = (cmdLine + " --gui").split("\\s+"); - Jalview.main(args); + callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); for (String filename : filenames) diff --git a/test/jalview/bin/CommandsTest2.java b/test/jalview/bin/CommandsTest2.java index 0a47700..0c2071a 100644 --- a/test/jalview/bin/CommandsTest2.java +++ b/test/jalview/bin/CommandsTest2.java @@ -51,8 +51,7 @@ public class CommandsTest2 @AfterMethod(alwaysRun = true) public void tearDown() { - if (Desktop.instance != null) - Desktop.instance.closeAll_actionPerformed(null); + Desktop.closeDesktop(); } @Test( @@ -65,7 +64,7 @@ public class CommandsTest2 { String[] args = cmdLine.split("\\s+"); - Jalview.main(args); + CommandsTest.callJalviewMain(args); try { // sleep for slow build server to open annotations and viewer windows