diff --git a/src/main/java/de/embl/schwab/crosshair/Crosshair.java b/src/main/java/de/embl/schwab/crosshair/Crosshair.java index 54cbf55..59017f3 100644 --- a/src/main/java/de/embl/schwab/crosshair/Crosshair.java +++ b/src/main/java/de/embl/schwab/crosshair/Crosshair.java @@ -47,6 +47,7 @@ public class Crosshair { private BdvHandle bdvHandle; // bdvHandle of the BigDataViewer window private Image3DUniverse universe; // universe of the 3D viewer + private CrosshairFrame crosshairFrame; // crosshair control panel private Content imageContent; // image content displayed in 3D viewer private PlaneManager planeManager; private MicrotomeManager microtomeManager; @@ -120,7 +121,7 @@ private void initialiseCrosshair(BdvStackSource bdvStackSource, Image3DUniverse microtomeManager = new MicrotomeManager(planeManager, universe, imageContent, bdvStackSource, unit); new BdvBehaviours(bdvHandle, planeManager, microtomeManager); - CrosshairFrame crosshairFrame = new CrosshairFrame(this); + crosshairFrame = new CrosshairFrame(this); spaceOutWindows( crosshairFrame, bdvHandle, universe ); } @@ -148,4 +149,6 @@ public PlaneManager getPlaneManager() { public String getUnit() { return unit; } + + public CrosshairFrame getCrosshairFrame() { return crosshairFrame; } } diff --git a/src/test/java/de/embl/schwab/crosshair/CrosshairTest.java b/src/test/java/de/embl/schwab/crosshair/CrosshairTest.java index 777d93c..f903caf 100644 --- a/src/test/java/de/embl/schwab/crosshair/CrosshairTest.java +++ b/src/test/java/de/embl/schwab/crosshair/CrosshairTest.java @@ -3,6 +3,8 @@ import de.embl.cba.bdv.utils.sources.LazySpimSource; import org.junit.jupiter.api.Test; +import javax.swing.*; +import java.awt.*; import java.io.File; import static org.junit.jupiter.api.Assertions.*; @@ -17,9 +19,39 @@ void openCrosshairFromBdv() { final LazySpimSource imageSource = new LazySpimSource("raw", xray.getAbsolutePath()); Crosshair crosshair = new Crosshair(imageSource); - // Check successfully created a bdv window + 3D viewer + // Check successfully created crosshair controls, bdv window + 3D viewer + assertNotNull(crosshair.getCrosshairFrame()); assertNotNull(crosshair.getBdvHandle()); assertNotNull(crosshair.getUniverse()); + + // Check all windows on screen + not overlapping + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Window[] windows = new Window[]{ + crosshair.getCrosshairFrame(), + SwingUtilities.getWindowAncestor(crosshair.getBdvHandle().getViewerPanel()), + crosshair.getUniverse().getWindow() + }; + int[] xMins = new int[windows.length]; + int[] xMaxes = new int[windows.length]; + + for (int i = 0; i < windows.length; i++) { + Window window = windows[i]; + + // Check height within screen limits + assertTrue(window.getLocationOnScreen().y >= 0); + assertTrue(window.getLocationOnScreen().y + window.getHeight() <= screenSize.height); + + xMins[i] = window.getLocationOnScreen().x; + xMaxes[i] = window.getLocationOnScreen().x + window.getWidth(); + + // check width within screen limits + assertTrue(xMins[i] >= 0); + assertTrue(xMaxes[i] <= screenSize.width); + } + + // Check windows don't overlap + assertTrue(xMaxes[0] <= xMins[1]); + assertTrue(xMaxes[1] <= xMins[2]); } } \ No newline at end of file