From ed5b661a62a1cc6abf0f4d28ee17f2360064fbca Mon Sep 17 00:00:00 2001 From: LeonYang5114 Date: Wed, 18 Nov 2015 16:22:25 -0600 Subject: [PATCH] Resolve racing condition Racing condition occurs when a command is programmatically invoked immediately after a display is created, using swing ui. The racing condition is resovled in a similar way to the LegacyImageDisplayViewer. See https://github.com/scijava/scijava-ui-swing/issues/18 --- .../swing/viewer/image/AbstractSwingImageDisplayViewer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/net/imagej/ui/swing/viewer/image/AbstractSwingImageDisplayViewer.java b/src/main/java/net/imagej/ui/swing/viewer/image/AbstractSwingImageDisplayViewer.java index 9f7968f5..95c5b418 100644 --- a/src/main/java/net/imagej/ui/swing/viewer/image/AbstractSwingImageDisplayViewer.java +++ b/src/main/java/net/imagej/ui/swing/viewer/image/AbstractSwingImageDisplayViewer.java @@ -35,6 +35,7 @@ import net.imagej.ui.viewer.image.AbstractImageDisplayViewer; import org.scijava.display.Display; +import org.scijava.display.DisplayService; import org.scijava.event.EventHandler; import org.scijava.event.EventService; import org.scijava.options.event.OptionsEvent; @@ -77,6 +78,10 @@ public JHotDrawImageCanvas getCanvas() { @Override public void view(final DisplayWindow w, final Display d) { super.view(w, d); + + // NB: resolve the racing condition when other consumer are looking up the + // active display + getContext().service(DisplayService.class).setActiveDisplay(getDisplay()); dispatcher = new AWTInputEventDispatcher(getDisplay(), eventService);