Skip to content

Commit

Permalink
check windows within screen limits without overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Meech committed Jul 18, 2024
1 parent e08e062 commit b82b6be
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/de/embl/schwab/crosshair/Crosshair.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -148,4 +149,6 @@ public PlaneManager getPlaneManager() {
public String getUnit() {
return unit;
}

public CrosshairFrame getCrosshairFrame() { return crosshairFrame; }
}
34 changes: 33 additions & 1 deletion src/test/java/de/embl/schwab/crosshair/CrosshairTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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]);
}

}

0 comments on commit b82b6be

Please sign in to comment.