From c20939ef70b9f0e231ccd531817aa51f98e3f5ce Mon Sep 17 00:00:00 2001
From: Kimberly Meechan <24316371+K-Meech@users.noreply.github.com>
Date: Mon, 8 Jul 2024 17:07:38 +0100
Subject: [PATCH] fix window spacing
---
pom.xml | 2 +-
.../de/embl/schwab/crosshair/Crosshair.java | 2 +-
.../targetingaccuracy/TargetingAccuracy.java | 2 +-
.../de/embl/schwab/crosshair/utils/Utils.java | 34 +++++++++++++++----
4 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index b70d41a..7dc2878 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
crosshair
https://github.com/K-Meech/crosshair
- 1.0.4
+ 1.0.5
Crosshair
Assisted 3D targeting via an ultramicrotome
2020
diff --git a/src/main/java/de/embl/schwab/crosshair/Crosshair.java b/src/main/java/de/embl/schwab/crosshair/Crosshair.java
index d22f8db..54cbf55 100644
--- a/src/main/java/de/embl/schwab/crosshair/Crosshair.java
+++ b/src/main/java/de/embl/schwab/crosshair/Crosshair.java
@@ -122,7 +122,7 @@ private void initialiseCrosshair(BdvStackSource bdvStackSource, Image3DUniverse
CrosshairFrame crosshairFrame = new CrosshairFrame(this);
- spaceOutWindows( bdvHandle, crosshairFrame, universe );
+ spaceOutWindows( crosshairFrame, bdvHandle, universe );
}
public BdvHandle getBdvHandle() {
diff --git a/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/TargetingAccuracy.java b/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/TargetingAccuracy.java
index 0ef26b2..5991ace 100644
--- a/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/TargetingAccuracy.java
+++ b/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/TargetingAccuracy.java
@@ -105,7 +105,7 @@ public TargetingAccuracy ( File beforeTargetingXml, File registeredAfterTargetin
reader.loadSettings( settings, planeManager,
accuracyFrame.getImagesPanel().getImageNameToContent(), accuracyFrame.getOtherPanel() );
- spaceOutWindows(beforeStackSource.getBdvHandle(), accuracyFrame, universe);
+ spaceOutWindows(accuracyFrame, beforeStackSource.getBdvHandle(), universe);
}
}
diff --git a/src/main/java/de/embl/schwab/crosshair/utils/Utils.java b/src/main/java/de/embl/schwab/crosshair/utils/Utils.java
index e67300b..efb62e7 100644
--- a/src/main/java/de/embl/schwab/crosshair/utils/Utils.java
+++ b/src/main/java/de/embl/schwab/crosshair/utils/Utils.java
@@ -40,16 +40,38 @@ public static int findIndexOfMaxMin (ArrayList values, String MinMax) {
}
- public static void spaceOutWindows( BdvHandle bdvHandle, JFrame frame, Image3DUniverse universe ) {
- // Space out windows like here:
- // https://github.com/mobie/mobie-viewer-fiji/blob/9f7367902cc0bd01e089f7ce40cdcf0ee0325f1e/src/main/java/de/embl/cba/mobie/ui/viewer/SourcesPanel.java#L369
+ /**
+ * Space out the three Crosshair windows, with the JFrame on the left (with controls), big data viewer in the
+ * middle and the 3D viewer on the right.
+ * Based on
+ * https://github.com/mobie/mobie-viewer-fiji/blob/main/src/main/java/org/embl/mobie/ui/WindowArrangementHelper.java
+ * @param frame JFrame containing controls
+ * @param bdvHandle bdvHandle of the BigDataViewer window
+ * @param universe universe of the 3D viewer
+ */
+ public static void spaceOutWindows( JFrame frame, BdvHandle bdvHandle, Image3DUniverse universe ) {
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Window viewFrame = SwingUtilities.getWindowAncestor(bdvHandle.getViewerPanel());
+
+ // Make sure bigdataviewer + 3D viewer aren't taller than the screen
+ int viewHeight = viewFrame.getHeight();
+ if (viewHeight > screenSize.getHeight()) {
+ viewHeight = (int) Math.floor(screenSize.getHeight());
+ }
+
+ // Place the 3D viewer in the top right corner, and set its width to a third of the remaining space
+ // (after the controls width is taken into account)
+ int width3DViewer = (int) Math.floor((screenSize.getWidth() - frame.getWidth())/3.0);
+ universe.setSize(width3DViewer, viewHeight);
+ universe.getWindow().setLocation((int) Math.floor(screenSize.getWidth() - width3DViewer),
+ frame.getLocationOnScreen().y);
+
+ // Fill any remaining width between the controls and 3D viewer with the bdv window
viewFrame.setLocation(
frame.getLocationOnScreen().x + frame.getWidth(),
frame.getLocationOnScreen().y );
-
- universe.getWindow().setLocation(viewFrame.getLocationOnScreen().x + viewFrame.getWidth(),
- viewFrame.getLocation().y);
+ int newViewWidth = (int) Math.floor(screenSize.width - width3DViewer - frame.getWidth());
+ viewFrame.setSize(newViewWidth, viewHeight);
}
public static void resetCrossPlatformSwingLookAndFeel() {