Skip to content

Commit

Permalink
Merge pull request #73 from pvlaraia/fix-window-crash
Browse files Browse the repository at this point in the history
Fix Colocalisation_Test window crash on multiple runs
  • Loading branch information
ctrueden authored Aug 27, 2024
2 parents 95f4f2b + c96419e commit fc38813
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 28 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/build-pr.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- master
tags:
- "*-[0-9]+.*"
pull_request:
branches:
- master

jobs:
build:
Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@

<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<imglib2.version>6.1.0</imglib2.version>
</properties>

<repositories>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/sc/fiji/coloc/Colocalisation_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import ij.text.TextWindow;

import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.DecimalFormat;

public class Colocalisation_Test implements PlugIn
Expand Down Expand Up @@ -701,10 +703,16 @@ public void correlate(ImagePlus imp1, ImagePlus imp2, ImagePlus imp3)
"\t" +df0.format(iterations)+
"\t" + randMethod+
"\t" +strPSF;
if (textWindow == null)
if (textWindow == null) {
textWindow = new TextWindow("Results",
Headings2, str, 400, 250);
else {
Headings2, str, 400, 250);
textWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent arg0) {
textWindow = null;
}
});
} else {
textWindow.getTextPanel().setColumnHeadings(Headings2);
textWindow.getTextPanel().appendLine(str);
}
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/sc/fiji/coloc/tests/ColocalisationGUITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*-
* #%L
* Fiji's plugin for colocalization analysis.
* %%
* Copyright (C) 2009 - 2024 Fiji developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package sc.fiji.coloc.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import java.awt.Window;
import java.awt.event.WindowEvent;

import org.junit.Test;

import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import ij.plugin.ChannelSplitter;
import sc.fiji.coloc.Colocalisation_Test;

public class ColocalisationGUITest extends ColocalisationTest {
@Test
public void testThatWindowRefIsCleanedUpIfClosed() {
assumeFalse(java.awt.GraphicsEnvironment.isHeadless());

ImagePlus img = IJ.openImage("http://imagej.net/images/FluorescentCells.zip");
ImagePlus[] splitImg = ChannelSplitter.split(img);
Colocalisation_Test colocalisationTest = new Colocalisation_Test();

// run module once, it'll open results textWindow
colocalisationTest.correlate(splitImg[0], splitImg[1], splitImg[2]);

// check textWindow is open, and close it
Window resultsWindow = WindowManager.getWindow("Results");
assertTrue(resultsWindow.isVisible());
resultsWindow.dispatchEvent(new WindowEvent(resultsWindow, WindowEvent.WINDOW_CLOSING));
assertFalse(resultsWindow.isVisible());

// run module again
colocalisationTest.correlate(splitImg[0], splitImg[1], splitImg[2]);

// check textWindow is open, .correlate didnt crash!
resultsWindow = WindowManager.getWindow("Results");
assertTrue(resultsWindow.isVisible());

}
}

0 comments on commit fc38813

Please sign in to comment.